Example #1
0
        public ResolveArrayArgument(ExcessContext ctx, SyntaxNode node, ArrayCreationExpressionSyntax arg)
        {
            ctx_  = ctx;
            node_ = node;

            args_.Add(SyntaxFactory.Argument(arg));
        }
Example #2
0
        private SyntaxNode linkArray(ExcessContext ctx, SyntaxNode linkNode, SyntaxNode newNode, SemanticModel model)
        {
            ArrayCreationExpressionSyntax ace = newNode as ArrayCreationExpressionSyntax;
            ArgumentSyntax arg = null;
            bool asParam = newNode is ArgumentSyntax;
            if (asParam)
            {
                arg = (ArgumentSyntax)newNode;
                ace = (ArrayCreationExpressionSyntax)arg.Expression;
            }

            ITypeSymbol arrayType = null;
            foreach (var expr in ace.Initializer.Expressions)
            {
                ITypeSymbol type = model.GetSpeculativeTypeInfo(expr.SpanStart, expr, SpeculativeBindingOption.BindAsExpression).Type;

                if (arrayType == null)
                    arrayType = type;
                else if (type != arrayType)
                {
                    if (isSuperClass(type, arrayType))
                        arrayType = type; //downcast
                    else if (!isSuperClass(arrayType, type))
                    {
                        //td: error
                        return newNode; //unable to refine
                    }
                }
            }

            if (arrayType == null)
                return newNode;

            ace = ace.WithType(SyntaxFactory.ArrayType(SyntaxFactory.IdentifierName(arrayType.Name + "[]")));
            if (asParam)
                return arg.WithExpression(ace);

            return ace;
        }
Example #3
0
 public Compiler(ExcessContext ctx)
 {
     ctx_ = ctx;
 }
Example #4
0
 public ExcessParamListRewriter(ExcessContext ctx)
 {
     ctx_ = ctx;
 }
Example #5
0
 public Linker(ExcessContext ctx, Compilation compilation)
 {
     ctx_         = ctx;
     compilation_ = compilation;
 }
Example #6
0
        public SyntaxNode compile(ExcessContext ctx, DSLContext dctx)
        {
            setContext(_parser, ctx);
            setContext(_linker, ctx);

            var node = dctx.MainNode;
            switch (dctx.Surroundings)
            {
                case DSLSurroundings.Global:
                {
                    if (node is ClassDeclarationSyntax)
                    {
                        if (_parseClass == null)
                            throw new InvalidOperationException("This dsl does not support types");

                        var classDeclaration = (ClassDeclarationSyntax)ctx.Rewriter.Visit(node);

                        var id = classDeclaration.Identifier.ToString();
                        var result = ctx.Rewriter.Visit(node);
                        return (SyntaxNode)_parseClass.Invoke(_parser, new object[] { classDeclaration, id, SyntaxFactory.ParameterList() });
                    }
                    else if (node is MethodDeclarationSyntax)
                    {
                        if (_parseNamespace == null)
                            throw new InvalidOperationException("This dsl does not support namespaces");

                        var method = (MethodDeclarationSyntax)node;
                        var id     = method.ReturnType.IsMissing? "" :  method.Identifier.ToString();
                        var code   = (BlockSyntax)ctx.Rewriter.Visit(method.Body);

                        return (SyntaxNode)_parseNamespace.Invoke(_parser, new object[] { method, id, method.ParameterList, code });
                    }

                    //td: error
                    break;
                }

                case DSLSurroundings.TypeBody:
                {
                    if (_parseMethod == null)
                        throw new InvalidOperationException("This dsl does not support methods");

                    var method = (MethodDeclarationSyntax)node;
                    var code = (BlockSyntax)ctx.Rewriter.Visit(method.Body);

                    return (SyntaxNode)_parseMethod.Invoke(_parser, new object[] { method, "", method.ParameterList, code });
                }

                case DSLSurroundings.Code:
                {
                    if (_parseCodeHeader == null)
                        return null;

                    return (SyntaxNode)_parseCodeHeader.Invoke(_parser, new object[] { node });
                }
            }

            return node;
        }
Example #7
0
 private void setContext(object obj, ExcessContext ctx)
 {
     var method = obj.GetType().GetMethod("SetContext");
     method.Invoke(obj, new object[] { ctx });
 }
Example #8
0
        public SyntaxNode setCode(ExcessContext ctx, DSLContext dctx, BlockSyntax code)
        {
            if (_parseCode == null)
                throw new InvalidOperationException("This dsl does not support code");

            SyntaxNode          node       =  dctx.MainNode;
            string              identifier = "";
            ParameterListSyntax args       = null;

            var invocation = node as InvocationExpressionSyntax;
            if (invocation != null)
            {
                args = toParameterList(invocation.ArgumentList.Arguments);
            }
            else
            {
                var varDeclarator = node as VariableDeclaratorSyntax;
                if (varDeclarator == null)
                {
                    //td: error
                    return node;
                }

                identifier = varDeclarator.Identifier.ToString();
                args = toParameterList(varDeclarator.ArgumentList.Arguments);
            }

            code = (BlockSyntax)ctx.Rewriter.Visit(code);
            return (SyntaxNode)_parseCode.Invoke(_parser, new object[] { code, identifier, args, code, dctx.Assign });
        }
Example #9
0
        public SyntaxNode link(ExcessContext ctx, SyntaxNode node, SemanticModel model)
        {
            if (_link == null)
                throw new InvalidOperationException("This dsl does not support linking");

            return (SyntaxNode)_link.Invoke(_linker, new object[] { node, model });
        }
Example #10
0
 public ResolveDSLClass(IDSLHandler dsl, ExcessContext ctx, List<MemberDeclarationSyntax> extraMembers)
 {
     dsl_ = dsl;
     ctx_ = ctx;
     extraMembers_ = extraMembers;
 }
Example #11
0
 public ResolveTypedFunction(FieldDeclarationSyntax field, ExcessContext ctx, bool asPublic)
 {
     field_ = field;
     ctx_   = ctx;
     asPublic_ = asPublic;
 }
Example #12
0
 public ResolveTypedef(FieldDeclarationSyntax field, ExcessContext ctx)
 {
     field_ = field;
     ctx_   = ctx;
 }
Example #13
0
 public ResolveEventArguments(string name, ExcessContext ctx, List<MemberDeclarationSyntax> extraMembers, SyntaxTokenList modifiers)
 {
     name_         = name;
     ctx_          = ctx;
     extraMembers_ = extraMembers;
     modifiers_    = modifiers;
 }
Example #14
0
 public ResolveDSLCode(IDSLHandler dsl, ExcessContext ctx, DSLContext dctx)
 {
     dsl_  = dsl;
     ctx_  = ctx;
     dctx_ = dctx;
 }