コード例 #1
0
        private static LiteralNode ParseRational(ProjectParser parser, string value, TypeReference requestedType, SequencePoint point)
        {
            try
            {
                switch (requestedType.MetadataType)
                {
                case MetadataType.Single:
                    return(new LiteralNode(Convert.ToSingle(value, CultureInfo.InvariantCulture), requestedType, point));

                case MetadataType.Double:
                    return(new LiteralNode(Convert.ToDouble(value, CultureInfo.InvariantCulture), requestedType, point));

                default:
                    ContractsHelper.AssertUnreachable("Unexpected type {0} in ParseRational", requestedType.MetadataType);
                    return(Utils.Utils.Fail <LiteralNode>());
                }
            }
            catch (OverflowException)
            {
                ErrorCode.InvalidStructure.ReportAndThrow(point, "Could not parse {0} as {1}, overflow", value, requestedType.FullName);
                return(Utils.Utils.Fail <LiteralNode>());
            }
            catch (FormatException)
            {
                ErrorCode.InvalidStructure.ReportAndThrow(point, "Could not parse {0} as {1}, format error", value, requestedType.FullName);
                return(Utils.Utils.Fail <LiteralNode>());
            }
        }
コード例 #2
0
        public void Release(VariableDefinition variable)
        {
            Contract.Requires(variable != null);

            for (int i = 0; i < temporaryVariables.Count; i++)
            {
                if (temporaryVariables[i].variable == variable)
                {
                    temporaryVariables[i] = new TempVariable(variable, false);
                    return;
                }
            }

            ContractsHelper.AssertUnreachable("Invalid variable was passed to TemporaryVairables.Release().");
        }
        private static string ModuleKindToExtension(ModuleKind moduleKind)
        {
            Contract.Requires(moduleKind != ModuleKind.NetModule);

            switch (moduleKind)
            {
            case ModuleKind.Console:
            case ModuleKind.Windows:
                return(".exe");

            case ModuleKind.Dll:
                return(".dll");

            default:
                ContractsHelper.AssertUnreachable(string.Format("Unknown module kind: {0}.", moduleKind));
                return(string.Empty);
            }
        }
コード例 #4
0
        private static ExpressionNode ParsePrefix(ContextNode context, IAbstractSyntaxTree lexerNode)
        {
            var opType = lexerNode.Children[1].Type;

            if (opType == Lexer.TokenType.CastOperator)
            {
                return(CastNode.Parse(context, lexerNode));
            }
            else
            {
                InternalUnaryOperatorType op;
                switch (opType)
                {
                case Lexer.TokenType.PlusPlus:
                    op = InternalUnaryOperatorType.PreIncrement;
                    break;

                case Lexer.TokenType.MinusMinus:
                    op = InternalUnaryOperatorType.PreDecrement;
                    break;

                case Lexer.TokenType.Not:
                    op = InternalUnaryOperatorType.LogicalNot;
                    break;

                case Lexer.TokenType.BitwiseComplement:
                    op = InternalUnaryOperatorType.BinaryNot;
                    break;

                case Lexer.TokenType.Minus:
                    op = InternalUnaryOperatorType.Negation;
                    break;

                default:
                    ContractsHelper.AssertUnreachable("Unknown prefix op {0}", opType);
                    return(null);   //unreachable
                }
                return(Create(context, ExpressionNode.Parse(context, lexerNode.Children[0]), op));
            }
        }
コード例 #5
0
        public static ExpressionNode Parse(ContextNode context, IAbstractSyntaxTree lexerNode)
        {
            Contract.Requires(lexerNode.Type == TokenType.InfixNode);
            var op = lexerNode.Children[2].Type;

            if (op.IsBinaryOp())
            {
                return(BinaryOperatorNode.Parse(context, lexerNode));
            }

            if (op.IsAssignmentOp())
            {
                return(AssignmentOperatorNode.Parse(context, lexerNode));
            }

            if (op.IsPeriodOp())
            {
                return(DotOperatorNode.Parse(context, lexerNode));
            }

            ContractsHelper.AssertUnreachable("Unknown infix operator {0}", op);
            return(null);//unreachable
        }
コード例 #6
0
        private static ExpressionNode ParseSuffix(ContextNode context, IAbstractSyntaxTree lexerNode)
        {
            var opType = lexerNode.Children[1].Type;

            switch (opType)
            {
            case Lexer.TokenType.PlusPlus:
                return(Create(context, ExpressionNode.Parse(context, lexerNode.Children[0]), InternalUnaryOperatorType.PostIncrement));

            case Lexer.TokenType.MinusMinus:
                return(Create(context, ExpressionNode.Parse(context, lexerNode.Children[0]), InternalUnaryOperatorType.PostDecrement));

            case Lexer.TokenType.FunctionArgumentsList:
                return(MethodCallNode.Parse(context, lexerNode));

            case Lexer.TokenType.IndexNode:
                return(ArrayAccessNode.Parse(context, lexerNode));

            default:
                ContractsHelper.AssertUnreachable("Unknown postfix op {0}", opType);
                return(null);   //unreachable
            }
        }
コード例 #7
0
        private static List <ExpressionNode> ParseArgList(ContextNode parent, IAbstractSyntaxTree lexerNode)
        {
            var args = new List <ExpressionNode>();

            foreach (var node in lexerNode.Children)
            {
                switch (node.Type)
                {
                case Lexer.TokenType.LeftParenthesis:
                case Lexer.TokenType.RightParenthesis:
                case Lexer.TokenType.Comma:
                    break;

                case Lexer.TokenType.Value:
                    args.Add(ExpressionNode.Parse(parent, node));
                    break;

                default:
                    ContractsHelper.AssertUnreachable("Unexpected node {0} in call", node.Type);
                    break;
                }
            }
            return(args);
        }