Detect conditionals which never terminate.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 06 Feb 2009 15:34:09 -0500
changeset 57 59302968cf3b9998c95a210c08cf466aac216521
parent 56 3ce56bc0b679ec3853ff501857a989290c72ae4e
child 58 33ec07baae053afcd497466cf9839040edd545f6
push id32
push userbsmedberg@mozilla.com
push dateFri, 06 Feb 2009 20:34:17 +0000
Detect conditionals which never terminate.
pymake/parser.py
--- a/pymake/parser.py
+++ b/pymake/parser.py
@@ -272,17 +272,17 @@ conditionkeywords = {
     }
 
 class Condition(object):
     """
     Represent aa makefile conditional.
     1) is the condition active right now?
     2) was the condition ever met?
     """
-    def __init__(self, active):
+    def __init__(self, active, loc):
         self.active = active
         self.everactive = active
 
     def makeactive(self, active):
         if self.everactive:
             self.active = False
             return
 
@@ -368,17 +368,17 @@ def parsestream(fd, filename, makefile):
                 vname = e.resolve(makefile.variables, None)
                 makefile.variables.set(vname, data.Variables.FLAVOR_RECURSIVE,
                                        data.Variables.SOURCE_MAKEFILE, val)
                 continue
             elif kword == 'include':
                 raise NotImplementedError('no includes yet')
             elif kword in conditionkeywords:
                 m = conditionkeywords[kword](d, kwoffset, makefile)
-                condstack.append(Condition(m))
+                condstack.append(Condition(m, d.getloc(offset)))
                 continue
 
             if any((not c.active for c in condstack)):
                 log.info('skipping line %i, ifdefed away' % lineno)
                 continue
 
             e, stoppedat = parsemakesyntax(d, 0, ':=', PARSESTYLE_MAKEFILE)
             if stoppedat == -1:
@@ -484,16 +484,19 @@ def parsestream(fd, filename, makefile):
                     makefile.foundtarget(targets[0].gettarget())
 
                     if stoppedat != -1:
                         e, stoppedat = parsemakesyntax(d, stoppedat + 1, '', PARSESTYLE_COMMAND)
                         assert stoppedat == -1
                         e.lstrip()
                         currule.addcommand(e)
 
+    if len(condstack):
+        raise SyntaxError("Condition never terminated with endif", condstack[-1].loc)
+
 PARSESTATE_TOPLEVEL = 0    # at the top level
 PARSESTATE_FUNCTION = 1    # expanding a function call. data is function
 
 # For the following three, data is a tuple of Expansions: (varname, substfrom, substto)
 PARSESTATE_VARNAME = 2     # expanding a variable expansion.
 PARSESTATE_SUBSTFROM = 3   # expanding a variable expansion substitution "from" value
 PARSESTATE_SUBSTTO = 4     # expanding a variable expansion substitution "to" value