public override void VisitMethodDecl(MethodDecl x)
 {
     if (x.Name == MethodName && x.ContainingType.QualifiedName == ClassName)
     {
         Method = x;
     }
 }
示例#2
0
 public override void VisitMethodDecl(MethodDecl x)
 {
     using (new ScopeHelper(this, x))
     {
         base.VisitMethodDecl(x);
     }
 }
示例#3
0
        private MainClass parseMainClass()
        {
            parseImports();
            if (token.TokenType == TokenType.PUBLIC)
            {
                eat(TokenType.PUBLIC);
            }

            eat(TokenType.CLASS);
            Identifier className = parseIdentifier(Tipo.Class);

            eat(TokenType.LLAVEI);
            eat(TokenType.PUBLIC);
            eat(TokenType.STATIC);
            eat(TokenType.VOID);
            eat(TokenType.MAIN);
            eat(TokenType.IPAREN);
            eat(TokenType.STRING);
            eat(TokenType.ident);
            eat(TokenType.DPAREN);

            Statement stm = parseStatement();

            eat(TokenType.LLAVED);

            MethodDecl mainMethod = new MethodDecl(Tipo.Int, new Identifier(new Palabra("main", TokenType.MAIN), Tipo.Int), stm);

            return(new MainClass(className, mainMethod));
        }
示例#4
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            m_currentMethod           = ast.MethodInfo;
            m_currentVariableIndex    = 0;
            m_currentMethodParameters = new VariableCollection <Parameter>();

            foreach (var param in m_currentMethod.Parameters)
            {
                m_currentMethodParameters.Add(param);
            }

            m_currentMethodVariables = new VariableCollection <VariableInfo>();

            if (ast.Statements == null || ast.ReturnExpression == null)
            {
                AddError(c_SE_NotSupported, ast.Name.Span, "A method must have body defined");
                return(ast);
            }

            foreach (var statement in ast.Statements)
            {
                Visit(statement);
            }

            Visit(ast.ReturnExpression);

            return(ast);
        }
示例#5
0
 public override void VisitMethodDecl(MethodDecl x)
 {
     if (x == _routine)
     {
         _statementContext = VariableKind.LocalVariable;
         base.VisitMethodDecl(x);
     }
 }
示例#6
0
        public SourceMethodSymbol(SourceTypeSymbol /*!*/ type, MethodDecl /*!*/ syntax)
        {
            Contract.ThrowIfNull(type);
            Contract.ThrowIfNull(syntax);

            _type   = type;
            _syntax = syntax;
        }
示例#7
0
            public override void VisitMethodDecl(MethodDecl x)
            {
                VisitSpecificElementProlog();

                SerializeToken(nameof(x.Name), x.Name.ToString(), x.Name.Span);

                base.VisitMethodDecl(x);
            }
示例#8
0
 /// <summary>
 /// Constructs a confrolflow graph. This method should be used only for testing with purpose of testing.
 /// </summary>
 /// <param name="globalCode">needed for drawing</param>
 /// <param name="function">function to construct controlflow graph</param>
 /// <param name="file">Information about source file</param>
 private ControlFlowGraph(GlobalCode globalCode, MethodDecl function, FileInfo file)
 {
     File            = file;
     this.globalCode = globalCode;
     this.visitor    = new CFGVisitor(this);
     start           = visitor.MakeFunctionCFG(function, function.Body);
     PostProcess(visitor);
 }
示例#9
0
        public SourceMethodSymbol(SourceTypeSymbol/*!*/type, MethodDecl/*!*/syntax)
        {
            Contract.ThrowIfNull(type);
            Contract.ThrowIfNull(syntax);

            _type = type;
            _syntax = syntax;

            // TODO: lazily; when using late static binding in a static method, add special <static> parameter, where runtime passes late static bound type
            _params = BuildParameters(syntax.Signature, syntax.PHPDoc).AsImmutable();
        }
示例#10
0
        public SourceMethodSymbol(SourceTypeSymbol /*!*/ type, MethodDecl /*!*/ syntax)
        {
            Contract.ThrowIfNull(type);
            Contract.ThrowIfNull(syntax);

            _type   = type;
            _syntax = syntax;

            // TODO: lazily; when using late static binding in a static method, add special <static> parameter, where runtime passes late static bound type
            _params = BuildParameters(syntax.Signature, syntax.PHPDoc).AsImmutable();
        }
