Exemplo n.º 1
0
Arquivo: pcmd.py Projeto: oliora/pcpp
 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)
Exemplo n.º 2
0
        def on_directive_handle(self, directive, toks, ifpassthru, precedingtoks):
            if directive.value == "include":
                raise OutputDirective(action=Action.IgnoreAndPassThrough)
            elif directive.value == "define":
                assert toks
                macro_name = toks[0].value
                if macro_name in ISL_SEM_TO_SEM:
                    raise OutputDirective(action=Action.IgnoreAndRemove)

            return super(MacroExpandingCPreprocessor, self).on_directive_handle(
                    directive, toks, ifpassthru, precedingtoks)
        def on_directive_handle(self, directive, toks, ifpassthru,
                                precedingtoks):

            if directive.value == 'define' or directive.value == 'undef':
                if toks[0].type == 'CPP_ID' and toks[0].value in [
                        'SPGM', 'FSPGM', 'PROGMEM_STRING_DEF',
                        'AUTO_INIT_SPGM', 'AUTO_STRING_DEF'
                ]:
                    raise OutputDirective(Action.IgnoreAndPassThrough)
            # elif directive.value=='include':
            #     file = self.tokens_to_string(toks)
            #     if os.path.isabs(file):
            #         files = [file]
            #     else:
            #         files = []
            #         for path in self.path:
            #             new_path = os.path.abspath(os.path.join(path, file))
            #             if os.path.isfile(new_path):
            #                 files.append(new_path)
            #     for file in files:
            #         for ignore in self._skip_includes:
            #             if fnmatch.fnmatch(file, ignore):
            #                 if self.verbose:
            #                     print('include include %s' % file)
            #                 raise OutputDirective(Action.IgnoreAndPassThrough)
            #         break
            #     if self.verbose:
            #         if len(files)==1:
            #             files = files[0]
            #         self._include_counter += 1
            #         print('include %u: %s' % (self._include_counter, files))

            return Preprocessor.on_directive_handle(self, directive, toks,
                                                    ifpassthru, precedingtoks)
Exemplo n.º 4
0
 def on_include_not_found(self, is_malformed, is_system_include, curdir,
                          includepath):
     if self.args.passthru_unfound_includes:
         raise OutputDirective(Action.IgnoreAndPassThrough)
     return super(CmdPreprocessor,
                  self).on_include_not_found(is_malformed,
                                             is_system_include, curdir,
                                             includepath)
Exemplo n.º 5
0
 def on_include_not_found(self, is_system_include, curdir, includepath):
     self.handler.on_include_not_found(is_system_include, curdir,
                                       includepath)
     if not self.passthru_unfound_includes:
         raise OutputDirective(Action.IgnoreAndRemove)
     return super(FFIPreprocessor,
                  self).on_include_not_found(is_system_include, curdir,
                                             includepath)
        def on_file_open(self, is_system_include, includepath):
            if path.isfile(includepath):
                includepath = os.path.abspath(includepath)

                for skip_include in self._skip_includes:
                    if fnmatch.fnmatch(includepath, skip_include):
                        # SpgmConfig.debug('skip include %s pattern=%s' % (includepath, skip_include))
                        raise OutputDirective(Action.IgnoreAndPassThrough)

            # SpgmConfig.debug('pcpp %s' % includepath)

            try:
                result = Preprocessor.on_file_open(self, is_system_include,
                                                   includepath)
                if not includepath in self._files:
                    self._files.append(includepath)
                if self._display_info:
                    # tmp = includepath.split(os.sep)
                    # if len(tmp)>4:
                    #     includepath = os.sep.join(tmp[-4:])
                    print('Preprocessing %s' % path.relpath(includepath))
            except Exception as e:
                raise e
            return result
Exemplo n.º 7
0
Arquivo: cmd.py Projeto: meetnow/pcpp
 def on_include_not_found(self,is_system_include,curdir,includepath):
     if self.args.passthru_unfound_includes:
         raise OutputDirective()
     return super(CmdPreprocessor, self).on_include_not_found(is_system_include,curdir,includepath)