public static void SetEntryPoint(MethodDef method)
        {
            if (EntryPoint != null)
                throw new Exception("EntryPoint is already set.");

            EntryPoint = method;
        }
Ejemplo n.º 2
0
        public Block(MethodDef method, Block parent)
            : base(method, parent)
        {
            statements = new List<Statement>();

            if (parent == null)
            {
                localScope = new LocalScope(this, null);
            }
            else
            {
                localScope = new LocalScope(this, parent.localScope);
            }
        }
 public void AddMethod(MethodDef method)
 {
     methods.Add(method);
 }
 public static ITypeDefinition AnalyzeExpression(MethodDef method, Expression expression,
                                                 bool shallReturnResult)
 {
     return null;
 }
        private void ParseSubroutine()
        {
            Modifier modifiers;

            MemberName name;
            ParameterList paramList;

            TokenInfo token = tokenQueue.Dequeue();

            bool flag;

            modifiers = ParseMethodModifiers();

            name = ParseMemberName();
            paramList = ParseMethodParameters();

            TokenInfo token2 = Tokenizer.PeekToken();

            if (token.Is(Token.Handles))
            {
                FullNamedExpression expr = ParseTypeName();

                if (expr == null)
                {
                    Report.AddError("?", "Identifier expected.", token.SourceFile,
                                    new SourceSpan(token.GetSourceLocation(), default(SourceLocation)), null);
                }
            }

            TokenInfo token3 = statementSymbols.ElementAt(statementSymbols.Count() - 1);

            TokenList symbols = statementSymbols;

            ExpectEndOfStatementOrEat();

            method = new SubroutineDef((ClassStructOrModuleDef) type, name.BaseName, paramList, modifiers);

            flag = ParseSubroutineBlock();

            if (!flag)
            {
                Report.AddItem(VBErrors.EndSubExpected, SourceFile, token.GetSpan(token3), symbols);
            }

            paramList.SetMethod(method);
            method.SetBody(CloseBlock());
        }
        private void ParseFunction()
        {
            TokenInfo token = tokenQueue.Dequeue();

            Modifier modifiers;

            MemberName name;
            ParameterList paramList;
            FullNamedExpression returnType;

            bool flag;

            modifiers = ParseMethodModifiers();

            name = ParseMemberName();
            paramList = ParseMethodParameters();

            Expect(Token.As);
            returnType = ParseFullName();

            TokenInfo token2 = statementSymbols.ElementAt(statementSymbols.Count() - 1);

            TokenList symbols = statementSymbols;

            ExpectEndOfStatementOrEat();

            method = new FunctionDef((ClassStructOrModuleDef) type, name.BaseName, returnType, paramList, modifiers);

            flag = ParseFunctionBlock();

            if (!flag)
            {
                Report.AddItem(VBErrors.EndFunctionExpected, SourceFile, token.GetSpan(token2),
                               symbols);
            }

            paramList.SetMethod(method);
            method.SetBody(CloseBlock());
        }
        private void ParseField()
        {
            #region Old

            //bool b = Expect(Token.LeftSquareBracket);

            //TokenInfo token = Tokenizer.PeekToken();

            //if (token.Is(Token.Identifier) || token.Is(Token.ReservedWord))
            //{

            //}

            //if (Expect(Token.As))
            //{
            //    token = Tokenizer.PeekToken();

            //    if (Expect(Token.Identifier))
            //    {

            //    }
            //    else
            //    {

            //    }
            //}
            //else
            //{

            //}

            //if (Expect(Token.Equality))
            //{
            //    token = Tokenizer.PeekToken();

            //    if (Expect(Token.Identifier))
            //    {

            //    }
            //    else
            //    {

            //    }
            //}
            //else
            //{

            //}

            #endregion

            TokenInfo token;

            Modifier modifiers;
            SimpleName name;
            FullNamedExpression type;
            Expression expr;

            modifiers = ParseMethodModifiers();

            token = tokenQueue.Dequeue();

            name = null;
            type = null;
            expr = null;


            if (token.Is(Token.Identifier))
            {
                name = new SimpleName(statement, token.Value,
                                      new SourceData(token.GetSpan(token), SourceFile, statementSymbols));

                if (EatOptional(Token.As))
                {
                    type = ParseFullName();
                }

                TokenInfo token3 = Tokenizer.PeekToken();

                if (EatOptional(Token.Equality))
                {
                    EatOptional(Token.EOL);

                    //Set parse context to initializer
                    MethodDef initializer;

                    if ((modifiers & Modifier.Shared) == Modifier.Shared)
                    {
                        initializer = (MethodDef) this.type.GetTypeInitializer();
                    }
                    else
                    {
                        initializer = (MethodDef) this.type.GetDefaultConstructor();
                    }

                    //Initalize context
                    method = initializer;
                    block = method.Body;
                    var assignStmt = new ExpressionStatement(initializer.Body);
                    statement = assignStmt;

                    //Parse initialization expression
                    expr = ParseExpression();

                    //Build initialization expression statement
                    assignStmt.SetExpression(
                        new BinaryExpression(assignStmt, Operator.Assign,
                                             new VariableAccess(assignStmt,
                                                                new SimpleName(assignStmt, name, null), null),
                                             expr, null));

                    //Add statement
                    initializer.Body.AddStatement(assignStmt);

                    //Reset context to null
                    method = null;
                    block = null;
                    statement = null;

                    if (expr == null)
                    {
                        Report.AddItem(VBErrors.ExpressionExpected, SourceFile,
                                       token3.GetSpan(token3), statementSymbols);
                    }
                }

                TokenInfo token4 = Tokenizer.PeekToken();

                if (token4.Is(Token.EOL))
                {
                    //GetNextToken(); //*
                    resetStmtTokens();
                }
                else
                {
                    ExpectEndOfStatementOrEat();
                }
            }
            else
            {
                GetNextToken();
                TokenInfo token2 = Tokenizer.PeekToken();
                Report.AddItem(VBErrors.IdentifierExpected, SourceFile,
                               new SourceSpan(token.GetSourceLocation(), token2.GetSourceLocation()), statementSymbols);
                EatToEOL();
            }

            var fieldDef = new FieldDef(this.type, name, type, modifiers);
            fieldDef.SetInitalizationExpression(expr);

            ((ClassStructOrModuleDef) this.type).AddField(fieldDef);
        }
        public IMethodDefinition CreateAndGetAccessor(Modifier modifiers)
        {
            if (Accessor == null)
            {
                Accessor = new MethodDef((ClassStructOrModuleDef) Parent, "get_" + Name, PropertyType, parameters,
                                         modifiers);
                ((ClassStructOrModuleDef) Parent).AddMethod((MethodDef) Accessor);
            }

            return Accessor;
        }
        public IMethodDefinition CreateAndGetAssigner(Modifier modifiers)
        {
            if (Assigner == null)
            {
                Assigner = new MethodDef((ClassStructOrModuleDef) Parent, "set_" + Name,
                                         new SimpleName(null, "Void", null), parameters, modifiers);
                ((ClassStructOrModuleDef) Parent).AddMethod((MethodDef) Assigner);
            }

            return Assigner;
        }