示例#11
0
        /// <summary>
        /// Visit method parameters and method body.
        /// </summary>
        /// <param name="x"></param>
        virtual public void VisitMethodDecl(MethodDecl x)
        {
            VisitElement(x.PHPDoc);

            // function parameters
            VisitList(x.Signature.FormalParams);

            // function return type
            VisitElement(x.ReturnType);

            // function body
            VisitElement(x.Body);
        }
示例#12
0
 void CheckMethodDecl(MethodDecl method)
 {
     Assert.IsTrue(method.Span.Contains(method.Name.Span));
     Assert.IsTrue(method.Span.Contains(method.HeadingSpan));
     Assert.IsTrue(method.Span.Contains(method.ParametersSpan));
     Assert.IsTrue(method.HeadingSpan.Contains(method.Name.Span));
     Assert.IsTrue(method.HeadingSpan.Contains(method.ParametersSpan));
     if (method.Body != null)
     {
         Assert.IsTrue(method.Span.Contains(method.Body.Span));
         Assert.IsTrue(method.HeadingSpan.End <= method.Body.Span.Start);
     }
     Assert.IsTrue(method.Name.Span.End <= method.ParametersSpan.Start);
 }
示例#13
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            m_currentMethod = GetClrMethod(ast.MethodInfo) as MethodBuilder;
            m_ilgen         = m_currentMethod.GetILGenerator();

            foreach (var s in ast.Statements)
            {
                Visit(s);
            }

            //generates return expression
            Visit(ast.ReturnExpression);
            m_ilgen.Emit(OpCodes.Ret);

            return(ast);
        }
示例#14
0
        override public void VisitMethodDecl(MethodDecl x)
        {
            _serializer.StartSerialize(typeof(MethodDecl).Name, SerializeSpan(x.Span), new NodeObj("Name", x.Name.Name.Value),
                                       new NodeObj("Modifiers", MemberAttributesToString(x.Modifiers)));
            SerializePHPDoc(x.PHPDoc);
            _serializer.StartSerialize("FormalParams");
            // method parameters
            foreach (FormalParam p in x.Signature.FormalParams)
            {
                VisitElement(p);
            }
            _serializer.EndSerialize();

            SerializeOptionalProperty("Body", x.Body);

            SerializeOptionalProperty("ReturnType", x.ReturnType);
            _serializer.EndSerialize();
        }
示例#15
0
        /// <summary>
        /// Add method to the current class...
        /// </summary>
        public override void VisitMethodDecl(MethodDecl x)
        {
            // Skip constructors
            if (x.Name == PHP.Core.Reflection.DObject.SpecialMethodNames.Construct)
            {
                return;
            }

            var cmt = x.PHPDoc;

            if (cmt == null)
            {
                return;
            }

            if (cmt.Access == Reflection.PhpMemberAttributes.Public)
            {
                currentClass.Members.Add(GenerateFunctionCode(cmt, x.Name.Value));
            }
        }
示例#16
0
 protected override MethodSymbol CreateSourceMethod(MethodDecl m) => new SourceTraitMethodSymbol(this, m);
示例#17
0
 /// <inheritdoc />
 public override void VisitMethodDecl(MethodDecl x)
 {
     VisitSubroutineExpr <MethodDecl>(base.VisitMethodDecl, x);
 }
示例#18
0
文件: Parser.cs 项目: chenzuo/blue
 protected MethodDecl[] MethodDeclFromArray(ArrayList alParams)
 {
     MethodDecl[] v = new MethodDecl[alParams.Count];
     for(int i = 0; i < alParams.Count; i++)            
         v[i] = (MethodDecl) alParams[i];
         
     return v;
 }
示例#19
0
 /// <summary>
 /// Constructs a confrolflow graph. This method should be used for analysis. It cannot be used for testing.
 /// </summary>
 /// <param name="method">method to construct controlflow graph</param>
 /// <param name="file">Information about source file</param>
 /// <returns>new instace of ControlFlowGraph</returns>
 public static ControlFlowGraph FromMethod(MethodDecl method, FileInfo file)
 {
     return(new ControlFlowGraph(SyntaxParser.functions[method], method, file));
 }
