Пример #1
0
 /// <summary>
 /// This only hanldes function calls that are at the global scope, i.e. not in dotted expressions.
 /// </summary>
 /// <param name="node"></param>
 public override void AfterVisit(FunctionCallExpression node)
 {
     //Member references are handled during analysis of the parent BinaryExpression node
     //because knowledge of both the instance and member are required.
     if (!node.GetExtension<NamedExpressionNodeExtension>().IsMemberReference)
     {
         Expression getMethod = this.PropertyOrFieldGet(node.Identifier.Text, _globalScopeExp);
         var args = _expressionStack.Pop(node.Arguments.Length).ToArray();
         _expressionStack.Push(node, this.dynamicInvoke(getMethod, args));
     }
     base.AfterVisit(node);
 }
Пример #2
0
 public virtual void AfterVisit(FunctionCallExpression node)
 {
     this.AfterVisitCatchAll(node);
 }
Пример #3
0
 public virtual void BeforeVisit(FunctionCallExpression node)
 {
     this.BeforeVisitCatchAll(node);
 }
Пример #4
0
        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;
        }