public SymbolDef DefGlobal(AstSymbol symbol) { var name = symbol.Name; if (Globals !.ContainsKey(name)) { return(Globals ![name]);
public SymbolDef DefVariable(AstSymbol symbol, AstNode?init) { SymbolDef def; if (Variables !.ContainsKey(symbol.Name)) { def = Variables ![symbol.Name];
public SymbolDef DefVariable(AstSymbol symbol, AstNode?init) { SymbolDef def; if (Variables !.ContainsKey(symbol.Name)) { def = Variables[symbol.Name]; def.Orig.Add(symbol); if (def.Init != null && (!ReferenceEquals(def.Scope, symbol.Scope) || def.Init is AstFunction)) { def.Init = init; } }
public SymbolDef DefFunction(AstSymbol symbol, AstNode init) { var def = DefVariable(symbol, init); if (def.Init == null || def.Init is AstDefun) { def.Init = init; } if (!Functions.ContainsKey(symbol.Name)) { Functions.Add(symbol.Name, def); } return(def); }
public SymbolDef DefGlobal(AstSymbol symbol) { var name = symbol.Name; if (Globals.ContainsKey(name)) { return(Globals[name]); } var global = new SymbolDef(this, symbol, null); global.Undeclared = true; global.Global = true; Globals.Add(name, global); return(global); }
public SymbolDef DefVariable(AstSymbol symbol, AstNode init) { SymbolDef def; if (Variables.ContainsKey(symbol.Name)) { def = Variables[symbol.Name]; def.Orig.Add(symbol); if (def.Init != null && (!ReferenceEquals(def.Scope, symbol.Scope) || def.Init is AstFunction)) { def.Init = init; } } else { def = new SymbolDef(this, symbol, init); Variables.Add(symbol.Name, def); def.Global = ParentScope == null; } return(symbol.Thedef = def); }
public override void CodeGen(OutputContext output) { string GetName(AstSymbol symbol) { return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name); } var allowShortHand = output.Options.Shorthand; var keyString = Key switch { AstString str => str.Value, AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture), AstSymbol key => GetName(key), _ => null }; if (allowShortHand && Value is AstSymbol && keyString != null && GetName((AstSymbol)Value) == keyString && OutputContext.IsIdentifierString(keyString) && OutputContext.IsIdentifier(keyString) ) { output.PrintPropertyName(keyString); } else if (allowShortHand && Value is AstDefaultAssign defAssign && keyString != null && defAssign.Left is AstSymbol && OutputContext.IsIdentifierString(keyString) && GetName((AstSymbol)defAssign.Left) == keyString ) { output.PrintPropertyName(keyString); output.Space(); output.Print("="); output.Space(); defAssign.Right.Print(output); }
protected void PrintGetterSetter(OutputContext output, string?type, bool @static) { if (@static) { output.Print("static"); output.Space(); } if (type != null) { output.Print(type); output.Space(); } var keyString = Key switch { AstString str => str.Value, AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture), AstSymbol key => key.Name, _ => null }; if (keyString != null) { output.PrintPropertyName(keyString); } else { output.Print("["); Key.Print(output); output.Print("]"); } ((AstLambda)Value).DoPrint(output, true); } }
public AstSymbolFunarg(AstSymbol from) : base(from) { }
public AstSymbolImport(AstSymbol init) : base(init) { }
protected AstSymbolDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol) { Init = init; }
public AstNameMapping(Parser parser, Position startLoc, Position endLoc, AstSymbol foreignName, AstSymbol name) : base(parser, startLoc, endLoc) { ForeignName = foreignName; Name = name; }
public AstSymbolVar(AstSymbol name) : base(name) { }
public AstSymbolProperty(AstSymbol symbol) : base(symbol) { }
static bool IsVarLetConst(AstSymbol astSymbol) { var t = astSymbol.GetType(); return(t == typeof(AstSymbolVar) || t == typeof(AstSymbolLet) || t == typeof(AstSymbolConst)); }
public AstSymbolExport(AstSymbol symbol) : base(symbol) { }
public AstSymbolExportForeign(AstSymbol symbol) : base(symbol) { }
public AstSymbolDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol) { Init = init; }
public SymbolDef FindVariable(AstSymbol symbol) { return(FindVariable(symbol.Name)); }
public AstSymbolLet(AstSymbol name) : base(name) { }
public AstSymbolLambda(AstSymbol from) : base(from) { }
protected AstSymbolBlockDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol, init) { }
public AstSymbolConst(AstSymbol name) : base(name) { }
protected AstSymbolRef(AstSymbol symbol) : base(symbol) { }
public AstSymbolDefClass(AstSymbol name, AstNode?init = null) : base(name, init) { }
public AstNameMapping(string?source, Position startLoc, Position endLoc, AstSymbol foreignName, AstSymbol name) : base(source, startLoc, endLoc) { ForeignName = foreignName; Name = name; }
public AstLabelRef(AstSymbol symbol) : base(symbol) { }
protected AstSymbol(AstSymbol symbol) : base(symbol) { Name = symbol.Name; }
public AstSymbolCatch(AstSymbol name) : base(name) { }
public override void Transform(TreeTransformer tt) { base.Transform(tt); Name = (AstSymbol)tt.Transform(Name); ForeignName = (AstSymbol)tt.Transform(ForeignName); }