示例#20
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            var method = ast.MethodInfo;

            method.Name = ast.Name.Content;
            method.IsStatic = false;

            //step 1, resolve return type
            var returnTypeNode = ast.ReturnType;
            var returnType = ResolveTypeNode(returnTypeNode);

            method.ReturnType = returnType;

            //step 2, resolve parameter types
            bool allValid = true;
            HashSet<string> paramNames = new HashSet<string>();

            int paramIndex = 1; //0 is "this"
            foreach (var parameter in ast.Parameters)
            {
                var paramTypeNode = parameter.Type;
                var paramType = ResolveTypeNode(paramTypeNode);

                if (paramType == null)
                {
                    allValid = false;
                }

                var paramInfo = new Parameter() { Name = parameter.ParameterName.Content, Type = paramType, Index = paramIndex };

                if (paramNames.Contains(paramInfo.Name))
                {
                    m_errorManager.AddError(c_SE_ParameterDuplicates, parameter.ParameterName.Span, method.Name, paramInfo.Name);
                    allValid = false;
                }
                else
                {
                    paramNames.Add(paramInfo.Name);
                    method.Parameters.Add(paramInfo);
                }

                paramIndex++;
            }

            //step 3, check overloading

            if (returnType == null || !allValid)
            {
                //resolve type failed
                return ast;
            }

            var declType = method.DeclaringType as CodeClassType;

            var methodsSameName = declType.Methods.Where(m => m.Name == method.Name).ToArray();
            foreach (var overloadMethod in methodsSameName)
            {
                if (overloadMethod.Parameters.Count == method.Parameters.Count)
                {
                    bool allTypeSame = true;
                    for (int i = 0; i < overloadMethod.Parameters.Count; i++)
                    {
                        if (overloadMethod.Parameters[i].Type != method.Parameters[i].Type)
                        {
                            allTypeSame = false;
                            break;
                        }
                    }

                    if (allTypeSame)
                    {
                        m_errorManager.AddError(c_SE_MethodDuplicates, ast.Name.Span, method.DeclaringType.Name, method.Name);
                    }
                }
            }

            declType.Methods.Add(method);
            return ast;
        }
示例#21
0
文件: Parser.cs 项目: chenzuo/blue
//-----------------------------------------------------------------------------
// Parse for overloaded operator
// -> mods type 'operator' op '(' paramlist ')' '{' statementlist '}'
//-----------------------------------------------------------------------------
    protected MethodDecl PartialParseOverloadedOp(    
        Modifiers mods, // must be public & static
        TypeSig typeReturn
    )
    {
        /*
        Modifiers modsLegal = new Modifiers(Modifiers.EFlags.Public | Modifiers.EFlags.Static);
        if (modsLegal.Flags != mods.Flags)
            ThrowError_BadModsOnOps(typeReturn.Location);
        */
        if (!mods.IsStatic || !mods.IsPublic)
            ThrowError(E_BadModsOnOps(typeReturn.Location));
        
            
        ReadExpectedToken(Token.Type.cOperator);
        
        // Get the operator
        Token tOp = m_lexer.GetNextToken();
        BinaryExp.BinaryOp op = ConvertToBinaryOp(tOp);
        
        // @todo - Check that it's a valid overloadable op...
        
        // Parse parameters. Expect 2, both values (not ref/out)
        ParamVarDecl [] arParams = ParseParamList();
        if (arParams.Length != 2)
            ThrowError(E_BadParamListOnOps(typeReturn.Location, "Must have 2 parameters"));

        
        for(int i = 0; i < arParams.Length; i++)
        {   
            if (arParams[i].Flow != EArgFlow.cIn)
                ThrowError(E_BadParamListOnOps(arParams[i].Location, "Parameter " + i + " can't be ref/out"));
        }
            
        
        // Read method body. This will include the '{' ... '}'    
        BlockStatement block = ParseStatementBlock();
        
        // Allocate the method decl
        MethodDecl nodeMethod = new MethodDecl(
            op, 
            typeReturn, 
            arParams, 
            block
        );
            
        return nodeMethod;            
        
    }
