]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/gc/noder.go
all: merge dev.inline into master
[gostls13.git] / src / cmd / compile / internal / gc / noder.go
index 1207c3f6149a2e902797c501427c9c1874b0e126..e4378544f0114d5225d9a761185bd9ed6b44bbcd 100644 (file)
@@ -51,6 +51,7 @@ func parseFiles(filenames []string) uint {
                if nsyntaxerrors != 0 {
                        errorexit()
                }
+               // Always run testdclstack here, even when debug_dclstack is not set, as a sanity measure.
                testdclstack()
        }
 
@@ -215,11 +216,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
 
 func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
        names := p.declNames(decl.NameList)
-
-       var typ *Node
-       if decl.Type != nil {
-               typ = p.typeExpr(decl.Type)
-       }
+       typ := p.typeExprOrNil(decl.Type)
 
        var exprs []*Node
        if decl.Values != nil {
@@ -232,11 +229,7 @@ func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
 
 func (p *noder) constDecl(decl *syntax.ConstDecl) []*Node {
        names := p.declNames(decl.NameList)
-
-       var typ *Node
-       if decl.Type != nil {
-               typ = p.typeExpr(decl.Type)
-       }
+       typ := p.typeExprOrNil(decl.Type)
 
        var exprs []*Node
        if decl.Values != nil {
@@ -248,14 +241,11 @@ func (p *noder) constDecl(decl *syntax.ConstDecl) []*Node {
 
 func (p *noder) typeDecl(decl *syntax.TypeDecl) *Node {
        name := typedcl0(p.name(decl.Name))
-       name.Name.Param.Pragma = decl.Pragma
 
-       var typ *Node
-       if decl.Type != nil {
-               typ = p.typeExpr(decl.Type)
-       }
+       // decl.Type may be nil but in that case we got a syntax error during parsing
+       typ := p.typeExprOrNil(decl.Type)
 
-       return typedcl1(name, typ, true)
+       return typedcl1(name, typ, syntax.Pragma(decl.Pragma), decl.Alias)
 }
 
 func (p *noder) declNames(names []*syntax.Name) []*Node {
@@ -320,19 +310,19 @@ func (p *noder) funcHeader(fun *syntax.FuncDecl) *Node {
                                yyerror("func main must have no arguments and no return values")
                        }
                }
-
-               f.Func.Nname = newfuncname(name)
        } else {
-               // Receiver MethodName Signature
-
-               f.Func.Shortname = newfuncname(name)
-               f.Func.Nname = methodname(f.Func.Shortname, t.Left.Right)
+               f.Func.Shortname = name
+               name = nblank.Sym // filled in by typecheckfunc
        }
 
+       f.Func.Nname = newfuncname(name)
        f.Func.Nname.Name.Defn = f
        f.Func.Nname.Name.Param.Ntype = t // TODO: check if nname already has an ntype
 
-       declare(f.Func.Nname, PFUNC)
+       if fun.Recv == nil {
+               declare(f.Func.Nname, PFUNC)
+       }
+
        funchdr(f)
        return f
 }
@@ -528,6 +518,13 @@ func (p *noder) typeExpr(typ syntax.Expr) *Node {
        return p.expr(typ)
 }
 
+func (p *noder) typeExprOrNil(typ syntax.Expr) *Node {
+       if typ != nil {
+               return p.expr(typ)
+       }
+       return nil
+}
+
 func (p *noder) chanDir(dir syntax.ChanDir) ChanDir {
        switch dir {
        case 0:
@@ -1088,6 +1085,7 @@ func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma {
                p.linknames = append(p.linknames, linkname{pos, f[1], f[2]})
 
        case strings.HasPrefix(text, "go:cgo_"):
+               // TODO(gri): lineno = p.baseline + int32(line) - 1 // pragcgo may call yyerror
                p.pragcgobuf += pragcgo(text)
                fallthrough // because of //go:cgo_unsafe_args
        default: