예제 #1
0
파일: Compiler.cs 프로젝트: zihotki/Excess
        public override SyntaxNode Visit(SyntaxNode node)
        {
            if (pending_ != null)
            {
                ITreeLookAhead curr = pending_;
                pending_ = null;

                LookAheadAction action;
                SyntaxNode      newNode = curr.rewrite(this, node, out action);
                switch (action)
                {
                case LookAheadAction.SUCCEDED: return(newNode);

                case LookAheadAction.CONTINUE:
                {
                    pending_ = curr;
                    return(newNode);
                }
                }
            }

            return(base.Visit(node));
        }
예제 #2
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        private SyntaxNode rewriteInvocation(InvocationExpressionSyntax node, bool assign)
        {
            IDSLHandler dsl = ctx_.CreateDSL(node.Expression.ToString());
            if (dsl != null)
            {
                DSLContext dctx = new DSLContext { MainNode = node, Surroundings = DSLSurroundings.Code, Assign = assign, ExtraMembers = members_ };

                Debug.Assert(pending_ == null);
                pending_ = new ResolveDSLCode(dsl, ctx_, dctx);
                return dsl.compile(ctx_, dctx);
            }
            else if (node.ArgumentList.GetDiagnostics().Any())
            {
                return SyntaxFactory.InvocationExpression(node.Expression, (ArgumentListSyntax)Visit(node.ArgumentList));
            }

            return node;
        }
예제 #3
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
        {
            if (node.Declaration.Variables.Count == 1)
            {
                IDSLHandler dsl = null;
                dsl = ctx_.CreateDSL(node.Declaration.Type.ToString());
                if (dsl != null)
                {
                    if (node.Declaration.Variables.Count != 1)
                    {
                        //td: error
                        return node;
                    }

                    var variable = node.Declaration.Variables[0];
                    DSLContext dctx = new DSLContext { MainNode = variable, Surroundings = DSLSurroundings.Code, Assign = false, ExtraMembers = members_ };
                    Debug.Assert(pending_ == null);
                    pending_ = new ResolveDSLCode(dsl, ctx_, dctx);
                    return dsl.compile(ctx_, dctx);
                }
            }

            return base.VisitLocalDeclarationStatement(node);
        }
예제 #4
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode VisitIncompleteMember(IncompleteMemberSyntax node)
        {
            string typename = node.Type.ToString();
            IDSLHandler dsl = ctx_.CreateDSL(typename);
            if (dsl != null)
            {
                pending_ = new ResolveDSLClass(dsl, ctx_, members_);
                return null;
            }

            return node;
        }
예제 #5
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            node = node.WithDeclaration((VariableDeclarationSyntax)VisitVariableDeclaration(node.Declaration));
            if (node.Declaration.Variables.Count == 1)
            {
                string typeName = node.Declaration.Type.ToString();
                switch (typeName)
                {
                    case "typedef":
                    {
                        Debug.Assert(pending_ == null);
                        pending_ = new ResolveTypedef(node, ctx_);
                        return null;
                    }

                    case "property":
                    {
                        var variable    = node.Declaration.Variables[0];
                        var initializer = variable.Initializer;
                        if (initializer != null)
                        {
                            var propType = Compiler.ConstantType(initializer.Value);
                            var result   = Compiler.Property(propType, variable.Identifier);
                            return result;
                        }
                        return node;
                    }
                }

                string variableName = node.Declaration.Variables[0].Identifier.ToString();
                switch (variableName)
                {
                    case "function":
                    case "method":
                    {
                        //when functions are declared with types the parser generates
                        //a subsquent erroneous method declaration
                        Debug.Assert(pending_ == null);
                        pending_ = new ResolveTypedFunction(node, ctx_, variableName == "method");
                        return null;
                    }
                    case "property":
                    {
                        //when functions are declared with types the parser generates
                        //a subsquent erroneous method declaration
                        Debug.Assert(pending_ == null);

                        var result = Compiler.Property(node.Declaration.Type);
                        pending_ = new ResolveProperty(result);
                        return null;
                    }
                }

            }
            return node;
        }
예제 #6
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            if (!node.Identifier.IsMissing)
                return node;

            string event_name    = node.Type.ToString();
            string delegate_name = event_name + "_delegate";

            Debug.Assert(pending_ == null);
            pending_ = new ResolveEventArguments(delegate_name, ctx_, members_, node.Modifiers);

            return SyntaxFactory.EventDeclaration(SyntaxFactory.IdentifierName(delegate_name), SyntaxFactory.Identifier(event_name)).
                                    WithModifiers(node.Modifiers).
                                    WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List( new AccessorDeclarationSyntax[]
                                    {
                                        SyntaxFactory.AccessorDeclaration(SyntaxKind.AddAccessorDeclaration,
                                            SyntaxFactory.Block(SyntaxFactory.List(new StatementSyntax[]
                                            {
                                                Compiler.EventAccessor(event_name, true)
                                            }))),

                                        SyntaxFactory.AccessorDeclaration(SyntaxKind.RemoveAccessorDeclaration,
                                            SyntaxFactory.Block(SyntaxFactory.List(new StatementSyntax[]
                                            {
                                                Compiler.EventAccessor(event_name, false)
                                            }))),
                                    })));
        }
예제 #7
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode VisitElementAccessExpression(ElementAccessExpressionSyntax node)
        {
            bool isAssignment = node.Expression.IsMissing;
            bool isParam      = node.Expression is InvocationExpressionSyntax;

            if (!isAssignment && !isParam)
                return node;

            List<ExpressionSyntax> casting = new List<ExpressionSyntax>();
            foreach (ArgumentSyntax arg in node.ArgumentList.Arguments)
            {
                casting.Add(arg.Expression);
            }

            ArrayCreationExpressionSyntax array = SyntaxFactory.ArrayCreationExpression(
                                                        SyntaxFactory.ArrayType(SyntaxFactory.IdentifierName("object[]")),
                                                        SyntaxFactory.InitializerExpression(SyntaxKind.ArrayInitializerExpression,
                                                            SyntaxFactory.SeparatedList(casting)));

            if (isAssignment)
            {
                return ctx_.AddLinker(array, linkArray);
            }
            else if (isParam)
            {
                //first parameter is an array
                var invocation    = (InvocationExpressionSyntax)node.Expression;
                var newInvocation = SyntaxFactory.InvocationExpression(invocation.Expression);
                var result = ctx_.AddLinker(newInvocation, (ctx, linkNode, newNode, model) =>
                {
                    var args = (ArgumentListSyntax)ctx.GetLinkData(linkNode);
                    var inv  = (InvocationExpressionSyntax)newNode;
                    return inv.WithArgumentList(args);
                });

                Debug.Assert(pending_ == null);
                pending_ = new ResolveArrayArgument(ctx_, result, array);

                return result;
            }

            return node;
        }
예제 #8
0
파일: Compiler.cs 프로젝트: mpmedia/Excess
        public override SyntaxNode Visit(SyntaxNode node)
        {
            if (pending_ != null)
            {
                ITreeLookAhead curr = pending_;
                pending_ = null;

                LookAheadAction action;
                SyntaxNode newNode = curr.rewrite(this, node, out action);
                switch (action)
                {
                    case LookAheadAction.SUCCEDED: return newNode;
                    case LookAheadAction.CONTINUE:
                    {
                        pending_ = curr;
                        return newNode;
                    }
                }
            }

            return base.Visit(node);
        }