示例#22
0
文件: AST.cs 项目: chenzuo/blue
    // For non-interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        FieldDecl[] alFields,
        EventDecl [] alEvents,
        TypeDeclBase[] alNestedTypes,
        Modifiers mods,
        bool fIsClass // true for class, false for struct
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        Debug.Assert(alFields != null);
        Debug.Assert(alProperties != null);
        Debug.Assert(alEvents != null);


        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alNestedTypes     = (alNestedTypes == null) ?  m_sEmptyTypeList : alNestedTypes;
        m_alMethods         = alMethods;
        m_alProperties      = alProperties;
        m_alFields          = alFields;
        m_alEvents          = alEvents;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        if (!fIsClass) // structs are implicitly sealed.           
            mods.SetSealed();
            
        m_mods = mods;          
                    
        m_genre = fIsClass ? TypeEntry.Genre.cClass : TypeEntry.Genre.cStruct;
    }
示例#23
0
文件: AST.cs 项目: chenzuo/blue
    // For interface types
    public ClassDecl(
        Identifier idName,         
        TypeSig [] arSuper, // super class & implemented interfaces
        MethodDecl [] alMethods,
        PropertyDecl[] alProperties,
        Modifiers mods    
    ) 
    {        
        Debug.Assert(idName != null);
        Debug.Assert(alMethods != null);
        

        m_strName = idName.Text;
        
        m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper;

        m_alMethods = alMethods;
        m_alProperties = alProperties;
        m_alNestedTypes = m_sEmptyTypeList;
        
        // @todo - this is wrong
        m_filerange = idName.Location;

        //m_mods.FlagSetter = mods.Flags | Modifiers.EFlags.Abstract;
        m_mods = mods;
        m_mods.SetAbstract();
       
        m_genre = TypeEntry.Genre.cInterface;
    }
示例#24
0
 /// <inheritdoc />
 public FunctionValue CreateFunction(MethodDecl declaration, FileInfo declaringScript)
 {
     _statistics.Report(Statistic.CreatedFunctionValues);
     return(new SourceMethodValue(declaration, declaringScript));
 }
示例#25
0
        /// <summary>
        /// Creates program point graph for given method declaration
        /// </summary>
        /// <param name="declaration">Method which program point graph will be created</param>
        /// <param name="file">File info describing where declaration comes from</param>
        /// <returns>Created program point graph</returns>
        internal static ProgramPointGraph FromSource(MethodDecl declaration, FileInfo file)
        {
            var cfg = ControlFlowGraph.ControlFlowGraph.FromMethod(declaration, file);

            return(new ProgramPointGraph(cfg, declaration));
        }
示例#26
0
 internal SourceMethodValue(MethodDecl declaration, FileInfo declaringScript)
     : base(declaration, declaration.Name, declaringScript)
 {
     Declaration = declaration;
 }
示例#27
0
 /// <summary>
 /// Visits MethodDecl. This method will be not called during constructuion cfg. Analysis creates cfg of method via MakeFunctionCFG &lt;T&gt; method.
 /// </summary>
 /// <param name="x">MethodDecl</param>
 public override void VisitMethodDecl(MethodDecl x)
 {
     //BasicBlock functionBasicBlock = MakeFunctionCFG(x, x.Body);
 }
示例#28
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            m_currentMethod = ast.MethodInfo;
            m_currentMethodParameters = new VariableCollection<Parameter>();

            foreach (var param in m_currentMethod.Parameters)
            {
                m_currentMethodParameters.Add(param);
            }

            m_currentMethodVariables = new VariableCollection<VariableInfo>();

            foreach (var statement in ast.Statements)
            {
                Visit(statement);
            }

            Visit(ast.ReturnExpression);

            return ast;
        }
示例#29
0
 public MainClass(Identifier className, MethodDecl mainMethod)
 {
     this.className  = className;
     this.mainMethod = mainMethod;
 }
示例#30
0
 public override void VisitMethodDecl(MethodDecl x)
 {
     _name = x.Name.Value;
 }
