Esempio n. 1
0
 private DeclNode resovleType(List <FlowGraphNode> Scope, string name)
 {
     foreach (FlowGraphNode g in Scope)
     {
         if (g.getNodeType() == NodeType.E_DECL)
         {
             DeclNode tmp = (DeclNode)g;
             if (tmp.DeclName == name)
             {
                 return(tmp);
             }
         }
         if (g.getNodeType() == NodeType.E_STRUCT)
         {
             StructNode tmp = (StructNode)g;
             foreach (FlowGraphNode node in tmp.Decl)
             {
                 if (null != resovleType(new List <FlowGraphNode>()
                 {
                     node
                 }, name))
                 {
                     return(resovleType(new List <FlowGraphNode>()
                     {
                         node
                     }, name));
                 }
             }
         }
         if (g.getNodeType() == NodeType.E_UNION)
         {
             UnionNode tmp = (UnionNode)g;
             foreach (FlowGraphNode node in tmp.Decl)
             {
                 if (null != resovleType(new List <FlowGraphNode>()
                 {
                     node
                 }, name))
                 {
                     return(resovleType(new List <FlowGraphNode>()
                     {
                         node
                     }, name));
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
 private FlowGraphNode getStructByType(List <FlowGraphNode> Scope, string typename)
 {
     foreach (FlowGraphNode node in Scope)
     {
         if (node.getNodeType() == NodeType.E_STRUCT)
         {
             StructNode tmp = (StructNode)node;
             //if (tmp. == typename)
             // {
             //   return tmp.TypeDecl;
             //}
         }
     }
     return(null);
 }
Esempio n. 3
0
        FlowGraphNode ParseStruct(Dictionary <string, object> item)
        {
            StructNode node = new StructNode(Id++);

            node.Decl = new List <FlowGraphNode>();
            ArrayList decls = (ArrayList)item["decls"];

            if (decls != null)
            {
                foreach (Dictionary <string, object> decl in decls)
                {
                    node.Decl.Add(ParseNode(decl));
                }
            }
            if (item.ContainsKey("name"))
            {
                if (item["name"] != null)
                {
                    node.name = item["name"].ToString();
                }
            }
            return(node);
        }
Esempio n. 4
0
        FlowGraphNode ParseDeclaration(Dictionary <string, object> item)
        {
            DeclNode node = new DeclNode(Id++);
            Dictionary <string, object> type = null;

            if (item.ContainsKey("name"))
            {
                if (item["name"] != null)
                {
                    node.DeclName = item["name"].ToString();
                }
            }
            if (item.ContainsKey("init"))
            {
                if (null == item["init"])
                {
                    node.isInited = false;
                }
                else
                {
                    node.isInited = true;
                }
            }
            do
            {
                string var;
                if (item.ContainsKey("type"))
                {
                    if (null == type)
                    {
                        type = (Dictionary <string, object>)item["type"];
                    }
                    else
                    {
                        type = (Dictionary <string, object>)type["type"];
                    }
                    var = type["_nodetype"].ToString();
                }
                else
                {
                    type = item;
                    var  = item["_nodetype"].ToString();
                }
                if ("Union" == var)
                {
                    if (node.isArray || node.isPointer)
                    {
                        UnionNode r = (UnionNode)ParseNode(type);
                        node.DeclType = r.name;
                    }
                    else
                    {
                        return(ParseNode(type));
                    }
                }
                if ("Struct" == var)
                {
                    if (node.isArray || node.isPointer)
                    {
                        StructNode r = (StructNode)ParseNode(type);
                        node.DeclType = r.name;
                    }
                    else
                    {
                        return(ParseNode(type));
                    }
                }
                if ("ArrayDecl" == var)
                {
                    node.ArrayLevel++;
                    node.isArray = true;
                }
                if ("PtrDecl" == var)
                {
                    node.PointerLevel++;
                    node.isPointer = true;
                }
                if ("TypeDecl" == var)
                {
                }
                if ("IdentifierType" == var)
                {
                    StringBuilder str = new StringBuilder();

                    ArrayList type1 = ((ArrayList)(type["names"]));
                    for (int i = 0; i < type1.Count; i++)
                    {
                        if (i == type1.Count - 1)
                        {
                            str.Append(type1[i].ToString());
                        }
                        else
                        {
                            str.Append(type1[i].ToString() + " ");
                        }
                    }
                    node.DeclType = str.ToString();
                }
            } while (type.ContainsKey("type"));

            return(node);
        }