Exemplo n.º 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
}
Exemplo n.º 2
0
func (pp *packageParser) getOrAddPointer(base st.ITypeSymbol) (result *st.PointerTypeSymbol) {

	nameToFind := base.Name()

	//anonymous type
	if base.Name() == st.NO_NAME {
		result = st.MakePointerType(base.Scope(), base)
		if s, ok := base.(*st.StructTypeSymbol); ok {
			result.Fields = s.Fields
		}
		return
	}

	pd, found := 0, false
	if p, ok := base.(*st.PointerTypeSymbol); ok {
		pd = p.Depth()
		nameToFind = p.BaseName()
	}

	var toLookUp *st.SymbolTable
	if base.PackageFrom() == pp.Package || base.PackageFrom() == nil {
		toLookUp = pp.Package.Symbols
	} else {
		toLookUp = base.PackageFrom().Symbols
	}
	// 	if base.Name() == "typesVisitor" {
	// 		fmt.Printf("goap %v and pp is in %v.  toLookUp is from %s\n", base.PackageFrom().AstPackage.Name, pp.Package.AstPackage.Name, toLookUp.Package.AstPackage.Name)
	// 	}

	if result, found = toLookUp.LookUpPointerType(nameToFind, pd+1); found {
		// 		fmt.Printf("Searched Pointer Type %s (%p) ,%d, from package %s\n", nameToFind, result, pd+1, func(p *st.Package) string {
		// 			if p == nil {
		// 				return "nil"
		// 			}
		// 			return p.AstPackage.Name
		// 		}(result.PackageFrom()))
		return
	}

	result = st.MakePointerType(toLookUp, base)
	if s, ok := base.(*st.StructTypeSymbol); ok {
		result.Fields = s.Fields
	}
	// 	fmt.Printf("Adding Pointer Type %s to %s at file of %s\n", result.Name(), func(p *st.Package) string {
	// 		if p == nil {
	// 			return "nil"
	// 		}
	// 		return p.AstPackage.Name
	// 	}(base.PackageFrom()),
	// 		pp.Package.AstPackage.Name)

	toLookUp.AddSymbol(result)
	return
}
Exemplo n.º 3
0
func (pp *packageParser) fixTypesInSymbolTable(table *st.SymbolTable) {
	if table == nil {
		return
	}
	table.ForEachNoLock(func(sym st.Symbol) {

		// 		if sym.Name() == "Parser" {
		// 			fmt.Printf("horay %T\n", sym)
		// 		}

		if uts, ok := sym.(*st.UnresolvedTypeSymbol); ok {

			res := pp.resolveType(uts)
			table.ReplaceSymbol(uts.Name(), res)
			pp.moveData(res, uts)
			// 			fmt.Printf("rewrited %s with %s from %s \n", sym.Name(), res.Name(), res.PackageFrom().AstPackage.Name)
			pp.fixType(res)
		} else {
			//Start recursive walk
			pp.fixType(sym)
		}
	})
}