示例#31
0
文件: AST.cs 项目: chenzuo/blue
    // Resolve all the fields in this type. Only class/struct should call
    // this. 
    void FixFields(ISemanticResolver s, ICLRtypeProvider provider)
    {
        Debug.Assert(!IsInterface);
        
        int cInstance = 0;
        int cStatic = 0;

        foreach(FieldDecl f in m_alFields)
        {
            f.ResolveMember(m_symbol, s, provider);
            //f.Symbol.SetInfo(provider);

            if (f.InitialExp != null)
                if (f.Mods.IsStatic) 
                    cStatic++; 
                else 
                    cInstance++;
        }


        Statement [] stmtStatic = new Statement[cStatic];
        Statement [] stmtInstance = new Statement[cInstance];

        cStatic = 0;
        cInstance = 0;
        // Fields can have assignments. Make 2 helper functions to do
        // assignment for static & instance fields
        foreach(FieldDecl f in m_alFields)
        {
            if (f.InitialExp != null)
            {           
                Statement stmt = new ExpStatement(new AssignStmtExp(
                    new SimpleObjExp(new Identifier(f.Name, f.Location)), f.InitialExp));

                if (f.Mods.IsStatic)
                {
                    stmtStatic[cStatic] = stmt;
                    cStatic++;
                } 
                else 
                {
                    if (IsStruct)
                    {
                        //ThrowError_NoFieldInitForStructs(s, f);
                        ThrowError(SymbolError.NoFieldInitForStructs(f));
                    }
                    
                    stmtInstance[cInstance] = stmt;
                    cInstance ++;
                }
            } // end has initializer expression
        }

        Debug.Assert(cStatic == stmtStatic.Length);
        Debug.Assert(cInstance == stmtInstance.Length);

        // Create methods to initialize the static & instance fields.
        // Then the ctors can call these methods
        if (cStatic != 0)
        {
            Modifiers mods = new Modifiers();
            mods.SetStatic();
            mods.SetPrivate();
            
            m_nodeStaticInit = new MethodDecl(
                new Identifier(".StaticInit", this.Location), 
                new ResolvedTypeSig(typeof(void), s),                    
                new ParamVarDecl[0],
                new BlockStatement(null, stmtStatic),                     
                mods
                );

            //AddMethodToList(m_nodeStaticInit);
        } 
        if (cInstance != 0)
        {   
            Modifiers mods = new Modifiers();
            mods.SetPrivate();
            
            m_nodeInstanceInit = new MethodDecl(
                new Identifier(".InstanceInit", this.Location),                     
                new ResolvedTypeSig(typeof(void), s),
                new ParamVarDecl[0],
                new BlockStatement(null, stmtInstance),                     
                mods
                );
            AddMethodToList(m_nodeInstanceInit);
        }        
    } // end fields
