示例#1
0
func makeCallExpr(name string, params *st.SymbolTable, pointerSymbols map[st.Symbol]int, pos token.Pos, recvSym *st.VariableSymbol, pack *st.Package, filename string) (*ast.CallExpr, int) {
	var Fun ast.Expr
	if recvSym != nil {
		x := ast.NewIdent(recvSym.Name())
		x.NamePos = pos
		Fun = &ast.SelectorExpr{x, ast.NewIdent(name)}
	} else {
		x := ast.NewIdent(name)
		x.NamePos = pos
		Fun = x
	}
	l, _ := utils.GetNodeLength(Fun)
	l += 2

	args, i := make([]ast.Expr, params.Count()), 0
	params.ForEachNoLock(func(sym st.Symbol) {
		args[i] = sym.ToAstExpr(pack, filename)
		if depth, ok := pointerSymbols[sym]; ok {
			for depth > 0 {
				args[i] = &ast.UnaryExpr{token.NoPos, token.AND, args[i]}
				depth--
			}
		}
		ll, _ := utils.GetNodeLength(args[i])
		l += ll + 2
		i++
	})
	l -= 2
	return &ast.CallExpr{Fun, token.NoPos, args, token.NoPos, pos + token.Pos(l-1)}, l
}
示例#2
0
func (pp *packageParser) fixVariableSymbol(t *st.VariableSymbol) {

	// 	fmt.Printf("%s %s has type %T\n", pp.Package.AstPackage.Name, t.VariableType.Name(), t.VariableType)

	if uts, ok := t.VariableType.(*st.UnresolvedTypeSymbol); ok {
		//pp.CurrentFileName = pp.Package.FileSet.Position(uts.Declaration.Pos()).Filename
		t.VariableType = pp.resolveType(uts)
		pp.moveData(t.VariableType, uts)

	}
	pp.fixType(t.VariableType)

}
示例#3
0
//ast.Visitor.Visit(). Looks for top-level ast.ValueSpec nodes of ast.Tree to register global vars
func (gv globalsFixVisitor) Visit(node ast.Node) ast.Visitor {

	switch t := node.(type) {
	case *ast.ValueSpec:

		gv.Parser.parseTypeSymbol(t.Type)

		for i, n := range t.Names {
			var v *st.VariableSymbol
			if sym, ok := gv.Parser.Package.Symbols.LookUp(n.Name, gv.Parser.CurrentFileName); !ok {
				panic("Lost variable or something...  " + n.Name)
			} else {
				v = sym.(*st.VariableSymbol)
			}

			var exprT st.ITypeSymbol = nil

			if t.Values != nil {
				exprT = gv.Parser.parseExpr(t.Values[i]).At(0).(st.ITypeSymbol)
				if _, ok := v.VariableType.(*st.UnresolvedTypeSymbol); ok {
					// 					if _, ok := exprT.(*st.UnresolvedTypeSymbol); !ok {
					// 						fmt.Printf("%s: =)))) var %s found its type type\n", gv.Parser.Package.AstPackage.Name, v.Name())
					// 					}
					v.VariableType = exprT
				}
			}
			if _, ok := exprT.(*st.UnresolvedTypeSymbol); ok {
				fmt.Printf("warning: var %s in package %s still has unresolved type\n", v.Name(), gv.Parser.Package.AstPackage.Name)
			}

			if arrT, ok := v.VariableType.(*st.ArrayTypeSymbol); ok {
				if arrT.Len == st.ELLIPSIS {
					arrT.Len = exprT.(*st.ArrayTypeSymbol).Len
				}
			}
			v.AddPosition(gv.Parser.Package.FileSet.Position(n.Pos()))
		}
	case *ast.ForStmt, *ast.FuncDecl, *ast.FuncLit, *ast.IfStmt, *ast.RangeStmt, *ast.SelectStmt, *ast.SwitchStmt, *ast.TypeSwitchStmt:
		//InnerScope, omitted
		return nil
	}
	return gv
}