public override void SetContainingBlock(BlockStatement containingBlock) { base.SetContainingBlock(containingBlock); this.body.SetContainingBlock(containingBlock); DummyExpression containingExpression = new DummyExpression(containingBlock, SourceDummy.SourceLocation); foreach (var e in this.expressions) e.SetContainingExpression(containingExpression); }
public override void SetContainingBlock(BlockStatement containingBlock) { base.SetContainingBlock(containingBlock); IEnumerable<IEnumerable<Expression>>/*?*/ triggers = this.Compilation.ContractProvider.GetTriggersFor(this); if (triggers != null) { Expression dummyExpression = new DummyExpression(containingBlock, this.SourceLocation); foreach (IEnumerable<Expression> trigger in triggers) foreach (Expression e in trigger) e.SetContainingExpression(dummyExpression); } }
public override void SetContainingBlock(BlockStatement containingBlock) { base.SetContainingBlock(containingBlock); foreach (var cs in this.cases) cs.SetContainingMatchStatement(this); DummyExpression containingExpression = new DummyExpression(containingBlock, SourceDummy.SourceLocation); this.expression.SetContainingExpression(containingExpression); }
private Expression ParseParenthesizedExpression(bool keepParentheses, TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { SourceLocationBuilder sctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken); if (this.currentToken == Token.LeftBrace) { Expression dummy = new DummyExpression(sctx); this.SkipTo(followers, Error.SyntaxError, "("); return dummy; } this.Skip(Token.LeftParenthesis); Expression result = this.ParseExpression(followers|Token.RightParenthesis|Token.Colon); if (keepParentheses) { sctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); result = new Parenthesis(result, sctx); } this.SkipOverTo(Token.RightParenthesis, followers); return result; }
private Expression GetInitialValue() { VccArrayTypeExpression /*?*/ arrayTypeExpression = this.ContainingLocalDeclarationsStatement.TypeExpression as VccArrayTypeExpression; var baseInit = base.InitialValue; if (baseInit == null && arrayTypeExpression != null && arrayTypeExpression.Size != null) { VccLocalDefinition loc = this.LocalVariable as VccLocalDefinition; var isSpec = loc != null ? loc.IsSpec : false; var result = new VccCreateStackArray(arrayTypeExpression.ElementType, arrayTypeExpression.Size, isSpec, SourceDummy.SourceLocation); var containingExpression = new DummyExpression(this.ContainingLocalDeclarationsStatement.ContainingBlock, SourceDummy.SourceLocation); result.SetContainingExpression(containingExpression); return result; } else if (baseInit == null) { return new DummyExpression(this.Name.SourceLocation); } else return baseInit; }
private Expression ParseSimpleExpression(TokenSet followers) { Expression result; TokenSet followersOrDotOrLeftParensOrLeftBracket = followers|Token.Dot|Token.LeftParens|Token.LeftBracket; switch (this.currentToken) { case Token.False: result = new CompileTimeConstant(false, this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.Identifier: result = this.ParseSimpleName(followersOrDotOrLeftParensOrLeftBracket); break; case Token.NumericLiteral: result = new CompileTimeConstant(decimal.Parse(this.scanner.GetTokenSource(), System.Globalization.CultureInfo.InvariantCulture), this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.StringLiteral: result = new CompileTimeConstant(this.scanner.GetTokenSource().Trim('"'), this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.True: result = new CompileTimeConstant(true, this.scanner.CurrentSourceLocation); this.GetNextToken(); break; case Token.LeftParens: result = this.ParseParenthesizedExpression(followersOrDotOrLeftParensOrLeftBracket); break; default: //TODO: error result = new DummyExpression(this.scanner.CurrentSourceLocation); break; } SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation); while (true) { switch (this.currentToken) { case Token.Dot: { this.GetNextToken(); SmallBasicSimpleName simpleName = this.ParseSimpleName(followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); slb.UpdateToSpan(simpleName.SourceLocation); result = new QualifiedName(result, simpleName, slb); continue; } case Token.LeftBracket: { this.GetNextToken(); IEnumerable<Expression> indices = this.ParseExpressions(slb, Token.RightBracket, followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); result = new SmallBasicIndexer(result, indices, slb); continue; } case Token.LeftParens: { this.GetNextToken(); IEnumerable<Expression> indices = this.ParseExpressions(slb, Token.RightParens, followers|Token.Dot|Token.Equals|Token.LeftBracket|Token.LeftParens|Token.EndOfLine); result = new MethodCall(result, indices, slb); //TODO: change this to VBMethodCall continue; } } break; } this.SkipTo(followers); return result; }
private Expression ParsePrimaryExpression(TokenSet followers) //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { ISourceLocation sctx = this.scanner.SourceLocationOfLastScannedToken; Expression expression = new DummyExpression(sctx); switch (this.currentToken) { case Token.ArgList: this.GetNextToken(); expression = new RuntimeArgumentHandleExpression(sctx); break; case Token.Delegate: expression = this.ParseAnonymousMethod(followers); break; case Token.New: expression = this.ParseNew(followers|Token.Dot|Token.LeftBracket|Token.Arrow); break; case Token.Identifier: expression = this.ParseSimpleName(followers|Token.Dot|Token.DoubleColon|Token.Lambda|Token.LeftParenthesis); if (this.currentToken == Token.DoubleColon) { if (((SimpleName)expression).Name == this.nameTable.global) expression = new RootNamespaceExpression(expression.SourceLocation); expression = this.ParseQualifiedName(expression, followers|Token.Dot|Token.LessThan|Token.LeftParenthesis|Token.AddOne|Token.SubtractOne); } else if (this.currentToken == Token.Lambda) { expression = this.ParseLambda((SimpleName)expression, followers); } break; case Token.Null: expression = new NullLiteral(sctx); this.GetNextToken(); break; case Token.True: expression = new CompileTimeConstant(true, false, sctx); this.GetNextToken(); break; case Token.False: expression = new CompileTimeConstant(false, false, sctx); this.GetNextToken(); break; case Token.CharLiteral: expression = new CompileTimeConstant(this.scanner.charLiteralValue, false, sctx); this.GetNextToken(); break; case Token.HexLiteral: expression = this.ParseHexLiteral(); break; case Token.IntegerLiteral: expression = this.ParseIntegerLiteral(); break; case Token.RealLiteral: expression = this.ParseRealLiteral(); break; case Token.StringLiteral: expression = new CompileTimeConstant(this.scanner.GetString(), false, sctx); this.GetNextToken(); break; case Token.This: expression = new ThisReference(sctx); this.GetNextToken(); break; case Token.Base: expression = new BaseClassReference(sctx); this.GetNextToken(); break; case Token.Typeof: case Token.Sizeof: case Token.Default: expression = this.ParseTypeofSizeofOrDefault(followers); break; case Token.Stackalloc: return this.ParseStackalloc(followers); case Token.Checked: case Token.MakeRef: case Token.RefType: case Token.Unchecked: expression = this.ParseCheckedOrMakeRefOrRefTypeOrUnchecked(followers); break; case Token.RefValue: expression = this.ParseGetValueOfTypedReference(followers); break; case Token.Bool: case Token.Decimal: case Token.Sbyte: case Token.Byte: case Token.Short: case Token.Ushort: case Token.Int: case Token.Uint: case Token.Long: case Token.Ulong: case Token.Char: case Token.Float: case Token.Double: case Token.Object: case Token.String: expression = this.RootQualifiedNameFor(this.currentToken, sctx); this.GetNextToken(); break; case Token.LeftParenthesis: expression = this.ParseCastExpression(followers|Token.Dot|Token.LeftBracket|Token.Arrow); break; default: if (Parser.IdentifierOrNonReservedKeyword[this.currentToken]) goto case Token.Identifier; if (Parser.InfixOperators[this.currentToken]) { this.HandleError(Error.InvalidExprTerm, this.scanner.GetTokenSource()); //^ assume this.currentToken != Token.EndOfFile; //should not be a member of InfixOperators this.GetNextToken(); } else this.SkipTo(followers|Parser.PrimaryStart, Error.InvalidExprTerm, this.scanner.GetTokenSource()); if (Parser.PrimaryStart[this.currentToken]) return this.ParsePrimaryExpression(followers); goto done; } expression = this.ParseIndexerCallOrSelector(expression, followers|Token.AddOne|Token.SubtractOne); for (; ; ) { switch (this.currentToken) { case Token.AddOne: SourceLocationBuilder slb = new SourceLocationBuilder(expression.SourceLocation); slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.GetNextToken(); expression = new PostfixIncrement(new TargetExpression(expression), slb); break; case Token.SubtractOne: slb = new SourceLocationBuilder(expression.SourceLocation); slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); this.GetNextToken(); expression = new PostfixDecrement(new TargetExpression(expression), slb); break; case Token.Arrow: case Token.Dot: case Token.LeftBracket: expression = this.ParseIndexerCallOrSelector(expression, followers|Token.AddOne|Token.SubtractOne); break; default: goto done; } } done: this.SkipTo(followers); return expression; }
/// <summary> /// Completes the two stage construction of this object. This allows bottom up parsers to construct an Expression before constructing the containing Expression. /// This method should be called once only and must be called before this object is made available to client code. The construction code itself should also take /// care not to call any other methods or property/event accessors on the object until after this method has been called. /// </summary> public override void SetContainingExpression(Expression containingExpression) { base.SetContainingExpression(containingExpression); Expression dummyExpression = new DummyExpression(this.ContainingBlock, this.SourceLocation); this.lambdaExpr.SetContainingExpression(dummyExpression); }
protected override Expression ParseLabeledExpression(TokenSet followers, bool isInvariant = false) { if (this.currentToken == Token.Colon) { SourceLocationBuilder slb = this.GetSourceLocationBuilderForLastScannedToken(); this.GetNextToken(); NameDeclaration label; if (isInvariant && this.currentToken == Token.Volatile) { label = new VccNameDeclaration(this.GetNameFor("volatile"), false, slb); this.GetNextToken(); } else { label = this.ParseNameDeclaration(true); } Expression expr; if (TS.UnaryStart[this.currentToken] || TS.PrimaryStart[this.currentToken]) { expr = this.ParseExpression(followers); slb.UpdateToSpan(expr.SourceLocation); } else { slb.UpdateToSpan(label.SourceLocation); expr = new DummyExpression(slb); this.SkipTo(followers); } return new VccLabeledExpression(expr, label, slb); } return this.ParseExpression(followers); }
public override void SetContainingTypeDeclaration(TypeDeclaration containingTypeDeclaration, bool recurse) { base.SetContainingTypeDeclaration(containingTypeDeclaration, recurse); if (this.expansion != null) { var dummyExpression = new DummyExpression(this.DummyBlock, SourceDummy.SourceLocation); this.expansion.SetContainingExpression(dummyExpression); } }
public void SetContainingTypeDeclaration(TypeDeclaration containingTypeDeclaration) { this.containingTypeDeclaration = containingTypeDeclaration; DummyExpression dummyExpression = new DummyExpression(this.DummyBlock, SourceDummy.SourceLocation); this.Type.SetContainingExpression(dummyExpression); if (this.parameters != null) foreach (ParameterDeclaration parameter in this.parameters) { parameter.SetContainingSignatureAndExpression(this, dummyExpression); parameter.Type.SetContainingExpression(dummyExpression); } if (this.templateParameters != null) { foreach (var tpar in this.templateParameters) tpar.SetContainingExpression(dummyExpression); } MethodContract/*?*/ contract = this.CompilationPart.Compilation.ContractProvider.GetMethodContractFor(this) as MethodContract; if (contract != null) contract.SetContainingBlock(this.DummyBlock); }
public void SetContainingTypeDeclaration(TypeDeclaration containingTypeDeclaration) { this.containingTypeDeclaration = containingTypeDeclaration; BlockStatement containingBlock = containingTypeDeclaration.DummyBlock; DummyExpression containingExpression = new DummyExpression(containingBlock, SourceDummy.SourceLocation); this.Type.SetContainingExpression(containingExpression); }