Skip to content

Commit

Permalink
parser 禁止类型别名
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Jan 12, 2024
1 parent 06c3e74 commit 7ed7e83
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ type (
Name *Ident // type name
TypeParams *FieldList // type parameters; or nil
ColonPos token.Pos // position of ":" operator (token.NoPos if there is no ":")
Assign token.Pos // position of '=', if any
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
Comment *CommentGroup // line comments; or nil
}
Expand Down
6 changes: 0 additions & 6 deletions internal/frontend/wz/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2432,9 +2432,6 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
if p.tok == token.COLON {
spec.ColonPos = p.pos
p.next()
} else if p.tok == token.ASSIGN {
spec.Assign = p.pos
p.next()
}
spec.Type = p.parseType()
p.expectSemi() // call before accessing p.linecomment
Expand Down Expand Up @@ -2890,9 +2887,6 @@ func (p *parser) 解析类型定义() *ast.GenDecl {
if p.tok == token.COLON {
spec.ColonPos = p.pos
p.next()
} else if p.tok == token.ASSIGN {
spec.Assign = p.pos
p.next()
}
// spec.Type = p.parseType()

Expand Down
3 changes: 0 additions & 3 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2443,9 +2443,6 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
if p.tok == token.COLON {
spec.ColonPos = p.pos
p.next()
} else if p.tok == token.ASSIGN {
spec.Assign = p.pos
p.next()
}
spec.Type = p.parseType()
p.expectSemi() // call before accessing p.linecomment
Expand Down
3 changes: 0 additions & 3 deletions internal/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,6 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
} else {
p.print(vtab)
}
if s.Assign.IsValid() {
p.print(token.ASSIGN, blank)
}
p.expr(s.Type)
p.setComment(s.Comment)

Expand Down
5 changes: 3 additions & 2 deletions internal/types/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (check *Checker) declare(scope *Scope, id *ast.Ident, obj Object, pos token

// pathString returns a string of the form a->b-> ... ->g for a path [a, b, ... g].
// TODO(gri) remove once we don't need the old cycle detection (explicitly passed
// []*TypeName path) anymore
//
// []*TypeName path) anymore
func pathString(path []*TypeName) string {
var s string
for i, p := range path {
Expand Down Expand Up @@ -682,7 +683,7 @@ func (check *Checker) declStmt(decl ast.Decl) {
check.declare(check.scope, s.Name, obj, scopePos)
// mark and unmark type before calling typeDecl; its type is still nil (see Checker.objDecl)
obj.setColor(grey + color(check.push(obj)))
check.typeDecl(obj, s.Type, nil, s.Assign.IsValid())
check.typeDecl(obj, s.Type, nil, false)
check.pop().setColor(black)
default:
check.invalidAST(s.Pos(), "const, type, or var declaration expected")
Expand Down
2 changes: 1 addition & 1 deletion internal/types/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (check *Checker) collectObjects() {
case *ast.TypeSpec:
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil)
obj.setNode(s)
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: s.Assign.IsValid()})
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: false})

if s.Doc == nil {
if d.Lparen == token.NoPos && d.Doc != nil {
Expand Down
1 change: 1 addition & 0 deletions waroot/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 版本日志

- (dev)
- 禁止类型别名
- v0.9.0 (2023-12-15) MVP
- 增加胶水代码定义特性
- 添加 js、js/cancas 标准库
Expand Down
2 changes: 1 addition & 1 deletion waroot/src/math/bits/bits_test.wa
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const DeBruijn64 = deBruijn64

type entry = struct {
type entry struct {
nlz, ntz, pop: int
}

Expand Down

0 comments on commit 7ed7e83

Please sign in to comment.