extract-ofp-errors: Check that error codes are in the expected ranges.
[openvswitch] / build-aux / check-structs
index 0849fcf14208174f9d1f4bba09c0e9db9b68b901..e50e3101164d872a993774ac49f82f9559aad514 100755 (executable)
@@ -11,9 +11,6 @@ anyWarnings = False
 types = {}
 types['char'] = {"size": 1, "alignment": 1}
 types['uint8_t'] = {"size": 1, "alignment": 1}
 types = {}
 types['char'] = {"size": 1, "alignment": 1}
 types['uint8_t'] = {"size": 1, "alignment": 1}
-types['uint16_t'] = {"size": 2, "alignment": 2}
-types['uint32_t'] = {"size": 4, "alignment": 4}
-types['uint64_t'] = {"size": 8, "alignment": 8}
 types['ovs_be16'] = {"size": 2, "alignment": 2}
 types['ovs_be32'] = {"size": 4, "alignment": 4}
 types['ovs_be64'] = {"size": 8, "alignment": 8}
 types['ovs_be16'] = {"size": 2, "alignment": 2}
 types['ovs_be32'] = {"size": 4, "alignment": 4}
 types['ovs_be64'] = {"size": 8, "alignment": 8}
@@ -23,13 +20,18 @@ token = None
 line = ""
 idRe = "[a-zA-Z_][a-zA-Z_0-9]*"
 tokenRe = "#?" + idRe + "|[0-9]+|."
 line = ""
 idRe = "[a-zA-Z_][a-zA-Z_0-9]*"
 tokenRe = "#?" + idRe + "|[0-9]+|."
+includeRe = re.compile(r'\s*#include\s+"(openflow/[^#]+)"')
+includePath = ''
 inComment = False
 inDirective = False
 inComment = False
 inDirective = False
+inputStack = []
 def getToken():
     global token
     global line
     global inComment
     global inDirective
 def getToken():
     global token
     global line
     global inComment
     global inDirective
+    global inputFile
+    global fileName
     while True:
         line = line.lstrip()
         if line != "":
     while True:
         line = line.lstrip()
         if line != "":
@@ -59,16 +61,27 @@ def getToken():
             return True
         else:
             global lineNumber
             return True
         else:
             global lineNumber
-            line = inputFile.readline()
-            lineNumber += 1
-            while line.endswith("\\\n"):
-                line = line[:-2] + inputFile.readline()
+            while True:
+                line = inputFile.readline()
                 lineNumber += 1
                 lineNumber += 1
-            if line == "":
-                if token == None:
-                    fatal("unexpected end of input")
-                token = None
-                return False
+                while line.endswith("\\\n"):
+                    line = line[:-2] + inputFile.readline()
+                    lineNumber += 1
+                match = includeRe.match(line)
+                if match:
+                    inputStack.append((fileName, inputFile, lineNumber))
+                    inputFile = open(includePath + match.group(1))
+                    lineNumber = 0
+                    continue
+                if line == "":
+                    if inputStack:
+                        fileName, inputFile, lineNumber = inputStack.pop()
+                        continue
+                    if token == None:
+                        fatal("unexpected end of input")
+                    token = None
+                    return False
+                break
     
 def fatal(msg):
     sys.stderr.write("%s:%d: error at \"%s\": %s\n" % (fileName, lineNumber, token, msg))
     
 def fatal(msg):
     sys.stderr.write("%s:%d: error at \"%s\": %s\n" % (fileName, lineNumber, token, msg))
@@ -199,7 +212,7 @@ def checkStructs():
         argv0 = os.path.basename(sys.argv[0])
         print '''\
 %(argv0)s, for checking struct and struct member alignment
         argv0 = os.path.basename(sys.argv[0])
         print '''\
 %(argv0)s, for checking struct and struct member alignment
-usage: %(argv0)s HEADER [HEADER]...
+usage: %(argv0)s -Ipath HEADER [HEADER]...
 
 This program reads the header files specified on the command line and
 verifies that all struct members are aligned on natural boundaries
 
 This program reads the header files specified on the command line and
 verifies that all struct members are aligned on natural boundaries
@@ -210,16 +223,19 @@ some ABIs for ARM require all structs to be a multiple of 32 bits), or
 compiler adding additional padding.  Finally, it checks struct size
 assertions using OFP_ASSERT.
 
 compiler adding additional padding.  Finally, it checks struct size
 assertions using OFP_ASSERT.
 
-Header files are read in the order specified.  #include directives are
-not processed, so specify them in dependency order.
-
-This program is specialized for reading include/openflow/openflow.h
-and include/openflow/nicira-ext.h.  It will not work on arbitrary
-header files without extensions.''' % {"argv0": argv0}
+This program is specialized for reading Open vSwitch's OpenFlow header
+files.  It will not work on arbitrary header files without extensions.\
+''' % {"argv0": argv0}
         sys.exit(0)
 
     global fileName
     for fileName in sys.argv[1:]:
         sys.exit(0)
 
     global fileName
     for fileName in sys.argv[1:]:
+        if fileName.startswith('-I'):
+            global includePath
+            includePath = fileName[2:]
+            if not includePath.endswith('/'):
+                includePath += '/'
+            continue
         global inputFile
         global lineNumber
         inputFile = open(fileName)
         global inputFile
         global lineNumber
         inputFile = open(fileName)