예제 #1
0
 public static AbstractNode MakeStructDeclaration(AbstractNode mods, AbstractNode id, AbstractNode body)
 {
     return(new StructDeclaration(mods, id, body));
 }
예제 #2
0
 public void VisitNode(AbstractNode node)
 {
 }
예제 #3
0
 public virtual AbstractNode orphan()
 {
     mysib    = parent = null;
     firstSib = this;
     return(this);
 }
예제 #4
0
 public ClassBody(AbstractNode classbdy)
 {
     adoptChildren(classbdy);
 }
예제 #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}");
                }
            }
        }
예제 #6
0
 public ReturnStatement(AbstractNode retrn)
 {
     adoptChildren(retrn);
 }
예제 #7
0
 public LocalItems(AbstractNode localItems)
 {
     adoptChildren(localItems);
 }
예제 #8
0
 public MethodCall(AbstractNode name)
 {
     adoptChildren(name);
 }
예제 #9
0
 public MethodCall(AbstractNode name, AbstractNode paramList)
 {
     adoptChildren(name);
     adoptChildren(paramList);
 }
예제 #10
0
 public MethodSignature(AbstractNode name)
 {
     adoptChildren(name);
 }
예제 #11
0
 public MethodSignature(AbstractNode name, AbstractNode paramList)
 {
     adoptChildren(name);
     adoptChildren(paramList);
 }
예제 #12
0
 public ParameterList(AbstractNode parameter) : base()
 {
     adoptChildren(parameter);
 }
예제 #13
0
 public Parameter(AbstractNode typeSpec, AbstractNode declName) : base()
 {
     adoptChildren(typeSpec);
     adoptChildren(declName);
 }
예제 #14
0
 public MethodBody(AbstractNode abstractNode)
 {
     adoptChildren(abstractNode);
 }
예제 #15
0
 public SelectionStatement(AbstractNode expr, AbstractNode stmt)
 {
     adoptChildren(expr);
     adoptChildren(stmt);
 }
예제 #16
0
 public CompilationUnit(AbstractNode classDecl)
 {
     adoptChildren(classDecl);
 }
예제 #17
0
 public IterationStatement(AbstractNode whileExpr, AbstractNode stmt)
 {
     adoptChildren(whileExpr);
     adoptChildren(stmt);
 }
예제 #18
0
 public Expression(AbstractNode expr, ExprKind kind)
 {
     adoptChildren(expr);
     exprKind = kind;
 }
예제 #19
0
 public LocalVariableNames(AbstractNode localVarName)
 {
     adoptChildren(localVarName);
 }
예제 #20
0
 public Expression(AbstractNode lhs, ExprKind kind, AbstractNode rhs)
 {
     adoptChildren(lhs);
     adoptChildren(rhs);
     exprKind = kind;
 }
예제 #21
0
 public ClassDeclaration(AbstractNode modifiers, AbstractNode identifier, AbstractNode classbody)
 {
     adoptChildren(modifiers);
     adoptChildren(identifier);
     adoptChildren(classbody);
 }
예제 #22
0
 public Block(AbstractNode blkCode)
 {
     adoptChildren(blkCode);
 }
예제 #23
0
 public ScanObj(int t, AbstractNode val, LexLocation loc)
 {
     this.token = t; this.yylval = val; this.yylloc = loc;
 }
예제 #24
0
 public StructDeclaration(AbstractNode modifier, AbstractNode identifier, AbstractNode structBody)
 {
     adoptChildren(modifier);
     adoptChildren(identifier);
     adoptChildren(structBody);
 }
예제 #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);
                    }
                }
            }
        }
예제 #26
0
 public LocalVariableDeclaration(AbstractNode typeSpecifier, AbstractNode localVariableName)
 {
     adoptChildren(typeSpecifier);
     adoptChildren(localVariableName);
 }
예제 #27
0
 public void VisitNode(AbstractNode node)
 {
     Console.Write("<" + node.ClassName() + ">");
 }
예제 #28
0
 public ArgumentList(AbstractNode expr)
 {
     adoptChildren(expr);
 }
예제 #29
0
 public virtual AbstractNode abandonChildren()
 {
     child = null;
     return(this);
 }
예제 #30
0
 public static AbstractNode MakeClassDeclaration(AbstractNode mods, AbstractNode id, AbstractNode body)
 {
     return(new ClassDeclaration(mods, id, body));
 }