示例#32
0
文件: Parser.cs 项目: chenzuo/blue
//-----------------------------------------------------------------------------
// Do a partial parse of the method decl (includes ctor), 
// Pass in the parameters that we've already parsed, which is everything 
// before the first '('. 
//
// ** Rules **
// methoddecl -> attrs type id '(' paramlist ')' '{' statementlist '}'
// methoddecl -> attrs type id '(' paramlist ')' ';'   // if abstract
//-----------------------------------------------------------------------------
    protected MethodDecl PartialParseMethodDecl(
        Modifiers mods, 
        TypeSig typeReturn,
        Identifier stMemberName,
        Genre genre // applies additional restrictions
    )
    {   
    // We should have already parsed the 'attrs type id'. So continue with param list
        
        ParamVarDecl [] arParams = ParseParamList();
        
        // Structs can't define a default ctor
        if ((genre == Genre.cStruct) && (typeReturn == null) && (arParams.Length == 0))
        {
            ThrowError(E_NoDefaultCtorForStructs(m_lexer.PeekNextToken().Location));
        }
        

        CtorChainStatement chain  = null;
    // If this is a constructor, then we can chain it
    // ctordecl -> mods type id '(' param_list ')' ':' (this|base) '(' param_list ')' '{' statementlist '}'
    // ctor can't be abstract / virtual. Can be static
        if (typeReturn == null)
        {   
            Token t = m_lexer.PeekNextToken();
            if (genre == Genre.cInterface)
            {
                ThrowError(E_NoCtorOnInterface(t.Location));
            }        
            
            if (t.TokenType == Token.Type.cColon)
            {                
                ConsumeNextToken();
                // Currently, 'base' & 'this' are just identifiers, not specific tokens
                Identifier id = this.ReadExpectedIdentifier();
                Exp [] arParams2 = ParseExpList();

                CtorChainStatement.ETarget eTarget = (CtorChainStatement.ETarget) (-1);
                
                if (id.Text == "this")
                    eTarget = CtorChainStatement.ETarget.cThis;
                else if (id.Text == "base")
                {
                    if (genre == Genre.cStruct)
                    {
                        ThrowError(E_NoBaseChainForStructs(id.Location));
                    }
                    eTarget = CtorChainStatement.ETarget.cBase;
                }
                else 
                {
                    ThrowError(E_BadCtorChain(id));
                }

                chain = new CtorChainStatement(eTarget, arParams2);
            } 
            else 
            {
                // If no explicit ctor chain, then we still have an implicit "base ()"
                // (except for static ctors, which can't be chained)
                if (!mods.IsStatic && (genre == Genre.cClass))                
                {                
                    chain = new CtorChainStatement();
                }
            }

            // Static ctors can't be chained
            if (chain != null)
            {
                if (mods.IsStatic)                
                {
                    ThrowError(E_NoChainForStaticCtor(stMemberName.Location));
                }
            }
        }


    // Parse body
        BlockStatement block = null;

        if (mods.IsAbstract)        
        {
        // For abstract methods, no body. Just end with a ';'
            ReadExpectedToken(Token.Type.cSemi);        
        } else 
        {        
        // Read method body. This will include the '{' ... '}'    
            block = ParseStatementBlock();
        }


        if (typeReturn == null)
        {
            if (mods.IsAbstract | mods.IsVirtual | (block == null))            
            {
                ThrowError(E_NoAbstractCtor(stMemberName));
            }
        }
        
        // Allocate the method decl
        MethodDecl nodeMethod = new MethodDecl(
            stMemberName, 
            typeReturn, 
            arParams, 
            block,
            mods);

        // If we have a chain, inject it into the statements
        if (chain != null)
        {
            nodeMethod.Body.InjectStatementAtHead(chain);
            chain.FinishInit(nodeMethod);
        }

        return nodeMethod;
    }
示例#33
0
 public SourceTraitMethodSymbol(SourceTraitTypeSymbol type, MethodDecl syntax)
     : base(type, syntax)
 {
 }
示例#34
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            var method = ast.MethodInfo;

            method.Name     = ast.Name.Content;
            method.IsStatic = false;

            //step 1, resolve return type
            var returnTypeNode = ast.ReturnType;
            var returnType     = ResolveTypeNode(returnTypeNode);

            method.ReturnType = returnType;

            //step 2, resolve parameter types
            bool             allValid   = true;
            HashSet <string> paramNames = new HashSet <string>();

            int paramIndex = 1; //0 is "this"

            foreach (var parameter in ast.Parameters)
            {
                var paramTypeNode = parameter.Type;
                var paramType     = ResolveTypeNode(paramTypeNode);

                if (paramType == null)
                {
                    allValid = false;
                }

                var paramInfo = new Parameter()
                {
                    Name = parameter.ParameterName.Content, Type = paramType, Index = paramIndex
                };

                if (paramNames.Contains(paramInfo.Name))
                {
                    AddError(c_SE_ParameterDuplicates, parameter.ParameterName.Span, method.Name, paramInfo.Name);
                    allValid = false;
                }
                else
                {
                    paramNames.Add(paramInfo.Name);
                    method.Parameters.Add(paramInfo);
                }

                paramIndex++;
            }

            //step 3, check overloading

            if (returnType == null || !allValid)
            {
                //resolve type failed
                return(ast);
            }

            var declType = method.DeclaringType as CodeClassType;

            var methodsSameName = declType.Methods.Where(m => m.Name == method.Name).ToArray();

            foreach (var overloadMethod in methodsSameName)
            {
                if (overloadMethod.Parameters.Count == method.Parameters.Count)
                {
                    bool allTypeSame = true;
                    for (int i = 0; i < overloadMethod.Parameters.Count; i++)
                    {
                        if (overloadMethod.Parameters[i].Type != method.Parameters[i].Type)
                        {
                            allTypeSame = false;
                            break;
                        }
                    }

                    if (allTypeSame)
                    {
                        AddError(c_SE_MethodDuplicates, ast.Name.Span, method.DeclaringType.Name, method.Name);
                    }
                }
            }

            declType.Methods.Add(method);
            return(ast);
        }
