public virtual void Visit(NullExpression node) { this.BeforeVisitCatchAll(node); }
public override void Visit(NullExpression node) { _expressionStack.Push(node, Expression.Constant(null, typeof(object))); }
private ExpressionNodeBase PromoteToExpression(Token firstToken) { ExpressionNodeBase retval; int intValue; switch(firstToken.HappyTokenKind) { case HappyTokenKind.Identifier: HappySourceLocation startsAt, endsAt; if (this.EatNextTokenIf(HappyTokenKind.OperatorOpenParen, out startsAt)) { List<ExpressionNodeBase> arguments = new List<ExpressionNodeBase>(); bool parseMore = !this.EatNextTokenIf(HappyTokenKind.OperatorCloseParen, out endsAt); while (parseMore) { arguments.Add(this.ParseExpression(ExpressionContext.ArgumentList)); var commaOrCloseParen = this.Expect(HappyTokenKind.Comma, HappyTokenKind.OperatorCloseParen, MiscMessages.CommaOrCloseParen); endsAt = commaOrCloseParen.Location; parseMore = commaOrCloseParen.HappyTokenKind != HappyTokenKind.OperatorCloseParen; } retval = new FunctionCallExpression(startsAt, endsAt, firstToken.ToIdentifier(), arguments.ToArray()); } else retval = new IdentifierExpression(firstToken.ToIdentifier()); break; case HappyTokenKind.LiteralBool: switch(firstToken.Text) { case "true": retval = new LiteralExpression(firstToken.Location, true); break; case "false": retval = new LiteralExpression(firstToken.Location, false); break; default: throw new UnhandledCaseSourceException(firstToken.Location); } break; case HappyTokenKind.LiteralDecimalInt32: if(!Int32.TryParse(firstToken.Text, out intValue)) throw new InternalSourceException(firstToken.Location, "Failed to parse an Int32 from \"{0}\" _tokenKind is LiteralInt32?!?!", firstToken.Text); retval = new LiteralExpression(firstToken.Location, intValue); break; case HappyTokenKind.LiteralHexInt32: if(!Int32.TryParse(firstToken.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat, out intValue)) throw new InternalSourceException(firstToken.Location, "Failed to parse an Int32 from \"{0}\" _tokenKind is LiteralHexInt32?!?!", firstToken.Text); retval = new LiteralExpression(firstToken.Location, intValue); break; case HappyTokenKind.LiteralHexInt64: long longValue; if (!Int64.TryParse(firstToken.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat, out longValue)) throw new InternalSourceException(firstToken.Location, "Failed to parse an Int32 from \"{0}\" _tokenKind is LiteralHexInt64?!?!", firstToken.Text); retval = new LiteralExpression(firstToken.Location, longValue); break; case HappyTokenKind.LiteralDouble: double doubleValue; try { doubleValue = Double.Parse(firstToken.Text); } catch(Exception e) { throw new InternalSourceException(e, firstToken.Location, "Failed to parse a Double from \"{0}\" but _tokenKind is LiteralDouble?!?!", firstToken.Text); } retval = new LiteralExpression(firstToken.Location, doubleValue); break; case HappyTokenKind.LiteralString: retval = new LiteralExpression(firstToken.Location, firstToken.Text); break; case HappyTokenKind.LiteralNull: retval = new NullExpression(firstToken.Location); break; case HappyTokenKind.BeginTemplate: retval = this.ParseAnonymousTemplateExpression(firstToken.Location); break; default: _errorCollector.UnexpectedToken(firstToken); throw new AbortParseException(firstToken.Location); } return retval; }