internal static Symbol Declare(Node declareNode, Scope s, string name, TokenPos pos, SymbolUsage usage) { var pre = s.FindSymbol(name); if (pre != null) { throw new CompileException(string.Format("{0} redeclared, pre define: {1}", name, pre.DefinePos), pos); } Symbol sb = new Symbol(); sb.Name = name; sb.Decl = declareNode; sb.DefinePos = pos; sb.Usage = usage; s.Insert(sb); if (declareNode != null) { var ident = declareNode as Ident; if (ident == null) { return(sb); } ident.Symbol = sb; } return(sb); }
internal Scope OpenScope(ScopeType type, TokenPos pos) { var s = new Scope(_topScope, type, pos); _topScope = s; return(s); }
public VarDeclareStmt(List <Ident> names, TokenPos varpos) { Names = names; VarPos = varpos; BuildRelation(); }
public ReturnStmt(List <Expr> list, TokenPos retpos) { Results = list; RetPos = retpos; BuildRelation(); }
public ExprStmt(List <Expr> x, TokenPos defpos) { X = x; DefPos = defpos; BuildRelation(); }
public ImportStmt(BasicLit src, TokenPos pos) { Source = src; ImportPos = pos; BuildRelation(); }
internal ValuePhoFunc(ObjectName name, TokenPos codepos, int regCount, Scope s) : base(name) { _regCount = regCount; _scope = s; _defpos = codepos; }
public SelectorExpr(Expr x, Ident sel, TokenPos pos) { X = x; Selector = sel; DotPos = pos; BuildRelation(); }
public UnaryExpr(Expr x, TokenType t, TokenPos oppos) { X = x; Op = t; OpPos = oppos; BuildRelation(); }
public ArrayExpr(List <Expr> values, TokenPos lbracket, TokenPos rbracket) { Values = values; LBracketPos = lbracket; RBracketPos = rbracket; BuildRelation(); }
public BlockStmt(List <Stmt> list, TokenPos lpos, TokenPos rpos) { Stmts = list; LBracePos = lpos; RBracePos = rpos; BuildRelation(); }
public MapExpr(Dictionary <BasicLit, Expr> values, TokenPos lbrace, TokenPos rbrace) { Values = values; LBracePos = lbrace; RBracePos = rbrace; BuildRelation(); }
public ParenExpr(Expr x, TokenPos lparen, TokenPos rparen) { X = x; LParenPos = lparen; RParenPos = rparen; BuildRelation(); }
public NewExpr(Ident className, Ident pkgName, TokenPos newpos) { NewPos = newpos; ClassName = className; PackageName = pkgName; BuildRelation(); }
public IncDecStmt(Expr x, TokenType t, TokenPos oppos) { X = x; Op = t; OpPos = oppos; BuildRelation(); }
public ConstDeclareStmt(Ident name, Expr value, TokenPos defpos) { Name = name; ConstPos = defpos; Value = value; BuildRelation(); }
public AssignStmt(List <Expr> lhs, List <Expr> rhs, TokenPos assignPos, TokenType op) { LHS = lhs; RHS = rhs; Op = op; AssignPos = assignPos; BuildRelation(); }
public WhileStmt(Expr con, TokenPos defpos, Scope s, BlockStmt body) { Condition = con; Pos = defpos; ScopeInfo = s; Body = body; BuildRelation(); }
public IfStmt(Expr con, BlockStmt body, BlockStmt elsebody, TokenPos ifpos) { Condition = con; Body = body; ElseBody = elsebody; IfPos = ifpos; BuildRelation(); }
public BinaryExpr(Expr x, Expr y, TokenType t, TokenPos oppos) { X = x; Y = y; Op = t; OpPos = oppos; BuildRelation(); }
public IndexExpr(Expr x, Expr index, TokenPos lpos, TokenPos rpos) { X = x; Index = index; LBrackPos = lpos; RBrackPos = rpos; BuildRelation(); }
public AssignStmt(Expr lhs, Expr rhs, TokenPos assignPos, TokenType op) { AssignPos = assignPos; Op = op; LHS.Add(lhs); RHS.Add(rhs); BuildRelation(); }
public CallExpr(Expr f, List <Expr> args, Scope s, TokenPos lparen, TokenPos rparen) { Func = f; Args = args; S = s; LParen = lparen; RParen = rparen; BuildRelation(); }
public ClassDeclare(Ident name, Ident parentName, Scope s, List <Ident> member, TokenPos classpos) { Name = name; ParentName = parentName; ClassPos = classpos; Member = member; ScopeInfo = s; BuildRelation(); }
public ForStmt(Stmt init, Expr con, Stmt post, TokenPos defpos, Scope s, BlockStmt body) { Condition = con; Init = init; Post = post; Pos = defpos; ScopeInfo = s; Body = body; BuildRelation(); }
public ForRangeStmt(Ident key, Ident value, Expr x, TokenPos inpos, TokenPos defpos, Scope s, BlockStmt body) { Key = key; Value = value; X = x; InPos = inpos; Pos = defpos; ScopeInfo = s; Body = body; BuildRelation(); }
public Scope(Scope outter, ScopeType type, TokenPos pos) { if (outter != null) { outter._child.Add(this); } _outter = outter; _type = type; _defpos = pos; }
void ResolveSelectorElement(Expr x, Ident sel, TokenPos dotpos) { var xident = x as Ident; if (xident == null) { return; } if (xident.Symbol == null) { throw new CompileException(string.Format("{0} not defined", xident.Name), dotpos); } switch (xident.Symbol.Usage) { // 包.函数名 case SymbolUsage.Package: { var pkg = Exe.GetPackageByName(xident.Name); if (pkg == null) { throw new CompileException("package not found: " + xident.Name, dotpos); } // 包必须有一个顶级作用域 if (pkg.TopScope == null) { throw new CompileException("package should have a scope: " + xident.Name, dotpos); } ScopeMgr.Resolve(sel, pkg.TopScope); } break; // 实例.函数名 case SymbolUsage.Variable: case SymbolUsage.Parameter: case SymbolUsage.SelfParameter: { } break; default: throw new CompileException("unknown usage", dotpos); } }
internal Scope OpenClassScope(string name, TokenPos pos) { var exists = GetClassScope(name); if (exists != null) { // 被函数提前定义, 所以这里补下主定义位置 exists.CodePos = pos; return(exists); } var s = OpenScope(ScopeType.Class, pos); s.ClassName = name; return(s); }
internal string QuerySourceLine(TokenPos pos) { foreach (var p in _packages) { foreach (var f in p.FileList) { if (f.Source.Name == pos.SourceName) { return(f.Source.GetLine(pos.Line)); } } } return(string.Empty); }