Ignore preprocessor commands while scanning for globals.

The pragma warnings were duplicated, one during globals scan, another during actual parsing. This should fix it.

This is somewhat potentially dangerous, as some directives (pragmas, notably) could in future affect the global scan phase by changing the language.
This commit is contained in:
Sei Lisa 2016-06-27 18:50:31 +02:00
parent 633c31df6c
commit 8fc4240142

View file

@ -318,6 +318,10 @@ class parser(object):
def ProcessDirective(self, directive): def ProcessDirective(self, directive):
"""Process a given preprocessor directive during parsing.""" """Process a given preprocessor directive during parsing."""
# Ignore directives on the first pass
if self.scanglobals:
return
if directive[len(directive)-1:] == '\\': if directive[len(directive)-1:] == '\\':
raise EParseInvalidBackslash(self) raise EParseInvalidBackslash(self)
@ -2490,6 +2494,7 @@ list lazy_list_set(list L, integer i, list v)
# incomplete parsing pass, gathering globals with their types and # incomplete parsing pass, gathering globals with their types and
# function arguments. And that's what we do. # function arguments. And that's what we do.
self.scanglobals = True # Tell the lexer not to process directives
self.pos = self.errorpos = 0 self.pos = self.errorpos = 0
self.linestart = True self.linestart = True
self.tok = self.GetToken() self.tok = self.GetToken()
@ -2498,6 +2503,7 @@ list lazy_list_set(list L, integer i, list v)
# Restart # Restart
self.scanglobals = False
self.pos = self.errorpos = 0 self.pos = self.errorpos = 0
self.linestart = True self.linestart = True
self.tok = self.GetToken() self.tok = self.GetToken()