Ejemplo n.º 1
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)

}
Ejemplo n.º 2
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
}