public void VisitSymbol(AstSymbol ast) { Assert.IsType <AstSymbol>(this.expected); var expectedAst = (AstSymbol)this.expected; Assert.Equal(expectedAst.Name, ast.Name); }
public override void CodeGen(OutputContext output) { string GetName(AstSymbol symbol) { return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name); } var allowShortHand = output.Options.Ecma >= 6; var keyString = Key switch { AstString str => str.Value, AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture), AstSymbolRef _ => null, AstSymbol key => GetName(key), _ => null }; if (allowShortHand && Value is AstSymbol value && keyString != null && GetName(value) == keyString && OutputContext.IsIdentifierString(keyString) && OutputContext.IsIdentifier(keyString) ) { output.PrintPropertyName(keyString); }
public SymbolDef DefVariable(AstSymbol symbol, AstNode?init) { SymbolDef def; if (Variables !.ContainsKey(symbol.Name)) { def = Variables ![symbol.Name];
public SymbolDef DefGlobal(AstSymbol symbol) { var name = symbol.Name; if (Globals !.ContainsKey(name)) { return(Globals ![name]);
AstNode ParseLabelledStatement(Position nodeStart, string maybeName, AstSymbol expr) { foreach (var label in _labels) { if (label.Name == maybeName) { Raise(expr.Start, "Label '" + maybeName + "' is already declared"); } } var newlabel = new AstLabel(this, nodeStart, _lastTokEnd, maybeName); newlabel.IsLoop = TokenInformation.Types[Type].IsLoop; _labels.Add(newlabel); var body = ParseStatement(true); if (body is AstClass || body is AstLet || body is AstConst || body is AstFunction functionDeclaration && (_strict || functionDeclaration.IsGenerator)) { RaiseRecoverable(body.Start, "Invalid labelled declaration"); } _labels.Pop(); return(new AstLabeledStatement(this, nodeStart, _lastTokEnd, (AstStatement)body, newlabel)); }
public static void SetSymbol(this IAstSymbolSite symbolEntrySite, AstSymbol symbolEntry) { if (!symbolEntrySite.TrySetSymbol(symbolEntry)) { throw new InternalErrorException( "Symbol is already set or null."); } }
internal void AstSymbol_Clone_ClonesTheObject() { var ast = new AstSymbol("foobar"); var cloned = ast.Clone(); Assert.NotSame(ast, cloned); Assert.Equal(ast, cloned); Assert.Equal(ast.Name, ((AstSymbol)cloned).Name); }
protected override string GetSymbolTargetName(AstSymbol symbol) { if (symbol.IsValidFrame) { return(UniqueNameGenerator.GetUniqueName(symbol.Name)); } throw new InvalidOperationException(); }
public static AstExpression Create(Source src, params string[] qualifier) { AstExpression @base = new AstSymbol(src, AstSymbolType.Global); foreach (var id in qualifier) { @base = new AstMember(@base, new AstIdentifier(src, id)); } return(@base); }
public SymbolDef(AstScope scope, AstSymbol orig, AstNode?init) { Name = orig.Name; Scope = scope; Orig = new StructList <AstSymbol>(); Orig.Add(orig); Init = init; References = new StructList <AstSymbol>(); Global = false; MangledName = null; MangledIdx = -2; Undeclared = false; Defun = null; }
public void Eval_Defines_ValueReferenced() { var env = new LispEnv(); var name = new AstSymbol("x"); var value = new AstIntNumber(42); env.Eval(new AstList( new AstSymbol("def!"), name, value)); var data = env.Copy(); Assert.Equal(value, data.Defines[name]); }
/// <summary> /// Close the child scope of the given namespace or frame /// </summary> /// <param name="symbol"></param> public void CloseScope(AstSymbol symbol) { if (symbol.IsValidNamespace) { CloseScope((AstNamespace)symbol); return; } if (symbol.IsValidFrame) { CloseScope((AstFrame)symbol); return; } this.ReportNormal("Close Scope", ProgressEventArgsResult.Failure); }
public void Clone_Defines_HasNotSameObject_ButEqual() { var data = new LispEnvData(); var sourceKey = new AstSymbol("foo"); var sourceValue = new AstSymbol("bar"); data.Defines[sourceKey] = sourceValue; var dataClone = data.Clone(); var keyClone = dataClone.Defines.Keys.Single(); var valueClone = (AstSymbol)dataClone.Defines[sourceKey]; Assert.NotSame(sourceKey, keyClone); Assert.NotSame(sourceValue, valueClone); Assert.Equal(sourceKey.Name, keyClone.Name); Assert.Equal(sourceValue.Name, valueClone.Name); }
/// <summary> /// The main Reset method called by all others. The given symbol must be a frame or a namespace /// </summary> /// <param name="symbol"></param> public void Reset(AstSymbol symbol) { if (symbol.IsNullOrInvalid() || (symbol.IsValidFrame == false && symbol.IsValidNamespace == false)) { this.ReportNormal("Reset Interpreter", ProgressEventArgsResult.Failure); return; } Output.Clear(); Root = symbol.Root; _mainCommandBlock = CommandBlock.Create(symbol.AssociatedSymbol as SymbolWithScope); RefResContext.Clear(_mainCommandBlock); _expressionEvaluator = GMacExpressionEvaluator.CreateForDynamicEvaluation(_mainCommandBlock); _symbolsCache.Clear(); this.ReportNormal("Reset Interpreter", symbol.AccessName, ProgressEventArgsResult.Success); }
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), AstSymbolRef => null, 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 AstSymbolLambda(AstSymbol from) : base(from) { }
protected override string GetSymbolTargetName(AstSymbol symbol) { return(symbol.AccessName); }
public AstSymbolExport(AstSymbol symbol) : base(symbol) { }
public AstSymbolVar(AstSymbol name) : base(name) { }
static bool IsVarLetConst(AstSymbol astSymbol) { var t = astSymbol.GetType(); return(t == typeof(AstSymbolVar) || t == typeof(AstSymbolLet) || t == typeof(AstSymbolConst)); }
public AstSymbolRef(AstSymbol symbol) : base(symbol) { }
internal SimpleSelfExport(string name, AstSymbol symbol) { Name = name; Symbol = symbol; }
public AstSymbolDefun(AstSymbol from) : base(from) { }
AstNode ParseFunction(Position startLoc, bool isStatement, bool isNullableId, bool allowExpressionBody = false, bool isAsync = false) { var generator = false; if (Options.EcmaVersion >= 6 && !isAsync) { generator = Eat(TokenType.Star); } if (Options.EcmaVersion < 8 && isAsync) { throw new InvalidOperationException(); } AstSymbol id = null; if (isStatement || isNullableId) { id = isNullableId && Type != TokenType.Name ? null : ParseIdent(); if (id != null) { CheckLVal(id, true, VariableKind.Var); } } var oldInGen = _inGenerator; var oldInAsync = _inAsync; var oldYieldPos = _yieldPos; var oldAwaitPos = _awaitPos; var oldInFunc = _inFunction; _inGenerator = generator; _inAsync = isAsync; _yieldPos = default; _awaitPos = default; _inFunction = true; EnterFunctionScope(); if (isStatement == false && isNullableId == false) { id = Type == TokenType.Name ? ParseIdent() : null; } var parameters = new StructList <AstNode>(); ParseFunctionParams(ref parameters); MakeSymbolFunArg(ref parameters); var body = new StructList <AstNode>(); var useStrict = false; var expression = ParseFunctionBody(parameters, startLoc, id, allowExpressionBody, ref body, ref useStrict); _inGenerator = oldInGen; _inAsync = oldInAsync; _yieldPos = oldYieldPos; _awaitPos = oldAwaitPos; _inFunction = oldInFunc; if (isStatement || isNullableId) { if (id != null) { id = new AstSymbolDefun(id); } return(new AstDefun(this, startLoc, _lastTokEnd, (AstSymbolDefun)id, ref parameters, generator, isAsync, ref body).SetUseStrict(useStrict)); } if (id != null) { id = new AstSymbolLambda(id); } return(new AstFunction(this, startLoc, _lastTokEnd, (AstSymbolLambda)id, ref parameters, generator, isAsync, ref body).SetUseStrict(useStrict)); }
public AstSymbolFunarg(AstSymbol from) : base(from) { }
public AstSymbolCatch(AstSymbol name) : base(name) { }
public AstSymbolDefClass(AstSymbol name, AstNode init = null) : base(name, init) { }
public AstSymbolProperty(AstSymbol symbol) : base(symbol) { }
public AstSymbolClass(AstSymbol from) : base(from) { }
public void VisitSymbol(AstSymbol ast) => IncrementCallCount(nameof(VisitSymbol));