コード例 #1
0
 public override void Visit(MethodCallExpressionNode node)
 {
     Gen("push", "ecx", "", "Save 'this' pointer for current function");
     if (node.expressionList != null)
         for (int x = node.expressionList.expressionList.Count - 1; x >= 0; x--)
         {
             node.expressionList.ExpressionAtIndex(x).Accept(this);
             Gen("push", "eax", "", "Pushing Parameter " + (x + 1).ToString());
         }
     node.expression.Accept(this);
     Gen("mov", "ecx", "eax");
     Gen("mov", "eax", "[ecx]");
     ClassDefinition classDefinition = Analysis.Environment.Classes.Lookup(node.expression.ExpressionType.Name);
     MethodDefinition methodDefinition = Analysis.Environment.LookupMethodInClass(node.identifier.name, classDefinition);
     Gen("call", "dword ptr [eax+" + methodDefinition.Location.ToString() + "]", "", "Calling method " + classDefinition.Name + "." + methodDefinition.Name + "()");
     if (node.expressionList != null)
         if (node.expressionList.expressionList.Count > 0)
             Gen("add", "esp", methodDefinition.SizeOfParametersInBytes.ToString());
     Gen("pop", "ecx", "", "Recover 'this' pointer for current function");
 }
コード例 #2
0
        public override void Visit(MethodCallExpressionNode node)
        {
            node.expression.Accept(this);

            if (node.expression.ExpressionType.GetType() != typeof(ClassType))
                throw new Exception("Object used for method call is not an instance of any Class");

            ClassDefinition classDefinition = Analysis.Environment.Classes.Lookup(node.expression.ExpressionType.Name);
            MethodDefinition methodDefinition;

            try
            {
                methodDefinition = Analysis.Environment.LookupMethodInClass(node.identifier.name, classDefinition);
            }
            catch (Exception)
            {
                throw new Exception("No definition exists for method '" + node.identifier.name + "' in class '" + node.expression.ExpressionType.Name + "'!");
            }
            if(!(node.expressionList == null && methodDefinition.Parameters.Count == 0))
            {
                if (node.expressionList != null && node.expressionList.expressionList.Count == methodDefinition.Parameters.Count)
                {
                    for (int x = 0; x < methodDefinition.Parameters.Count; x++)
                    {
                        node.expressionList.ExpressionAtIndex(x).Accept(this);
                        if(node.expressionList.ExpressionAtIndex(x).ExpressionType.GetType() == typeof(ClassType))
                        {
                            if(!IsClassCompatible((ClassType)node.expressionList.ExpressionAtIndex(x).ExpressionType, (ClassType)methodDefinition.Parameters.ItemAt(x).ParameterType))
                                throw new Exception("Type mismatch in method call at parameter " + x);
                        }
                        else
                            if(!AreTypeCompatible(node.expressionList.ExpressionAtIndex(x).ExpressionType.GetType(), methodDefinition.Parameters.ItemAt(x).ParameterType.GetType()))
                                throw new Exception("Type mismatch in method call at parameter " + x);
                    }
                }
                else
                    throw new Exception("Method '" + methodDefinition.Name + "' takes " + methodDefinition.Parameters.Count + " Paramater(s)");
            }

            node.ExpressionType = methodDefinition.ReturnType;
        }
コード例 #3
0
ファイル: BaseVisitor.cs プロジェクト: ssarangi/minijava
 public virtual void Visit(MethodCallExpressionNode node)
 {
     node.expression.Accept(this);
     if (node.expressionList != null)
         for (int x = 0; x < node.expressionList.expressionList.Count; x++)
             node.expressionList.ExpressionAtIndex(x).Accept(this);
 }
コード例 #4
0
 public override void Visit(MethodCallExpressionNode node)
 {
     Console.WriteLine(this.indentation + "<object_instance>." + node.identifier.name + "()           ---- Method Call -----");
     indentation = indentation + "   ";
     Console.WriteLine(this.indentation + "object_instance");
     indentation = indentation + "   ";
     node.expression.Accept(this);
     indentation = indentation.Substring(0, indentation.Length - 3);
     if (node.expressionList != null)
     {
         Console.WriteLine(this.indentation + "Paramaters");
         indentation = indentation + "   ";
         for (int x = 0; x < node.expressionList.expressionList.Count; x++)
         {
             node.expressionList.ExpressionAtIndex(x).Accept(this);
         }
         indentation = indentation.Substring(0, indentation.Length - 3);
     }
     indentation = indentation.Substring(0, indentation.Length - 3);
 }