Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_directive_handle(self,directive,toks,ifpassthru,precedingtoks):
if ifpassthru:
if directive.value == 'if' or directive.value == 'elif' or directive == 'else' or directive.value == 'endif':
self.bypass_ifpassthru = len([tok for tok in toks if tok.value == '__PCPP_ALWAYS_FALSE__' or tok.value == '__PCPP_ALWAYS_TRUE__']) > 0
if not self.bypass_ifpassthru and (directive.value == 'define' or directive.value == 'undef'):
if toks[0].value != self.potential_include_guard:
raise OutputDirective(Action.IgnoreAndPassThrough) # Don't execute anything with effects when inside an #if expr with undefined macro
if (directive.value == 'define' or directive.value == 'undef') and self.args.nevers:
if toks[0].value in self.args.nevers:
raise OutputDirective(Action.IgnoreAndPassThrough)
if self.args.passthru_defines:
super(CmdPreprocessor, self).on_directive_handle(directive,toks,ifpassthru,precedingtoks)
return None # Pass through where possible
return super(CmdPreprocessor, self).on_directive_handle(directive,toks,ifpassthru,precedingtoks)
def on_include_not_found(self,is_system_include,curdir,includepath):
if self.args.passthru_unfound_includes:
raise OutputDirective(Action.IgnoreAndPassThrough)
return super(CmdPreprocessor, self).on_include_not_found(is_system_include,curdir,includepath)
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
x[i].value = 'if'
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 ifpassthru:
# If this elif can only ever be true, simulate that
if result:
newtok = copy.copy(x[i+3])
newtok.type = self.t_INTEGER
newtok.value = self.t_INTEGER_TYPE(result)
x = x[:i+2] + [newtok] + [x[-1]]
raise OutputDirective(Action.IgnoreAndPassThrough)
# Otherwise elide
enable = False
elif result:
enable = True
iftrigger = True
else:
self.on_error(dirtokens[0].source,dirtokens[0].lineno,"Misplaced #elif")
elif name == 'else':
at_front_of_file = False
if ifstack:
if ifstack[-1].enable:
if ifpassthru:
enable = True
raise OutputDirective(Action.IgnoreAndPassThrough)
if enable: