public override void CaseAMethodDecl(AMethodDecl node)
        {
            if (node.GetNative() == null && node.GetBlock() == null)
                return;
            if (node.GetStatic() != null)
                return;

            string inputStr = "native " + TypeToString(node.GetReturnType()) + " " + node.GetName().Text +
                                 "(";
            bool first = true;
            foreach (AALocalDecl formal in node.GetFormals())
            {
                if (!first)
                    inputStr += ", ";
                inputStr += TypeToString(formal.GetType()) + " " + formal.GetName().Text;
                first = false;
            }
            inputStr += ");";

            writer.WriteLine(inputStr);

            AStructDecl str = Util.GetAncestor<AStructDecl>(node);
            List<AMethodDecl> methodList;
            if (str != null)
                methodList = StructMethods[str];
            else
                methodList = Methods;
            string sig = Util.GetMethodSignature(node);
            if (methodList.Any(otherMethod => Util.GetMethodSignature(otherMethod) == sig))
            {
                return;
            }

            methodList.Add(node);
            node.SetBlock(null);
            node.Parent().RemoveChild(node);
        }
예제 #2
0
 public override void CaseAMethodDecl(AMethodDecl node)
 {
     InAMethodDecl(node);
     if (node.GetBlock() != null)
     {
         node.GetBlock().Apply(this);
     }
     {
         Object[] temp = new Object[node.GetFormals().Count];
         node.GetFormals().CopyTo(temp, 0);
         for (int i = temp.Length - 1; i >= 0; i--)
         {
             ((PLocalDecl)temp[i]).Apply(this);
         }
     }
     if (node.GetName() != null)
     {
         node.GetName().Apply(this);
     }
     if (node.GetReturnType() != null)
     {
         node.GetReturnType().Apply(this);
     }
     if (node.GetDelegate() != null)
     {
         node.GetDelegate().Apply(this);
     }
     if (node.GetInline() != null)
     {
         node.GetInline().Apply(this);
     }
     if (node.GetNative() != null)
     {
         node.GetNative().Apply(this);
     }
     if (node.GetStatic() != null)
     {
         node.GetStatic().Apply(this);
     }
     if (node.GetTrigger() != null)
     {
         node.GetTrigger().Apply(this);
     }
     if (node.GetVisibilityModifier() != null)
     {
         node.GetVisibilityModifier().Apply(this);
     }
     OutAMethodDecl(node);
 }
예제 #3
0
 public override void OutAMethodDecl(AMethodDecl node)
 {
     //If void return is missing, insert it.
     if (node.GetReturnType() is AVoidType && node.GetBlock() != null)
     {
         AABlock block = (AABlock)node.GetBlock();
         bool insertReturn = false;
         while (true)
         {
             if (block.GetStatements().Count == 0)
             {
                 insertReturn = true;
                 break;
             }
             PStm lastStm = (PStm)block.GetStatements()[block.GetStatements().Count - 1];
             if (lastStm is AVoidReturnStm)
                 break;
             if (lastStm is ABlockStm)
             {
                 block = (AABlock)((ABlockStm)block.GetStatements()[block.GetStatements().Count - 1]).GetBlock();
                 continue;
             }
             insertReturn = true;
             break;
         }
         if (insertReturn)
         {
             block.GetStatements().Add(new AVoidReturnStm(new TReturn("return", block.GetToken().Line, block.GetToken().Pos)));
         }
     }
     //Check if delegate is valid
     if (node.GetDelegate() != null)
     {
         if (node.GetBlock() != null)
             errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText195")));
         if (node.GetInline() != null)
             errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText196")));
         if (node.GetTrigger() != null)
             errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText197")));
         if (node.GetStatic() != null)
             errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText198")));
         if (node.GetNative() != null)
             errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText199")));
     }
     //If it's protected, it must be in a struct
     if (!Util.HasAncestor<AStructDecl>(node))
     {
         if (node.GetVisibilityModifier() is AProtectedVisibilityModifier)
             errors.Add(new ErrorCollection.Error(node.GetName(),
                                                  LocRM.GetString("ErrorText200")));
     }
     base.OutAMethodDecl(node);
 }
        /*public override void InAMethodDecl(AMethodDecl node)
        {
            AABlock block = (AABlock) node.GetBlock();
            if (block != null)
            {
                if (!data.Locals.ContainsKey(block))
                    data.Locals.Add(block, new List<AALocalDecl>());
                foreach (AALocalDecl formal in node.GetFormals())
                {
                    data.Locals[block].Add(formal);
                }
            }
        }

        public override void InAConstructorDecl(AConstructorDecl node)
        {
            AABlock block = (AABlock)node.GetBlock();
            if (block != null)
            {
                if (!data.Locals.ContainsKey(block))
                    data.Locals.Add(block, new List<AALocalDecl>());
                foreach (AALocalDecl formal in node.GetFormals())
                {
                    data.Locals[block].Add(formal);
                }
            }
        }*/
        public override void OutAMethodDecl(AMethodDecl node)
        {
            AStructDecl parentStruct = Util.GetAncestor<AStructDecl>(node);
            AEnrichmentDecl parentEnrichment = Util.GetAncestor<AEnrichmentDecl>(node);
            if (parentStruct != null)
            {
                //Struct method
                data.StructMethods[parentStruct].Add(node);
            }
            else if (parentEnrichment == null)
            {//Global method
                //Dont care about abstract methods - will add them later
                if (node.GetBlock() != null || node.GetNative() != null)
                {
                    data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(currentSourceFile, node));
                    data.UserMethods.Add(node);
                }
                else if (node.GetDelegate() != null)
                    data.Delegates.Add(new SharedData.DeclItem<AMethodDecl>(currentSourceFile, node));
                else
                {
                    node.Parent().RemoveChild(node);
                    return;
                }
            }
            base.OutAMethodDecl(node);
        }
 public override void CaseAMethodDecl(AMethodDecl node)
 {
     Write("\n");
     if (node.GetStatic() != null) Write("static ");
     if (node.GetNative() != null) Write("native ");
     node.GetReturnType().Apply(this);
     Write(" " + node.GetName().Text + "(");
     bool first = true;
     foreach (AALocalDecl formal in node.GetFormals())
     {
         if (!first) Write(", ");
         formal.Apply(this);
         first = false;
     }
     if (node.GetBlock() != null)
     {
         Write(")\n");
         node.GetBlock().Apply(this);
     }
     else
         Write(");\n\n");
 }