Example #1
0
 public StatementParser(Token[] tokens, IParsingContext[] parsingContexts, MethodDefinition containingMethod)
 {
     mTokens = tokens;
     mParsingContexts = parsingContexts;
     mContainingMethod = containingMethod;
     Reset();
 }
Example #2
0
 public virtual void Visit(MethodDefinition methodDefinition)
 {
     if (methodDefinition.Body != null)
     {
         Visit(methodDefinition.Body);
     }
 }
Example #3
0
        private void ParseMethod(ITypeMemberContainer memberContainer, string memberDataTypeName, string memberName)
        {
            var xMethodDefinition = new MethodDefinition(mParsingContexts.ToArray(), memberName, (TypeReference)memberContainer);
            xMethodDefinition.ReturnTypeString = memberDataTypeName;
            memberContainer.Members.Add(xMethodDefinition);
            // for now:
            while (!IsMatch(')'))
            {
                ParseParameterDefinition(xMethodDefinition);
                if (!IsMatch(')'))
                {
                    if (!IsMatch(','))
                    {
                        Error("Comma or ) expected!");
                    }
                    else
                    {
                        Move();
                    }
                }
            }
            Match(')');
            Match('{');
            xMethodDefinition.Body = new MethodBodyDefinition()
            {
                MethodDefinition = xMethodDefinition
            };

            ParseStatements(xMethodDefinition);
            Match('}');
        }
Example #4
0
 public override void Visit(MethodDefinition methodDefinition)
 {
     var xCurType = TypesMap[methodDefinition.DeclaringType];
     var xMethod = new MCM.MethodDefinition
     {
         ContainingTypeDefinition = xCurType,
         InternFactory = mHostEnvironment.InternFactory,
         IsCil = true,
         IsStatic = true,
         Name = mHostEnvironment.NameTable.GetNameFor(methodDefinition.Name),
         Visibility = TypeMemberVisibility.Private
     };
     if (methodDefinition.ReturnType is BaseTypeDefinition)
     {
         xMethod.Type = TypesMap[methodDefinition.ReturnType];
     }
     else
     {
         var xAsmName = mHostEnvironment.NameTable.GetNameFor(methodDefinition.ReturnType.Assembly.Name);
         var xAsm = mHostEnvironment.LoadAssembly(new AssemblyIdentity(xAsmName, "", new Version(), new byte[0], methodDefinition.ReturnType.Assembly.Location));
         if (xAsm == null)
         {
             throw new Exception("Assembly not found!");
         }
         // todo: add support for generic parameters
         var xTypeRef = UnitHelper.FindType(mHostEnvironment.NameTable, xAsm, methodDefinition.ReturnType.FullName);
         xMethod.Type = xTypeRef;
     }
     xCurType.Methods.Add(xMethod);
     MethodsMap.Add(methodDefinition, xMethod);
     base.Visit(methodDefinition);
 }
Example #5
0
        public override void Visit(MethodDefinition methodDefinition)
        {
            var xMethodDef = MethodsMap[methodDefinition];
            mILGenerator = new ILGenerator(mHostEnvironment, xMethodDef);
            mBody = new ILGeneratorMethodBody(mILGenerator, true, 65000);
            mBody.MethodDefinition=xMethodDef;
            xMethodDef.Body=mBody;

            base.Visit(methodDefinition);
        }
Example #6
0
        public override void Visit(MethodDefinition methodDefinition)
        {
            mOutput.Write("{0} {1}(", methodDefinition.ReturnType.FullName, methodDefinition.Name);
            for (int i = 0; i < methodDefinition.Parameters.Count; i++)
            {
                mOutput.Write("{0} {1}", methodDefinition.Parameters[i].ParameterType.FullName, methodDefinition.Parameters[i].Name);

                if (i < (methodDefinition.Parameters.Count - 1))
                {
                    mOutput.Write(", ");
                }
            }
            mOutput.WriteLine(")");
            mOutput.WriteLine("{{");
            mOutput.Indent();
            {
                base.Visit(methodDefinition);
            }
            mOutput.Unindent();
            mOutput.WriteLine("}}");
        }
Example #7
0
 private void ParseStatements(MethodDefinition methodDef)
 {
     while (!IsMatch('}'))
     {
         if (IsMatch(Tag.Identifier))
         {
             var xValue = ((Word)mToken).Value;
             switch (mKeywords.IndexOf(xValue))
             {
                 case Keywords.ReturnIdx:
                     {
                         Move();
                         var xStatement = new ParsableReturnStatement();
                         xStatement.MethodBody = methodDef.Body;
                         xStatement.ParseEngine = this;
                         xStatement.ParsingContexts = mParsingContexts.ToArray();
                         var xStatementTokens = new List<Token>();
                         while (!IsMatch(';'))
                         {
                             xStatementTokens.Add(mToken);
                             Move();
                         }
                         Move(); // move past the ;
                         xStatement.Tokens = xStatementTokens.ToArray();
                         methodDef.Body.Statements.Statements.Add(xStatement);
                         break;
                     }
                 case -1:
                     {
                         var xStatementTokens = new List<Token>();
                         while (!IsMatch(';'))
                         {
                             xStatementTokens.Add(mToken);
                             Move();
                         }
                         Move(); // move past the ;
                         var xStatement = new ParsableExpressionStatement();
                         xStatement.MethodBody = methodDef.Body;
                         xStatement.Tokens = xStatementTokens.ToArray();
                         xStatement.ParseEngine = this;
                         xStatement.ParsingContexts = mParsingContexts.ToArray();
                         methodDef.Body.Statements.Statements.Add(xStatement);
                         break;
                     }
             }
             continue;
         }
         throw new Exception("Token not supported: " + mToken);
     }
 }
Example #8
0
 private void ParseParameterDefinition(MethodDefinition methodDefinition)
 {
     if (!IsMatch(Tag.Identifier))
     {
         // todo: add support for keywords ref, out, params
         Error("Identifier not expected!");
     }
     var xType = ReadFullIdentifier(true);
     // todo: add support for pointer types
     string xParamName = ReadFullIdentifier(false);
     var xParamDef = new ParameterDefinition(mParsingContexts.ToArray())
     {
         Name = xParamName,
         ParameterTypeName = xType
     };
     methodDefinition.Parameters.Add(xParamDef);
 }