ruby: slicc: derive DataMember class from Var instead of PairContainer
authorNilay Vaish <nilay@cs.wisc.edu>
Fri, 18 Sep 2015 18:27:47 +0000 (13:27 -0500)
committerNilay Vaish <nilay@cs.wisc.edu>
Fri, 18 Sep 2015 18:27:47 +0000 (13:27 -0500)
The DataMember class in Type.py was being derived from PairContainer.  A
separate Var object was also created for the DataMember.  This meant some
duplication of across the members of these two classes (Var and DataMember).
This patch changes DataMember from Var instead.  There is no obvious reason to
derive from PairContainer which can only hold pairs, something that Var class
already supports.  The only thing that DataMember has over Var is init_code,
which is being retained.  This change would later on help in having pointers
in DataMembers.

src/mem/slicc/symbols/Type.py

index 2dc35784a50bbbe36fbd6d38e8ffacc682518cbd..6234f4f7f08d5455352b6c45cb361f5e961d007d 100644 (file)
@@ -31,11 +31,11 @@ from slicc.util import PairContainer
 from slicc.symbols.Symbol import Symbol
 from slicc.symbols.Var import Var
 
-class DataMember(PairContainer):
-    def __init__(self, ident, type, pairs, init_code):
-        super(DataMember, self).__init__(pairs)
-        self.ident = ident
-        self.type = type
+class DataMember(Var):
+    def __init__(self, symtab, ident, location, type, code, pairs,
+                 machine, init_code):
+        super(DataMember, self).__init__(symtab, ident, location, type,
+                                         code, pairs, machine)
         self.init_code = init_code
 
 class Enumeration(PairContainer):
@@ -126,12 +126,11 @@ class Type(Symbol):
         if ident in self.data_members:
             return False
 
-        member = DataMember(ident, type, pairs, init_code)
-        self.data_members[ident] = member
+        member = DataMember(self.symtab, ident, self.location, type,
+                            "m_%s" % ident, pairs, None, init_code)
 
-        var = Var(self.symtab, ident, self.location, type,
-                "m_%s" % ident, {}, None)
-        self.symtab.registerSym(ident, var)
+        self.data_members[ident] = member
+        self.symtab.registerSym(ident, member)
         return True
 
     def dataMemberType(self, ident):