Example #1
0
 public static AbstractNode MakeStructDeclaration(AbstractNode mods, AbstractNode id, AbstractNode body)
 {
     return(new StructDeclaration(mods, id, body));
 }
Example #2
0
 public void VisitNode(AbstractNode node)
 {
 }
Example #3
0
 public virtual AbstractNode orphan()
 {
     mysib    = parent = null;
     firstSib = this;
     return(this);
 }
Example #4
0
 public ClassBody(AbstractNode classbdy)
 {
     adoptChildren(classbdy);
 }
Example #5
0
        public void VisitNode(MethodDeclaration node)
        {
            stlocCount = 0;
            Identifier       name  = (Identifier)node.Child.Sib.Sib.Child;
            AbstractNode     body  = node.Child.Sib.Sib.Sib;
            MethodAttributes attr  = (MethodAttributes)node.AttributesRef;
            List <string>    mods  = attr.Mods;
            AbstractNode     param = null;

            if (((SignatureTypeDescriptor)attr.Signature).Parameters != null)
            {
                param = ((SignatureTypeDescriptor)attr.Signature).Parameters.Child;
            }
            using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    string s = ".method ";
                    if (mods.Contains("PUBLIC"))
                    {
                        s += "public ";
                    }
                    if (mods.Contains("PRIVATE"))
                    {
                        s += "private ";
                    }
                    if (mods.Contains("STATIC"))
                    {
                        s += "static ";
                    }
                    s += attr.ReturnType.type + " ";
                    s += name.Name;
                    s += " (";
                    if (param != null)
                    {
                        while (param != null)
                        {
                            AbstractNode type      = param.Child;
                            Identifier   paramName = (Identifier)type.Sib;
                            s    += type.TypeRef.type;
                            param = param.Sib;
                            if (param != null)
                            {
                                s += ", ";
                            }
                        }
                    }
                    s += ")";
                    sw.WriteLine(s + "\n{");
                    if (name.Name == "main")
                    {
                        sw.WriteLine(".entrypoint");
                    }
                    sw.WriteLine(".maxstack 100");
                    if (((SignatureTypeDescriptor)attr.Signature).Parameters != null)
                    {
                        param = ((SignatureTypeDescriptor)attr.Signature).Parameters.Child;
                        while (param != null)
                        {
                            param.Accept(this);
                            param = param.Sib;
                        }
                    }
                }
            }
            MethodBodyVisitor visitor = new MethodBodyVisitor();

            body.Accept(visitor);
            using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine("\nret\n}");
                }
            }
        }
Example #6
0
 public ReturnStatement(AbstractNode retrn)
 {
     adoptChildren(retrn);
 }
Example #7
0
 public LocalItems(AbstractNode localItems)
 {
     adoptChildren(localItems);
 }
Example #8
0
 public MethodCall(AbstractNode name)
 {
     adoptChildren(name);
 }
Example #9
0
 public MethodCall(AbstractNode name, AbstractNode paramList)
 {
     adoptChildren(name);
     adoptChildren(paramList);
 }
Example #10
0
 public MethodSignature(AbstractNode name)
 {
     adoptChildren(name);
 }
Example #11
0
 public MethodSignature(AbstractNode name, AbstractNode paramList)
 {
     adoptChildren(name);
     adoptChildren(paramList);
 }
Example #12
0
 public ParameterList(AbstractNode parameter) : base()
 {
     adoptChildren(parameter);
 }
Example #13
0
 public Parameter(AbstractNode typeSpec, AbstractNode declName) : base()
 {
     adoptChildren(typeSpec);
     adoptChildren(declName);
 }
Example #14
0
 public MethodBody(AbstractNode abstractNode)
 {
     adoptChildren(abstractNode);
 }
Example #15
0
 public SelectionStatement(AbstractNode expr, AbstractNode stmt)
 {
     adoptChildren(expr);
     adoptChildren(stmt);
 }
Example #16
0
 public CompilationUnit(AbstractNode classDecl)
 {
     adoptChildren(classDecl);
 }
Example #17
0
 public IterationStatement(AbstractNode whileExpr, AbstractNode stmt)
 {
     adoptChildren(whileExpr);
     adoptChildren(stmt);
 }
Example #18
0
 public Expression(AbstractNode expr, ExprKind kind)
 {
     adoptChildren(expr);
     exprKind = kind;
 }
Example #19
0
 public LocalVariableNames(AbstractNode localVarName)
 {
     adoptChildren(localVarName);
 }
Example #20
0
 public Expression(AbstractNode lhs, ExprKind kind, AbstractNode rhs)
 {
     adoptChildren(lhs);
     adoptChildren(rhs);
     exprKind = kind;
 }
Example #21
0
 public ClassDeclaration(AbstractNode modifiers, AbstractNode identifier, AbstractNode classbody)
 {
     adoptChildren(modifiers);
     adoptChildren(identifier);
     adoptChildren(classbody);
 }
Example #22
0
 public Block(AbstractNode blkCode)
 {
     adoptChildren(blkCode);
 }
 public ScanObj(int t, AbstractNode val, LexLocation loc)
 {
     this.token = t; this.yylval = val; this.yylloc = loc;
 }
Example #24
0
 public StructDeclaration(AbstractNode modifier, AbstractNode identifier, AbstractNode structBody)
 {
     adoptChildren(modifier);
     adoptChildren(identifier);
     adoptChildren(structBody);
 }
Example #25
0
        public void VisitNode(MethodCall node)
        {
            Identifier   functionCall = (Identifier)node.Child.Child;
            AbstractNode list         = node.Child.Sib;
            string       s            = "";

            if (functionCall.TypeRef.GetType() == typeof(ASTBuilder.MSCorLibTypeDescriptor) &&
                node.TypeRef.GetType() == typeof(ASTBuilder.StringTypeDescriptor))
            {
                list.Accept(this);
                using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("call " + functionCall.TypeRef.type + functionCall.Name + "(string)");
                    }
                }
            }
            else if (functionCall.TypeRef.GetType() == typeof(ASTBuilder.MSCorLibTypeDescriptor) &&
                     node.TypeRef.GetType() == typeof(ASTBuilder.IntegerTypeDescriptor))
            {
                using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("ldstr \"{0}\"");
                    }
                }
                list.Accept(this);
                using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("box int32");
                        sw.WriteLine("call void [mscorlib]System.Console::WriteLine(string, object) ");
                    }
                }
            }
            else
            {
                while (list != null)
                {
                    list.Accept(this);
                    list = list.Sib;
                }
                s   += "call " + functionCall.TypeRef.type + " " + functionCall.Name + "(";
                list = node.Child.Sib;
                while (list != null)
                {
                    s   += list.TypeRef.type;
                    list = list.Sib;
                    if (list != null)
                    {
                        s += ", ";
                    }
                }
                s += ")";
                using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine(s);
                    }
                }
            }
        }
Example #26
0
 public LocalVariableDeclaration(AbstractNode typeSpecifier, AbstractNode localVariableName)
 {
     adoptChildren(typeSpecifier);
     adoptChildren(localVariableName);
 }
Example #27
0
 public void VisitNode(AbstractNode node)
 {
     Console.Write("<" + node.ClassName() + ">");
 }
Example #28
0
 public ArgumentList(AbstractNode expr)
 {
     adoptChildren(expr);
 }
Example #29
0
 public virtual AbstractNode abandonChildren()
 {
     child = null;
     return(this);
 }
Example #30
0
 public static AbstractNode MakeClassDeclaration(AbstractNode mods, AbstractNode id, AbstractNode body)
 {
     return(new ClassDeclaration(mods, id, body));
 }