Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.on_potential_include_guard(args[n].value)
include_guard = (args[n].value, 0)
at_front_of_file = False
ifstack.append(ifstackentry(enable,iftrigger,ifpassthru,x))
if enable:
iftrigger = False
ifpassthru = False
result, rewritten = self.evalexpr(args)
if rewritten is not None:
x = x[:i+2] + rewritten + [x[-1]]
x[i+1] = copy.copy(x[i+1])
x[i+1].type = self.t_SPACE
x[i+1].value = ' '
ifpassthru = True
ifstack[-1].rewritten = True
raise OutputDirective(Action.IgnoreAndPassThrough)
if not result:
enable = False
else:
iftrigger = True
elif name == 'elif':
at_front_of_file = False
if ifstack:
if ifstack[-1].enable: # We only pay attention if outer "if" allows this
if enable and not ifpassthru: # If already true, we flip enable False
enable = False
elif not iftrigger: # If False, but not triggered yet, we'll check expression
result, rewritten = self.evalexpr(args)
if rewritten is not None:
enable = True
if not ifpassthru:
# This is a passthru #elif after a False #if, so convert to an #if
else:
self.on_error(dirtokens[0].source,dirtokens[0].lineno,"Misplaced #else")
elif name == 'endif':
at_front_of_file = False
if ifstack:
oldifstackentry = ifstack.pop()
enable = oldifstackentry.enable
iftrigger = oldifstackentry.iftrigger
ifpassthru = oldifstackentry.ifpassthru
if self.debugout is not None:
print("%d:%d:%d %s:%d (%s:%d %s)" % (enable, iftrigger, ifpassthru, dirtokens[0].source, dirtokens[0].lineno,
oldifstackentry.startlinetoks[0].source, oldifstackentry.startlinetoks[0].lineno, "".join([n.value for n in oldifstackentry.startlinetoks])), file = self.debugout)
skip_auto_pragma_once_possible_check = True
if oldifstackentry.rewritten:
raise OutputDirective(Action.IgnoreAndPassThrough)
else:
self.on_error(dirtokens[0].source,dirtokens[0].lineno,"Misplaced #endif")
elif name == 'pragma' and args[0].value == 'once':
if enable:
self.include_once[self.source] = None
elif enable:
# Unknown preprocessor directive
output_unexpanded_line = (self.on_directive_unknown(dirtokens[0], args, ifpassthru, precedingtoks) is None)
except OutputDirective as e:
if e.action == Action.IgnoreAndPassThrough:
output_unexpanded_line = True
elif e.action == Action.IgnoreAndRemove:
pass
else:
assert False
def on_include_not_found(self,is_system_include,curdir,includepath):
"""Called when a #include wasn't found.
Raise OutputDirective to pass through or remove, else return
a suitable path. Remember that Preprocessor.add_path() lets you add search paths.
The default calls self.on_error() with a suitable error message about the
include file not found and raises OutputDirective (pass through).
"""
self.on_error(self.lastdirective.source,self.lastdirective.lineno, "Include file '%s' not found" % includepath)
raise OutputDirective(Action.IgnoreAndPassThrough)
if self.debugout is not None:
print("%d:%d:%d %s:%d (%s:%d %s)" % (enable, iftrigger, ifpassthru, dirtokens[0].source, dirtokens[0].lineno,
oldifstackentry.startlinetoks[0].source, oldifstackentry.startlinetoks[0].lineno, "".join([n.value for n in oldifstackentry.startlinetoks])), file = self.debugout)
skip_auto_pragma_once_possible_check = True
if oldifstackentry.rewritten:
raise OutputDirective(Action.IgnoreAndPassThrough)
else:
self.on_error(dirtokens[0].source,dirtokens[0].lineno,"Misplaced #endif")
elif name == 'pragma' and args[0].value == 'once':
if enable:
self.include_once[self.source] = None
elif enable:
# Unknown preprocessor directive
output_unexpanded_line = (self.on_directive_unknown(dirtokens[0], args, ifpassthru, precedingtoks) is None)
except OutputDirective as e:
if e.action == Action.IgnoreAndPassThrough:
output_unexpanded_line = True
elif e.action == Action.IgnoreAndRemove:
pass
else:
assert False
# If there is ever any non-whitespace output outside an include guard, auto pragma once is not possible
if not skip_auto_pragma_once_possible_check and auto_pragma_once_possible and not ifstack and not all_whitespace:
auto_pragma_once_possible = False
if self.debugout is not None:
print("%d:%d:%d %s:%d Determined that #include \"%s\" is not entirely wrapped in an include guard macro, disabling auto-applying #pragma once" % (enable, iftrigger, ifpassthru, x[0].source, x[0].lineno, self.source), file = self.debugout)
if output_and_expand_line or output_unexpanded_line:
if not all_whitespace:
at_front_of_file = False