senex avatar senex committed 5387601

Fixed bug 3567854: Not creating instances of anonymous unions

Now anonymous unions will act like anonymous structs, the variable name will be "" (empyt string)

Comments (0)

Files changed (3)

CppHeaderParser/CppHeaderParser.py

         debug_print("curAccessSpecifier changed/defaulted to %s"%self.curAccessSpecifier)
         if self.nameStack[0] == "union":
             newClass = CppUnion(self.nameStack)
+            self.anon_union_counter = [self.braceDepth, 2]
             trace_print( 'NEW UNION', newClass['name'] )
         else:
             newClass = CppClass(self.nameStack)
         debug_print("curAccessSpecifier changed/defaulted to %s"%self.curAccessSpecifier)
         self.initextra()
     
+        self.anon_union_counter = [-1, 0]
+    
         if (len(self.headerFileName)):
             fd = open(self.headerFileName)
             headerFileStr = "".join(fd.readlines())
             while True:
                 tok = lex.token()
                 if not tok: break
+                if self.anon_union_counter[0] == self.braceDepth and self.anon_union_counter[1]:
+                    self.anon_union_counter[1] -= 1
                 tok.value = TagStr(tok.value, lineno=tok.lineno)
                 if tok.type == 'NAME' and tok.value in self.IGNORE_NAMES: continue
                 self.stack.append( tok.value )
                         self.stack = []
                     else:
                         self.nameStack.append(tok.value)
+                        if self.anon_union_counter[0] == self.braceDepth:
+                            self.anon_union_counter = [-1, 0]
                 elif (tok.type == 'COLON'):
                     #Dont want colon to be first in stack
                     if len(self.nameStack) == 0:
                     self.accessSpecifierScratch = []
 
                 elif (tok.type == 'SEMI_COLON'):
+                    if self.anon_union_counter[0] == self.braceDepth and self.anon_union_counter[1]:
+                        debug_print("Creating anonymous union")
+                        #Force the processing of an anonymous union
+                        saved_namestack = self.nameStack[:] 
+                        saved_stack = self.stack[:]
+                        self.nameStack = [""]
+                        self.stack = self.nameStack + [";"]
+                        self.nameStack = self.nameStack[0:1]
+                        debug_print("pre eval anon stack")
+                        self.evaluate_stack( tok.type )
+                        debug_print("post eval anon stack")
+                        self.nameStack = saved_namestack
+                        self.stack = saved_stack
+                        self.anon_union_counter = [-1, 0];
+                    
+                    
                     if (self.braceDepth < 10): self.evaluate_stack( tok.type )
                     if not self.stack: continue
                     if self.stack[0]=='typedef' and ( '{' not in self.stack or '}' in self.stack ): self.stack = []; trace_print( "REAL CLEAR")

CppHeaderParser/test/TestSampleClass.h

 {
 	enum Stem stem_property;
 }
+
+// Bug 3567854
+struct Beans
+{
+    UINT16 hdr;
+    union
+    {
+        UINT16 typeA;
+        UINT16 typeB;
+        UINT16 raw[3];
+    };
+    UINT32 data[204];
 };

CppHeaderParser/test/test_CppHeaderParser.py

     def test_pragmas2(self):
         self.assertEqual(self.cppHeader.defines[2], 'DEBUG_PRINT(x)           \\\n    printf("---------------\\n"); \\\n    printf("DEBUG: %d\\n", x);    \\\n    printf("---------------\\n");')
 
+
+
+# Bug: 3567854
+class Beans_TestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.cppHeader = CppHeaderParser.CppHeader("TestSampleClass.h")
+    
+    def test_anonymous_union_name(self):
+        return self.assertEqual(self.cppHeader.classes["Beans"]["properties"]["public"][1]["name"], "")
+
 if __name__ == '__main__':
     unittest.main()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.