示例#35
0
 public override void VisitMethodDecl(MethodDecl x)
 {
     // ignored
 }
示例#36
0
 /// <summary>
 /// Determines whether method has <c>$this</c> variable.
 /// </summary>
 public static bool HasThisVariable(MethodDecl method)
 {
     return(method != null && (method.Modifiers & PhpMemberAttributes.Static) == 0);
 }
示例#37
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            m_currentMethod = GetClrMethod(ast.MethodInfo) as MethodBuilder;
            m_ilgen = m_currentMethod.GetILGenerator();

            foreach (var s in ast.Statements)
            {
                Visit(s);
            }

            //generates return expression
            Visit(ast.ReturnExpression);
            m_ilgen.Emit(OpCodes.Ret);

            return ast;
        }
示例#38
0
 private static ClassMethodDeclarationExpression ToClassMethodDeclarationExpression(MemberAttributes attributes, MethodDecl e)
 {
     return(new ClassMethodDeclarationExpression(
                ToNameOfMethod(e.Name),
                ToDeclarationSignature(e.Signature),
                Parse(e.Body),
                attributes
                ));
 }
示例#39
0
        public override AstNode VisitMethodDecl(MethodDecl ast)
        {
            m_currentMethod = ast.MethodInfo;
            m_currentVariableIndex = 0;
            m_currentMethodParameters = new VariableCollection<Parameter>();

            foreach (var param in m_currentMethod.Parameters)
            {
                m_currentMethodParameters.Add(param);
            }

            m_currentMethodVariables = new VariableCollection<VariableInfo>();

            if (ast.Statements == null || ast.ReturnExpression == null)
            {
                m_errorManager.AddError(c_SE_NotSupported, ast.Name.Span, "A method must have body defined");
                return ast;
            }

            foreach (var statement in ast.Statements)
            {
                Visit(statement);
            }

            Visit(ast.ReturnExpression);

            return ast;
        }
示例#40
0
 /// <inheritdoc />
 public FunctionValue CreateFunction(MethodDecl declaration, FileInfo declaringScript)
 {
     return(Snapshot.CreateFunction(declaration, declaringScript));
 }
示例#41
0
文件: AST.cs 项目: chenzuo/blue
    void FixCtors(
        ISemanticResolver s,
        ICLRtypeProvider provider
    )
    {
        // Add default ctor
        bool fFoundCtor = m_symbol.HasMethodHeader(Name);
            
        // Note that structs don't have a default ctor, but can have other ctors                        
        // But add a default ctor for classes if we don't have one.
        if (!fFoundCtor && IsClass)
        {                
            CtorChainStatement stmtChain = new CtorChainStatement();
            Modifiers mods = new Modifiers();
            mods.SetPublic();

            MethodDecl mdecl = new MethodDecl(
                new Identifier(Name, this.Location), 
                null, 
                null, 
                new BlockStatement(new LocalVarDecl[0], new Statement[] { stmtChain }), 
                //new AST.Modifiers(AST.Modifiers.EFlags.Public)
                mods
                );

            stmtChain.FinishInit(mdecl);
                
            mdecl.ResolveMember(m_symbol,s, null);
            mdecl.Symbol.SetInfo(provider);
                
            // Add to the end of the m_alMethods array so that we get codegen'ed!
            AddMethodToList(mdecl);
                
            Debug.Assert(m_symbol.HasMethodHeader(Name));
        }

        // @todo - perhaps we could just make the static initializer a static-ctor..
        // If we don't have a static ctor, but we do have static data, then add
        // a static ctor
        if (m_nodeStaticInit != null) 
        {
            bool fFoundStaticCtor = false;
            foreach(MethodDecl m in m_alMethods)
            {
                if (m.Mods.IsStatic && m.IsCtor)
                {
                    fFoundStaticCtor = true;
                    break;
                }
            }

            if (!fFoundStaticCtor)
            {
                Modifiers mods = new Modifiers();
                mods.SetStatic();
                mods.SetPublic();
                    
                MethodDecl mdecl2 = new MethodDecl(
                    new Identifier(Name, this.Location),
                    null,
                    null,
                    new BlockStatement(null, new Statement[]{}),
                    //new Modifiers(AST.Modifiers.EFlags.Static | Modifiers.EFlags.Public)
                    mods
                    );
                mdecl2.ResolveMember(m_symbol, s, null);
                mdecl2.Symbol.SetInfo(provider);
                AddMethodToList(mdecl2);
            }
        } // end check static ctor
    } // fix ctors
示例#42
0
 public void FinishInit(MethodDecl nodeCtor)
 {
     Debug.Assert(m_nodeCtor == null);
     m_nodeCtor = nodeCtor;
 }
示例#43
0
 /// <summary>
 /// Determines whether method has <c>$this</c> variable.
 /// </summary>
 public static bool HasThisVariable(MethodDecl method)
 {
     return method != null && (method.Modifiers & PhpMemberAttributes.Static) == 0;
 }
示例#44
0
文件: AST.cs 项目: chenzuo/blue
 // Helper to add automatically generated methods to the method list
 // Useful for properties, default ctors, and events
 public void AddMethodToList(MethodDecl m)
 {
     #if DEBUG
     // Ctor can skip this check since we explicitly resolve it and it can't
     // have any conflicting inheritence checks
     if (!m.IsCtor)
     {
         Debug.Assert(!m_fLockMethodList, "Can't add members after we start resolving");
     }
     
     // Make sure method isn't already in scope
     foreach(MethodDecl m2 in m_alMethods)
     {            
         Debug.Assert(m != m2, "Method '" + m.Name + "' already added");    
         Debug.Assert(m.Name != m2.Name, "Method name '" + m.Name + "' already added. Shouldn't add overload");        
     }
     #endif
 
     MethodDecl [] temp = new MethodDecl[m_alMethods.Length + 1];
     temp[0] = m;
     m_alMethods.CopyTo(temp, 1);
     m_alMethods = temp;
 }
示例#45
0
 public override void VisitMethodDecl(MethodDecl x)
 {
     VisitRoutineDecl(x, x.Signature, x.Body, x.Name, x.ReturnType, x.Modifiers);
 }
示例#46
0
文件: AST.cs 项目: chenzuo/blue
 public PropertyDecl(
     Identifier idName, TypeSig tType,
     ParamVarDecl param, // optional param, may be null
     BlockStatement stmtGet, bool fHasGet,
     BlockStatement stmtSet, bool fHasSet,
     Modifiers mods
 )
 {
     m_stmtGet = stmtGet;
     m_stmtSet = stmtSet;
     
     m_idName = idName;
     m_tType = tType;
     
     Debug.Assert(idName != null);
     Debug.Assert(tType != null);
     Debug.Assert(fHasGet || fHasSet);
             
     m_mods = mods;
     
     //m_expParam = expParam;
             
     // Spoof bodies. Note that we just pass the attributes (static, virtual)
     // right to the new methods. Also, if we're abstract, the XXXStmt will be null
     // and the methods will just deal with that too.
     if (fHasGet)
     {
         Debug.Assert(mods.IsAbstract ^ (stmtGet != null));
     
         // T get_XXX();
         Identifier idName2 = new Identifier("get_"+Name.Text, m_idName.Location);
         m_declGet = new MethodDecl(
             idName2,
             m_tType,
             (param == null) ? 
                 new ParamVarDecl[0] : 
                 new ParamVarDecl[] { param }, 
             GetStmt, 
             mods
         );
     }
     
     if (fHasSet)
     {
         Debug.Assert(mods.IsAbstract ^ (stmtSet != null));
         
         // void set_XXX(T value);
         Identifier idP1 = new Identifier("value", new FileRange());
         
         ParamVarDecl T = new ParamVarDecl(idP1, (NonRefTypeSig) m_tType, EArgFlow.cIn);
         
         ParamVarDecl [] p = (param == null) ? 
             new ParamVarDecl[] { T } :
             new ParamVarDecl[] { param, T };
         
         Identifier idName2 = new Identifier("set_"+Name.Text, m_idName.Location);
         AST.TypeSig tVoid = new SimpleTypeSig(new SimpleObjExp(new Identifier("void", new FileRange())));
         //AST.TypeSig tVoid = new ResolvedTypeSig(typeof(void), s);
         m_declSet = new MethodDecl(idName2, tVoid,p, SetStmt, mods);
     }        
 }