MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / SConsPreProcessorPatch

Class SConsPreProcessorPatch

tools/preprocessor.py:27–74  ·  view source on GitHub ↗

SCons PreProcessor patch class This class provides methods to patch the SCons PreProcessor to handle conditional compilation directives properly.

Source from the content-addressed store, hash-verified

25from SCons.Script import *
26
27class SConsPreProcessorPatch:
28 """
29 SCons PreProcessor patch class
30
31 This class provides methods to patch the SCons PreProcessor
32 to handle conditional compilation directives properly.
33 """
34
35 def __init__(self):
36 """Initialize the PreProcessor patch"""
37 self._patched_preprocessor = None
38 self._apply_patch()
39
40 def _apply_patch(self):
41 """
42 Apply the patch to SCons PreProcessor
43
44 This method patches the SCons.cpp.PreProcessor class with
45 custom methods for handling includes during conditional compilation.
46 """
47 from SCons import cpp
48
49 # Store reference to original PreProcessor
50 self._patched_preprocessor = cpp.PreProcessor
51
52 # Create bound methods for the patch
53 def start_handling_includes(preprocessor_self, t=None):
54 d = preprocessor_self.dispatch_table
55 p = preprocessor_self.stack[-1] if preprocessor_self.stack else preprocessor_self.default_table
56 for k in ('import', 'include', 'include_next', 'define'):
57 d[k] = p[k]
58
59 def stop_handling_includes(preprocessor_self, t=None):
60 d = preprocessor_self.dispatch_table
61 d['import'] = preprocessor_self.do_nothing
62 d['include'] = preprocessor_self.do_nothing
63 d['include_next'] = preprocessor_self.do_nothing
64 d['define'] = preprocessor_self.do_nothing
65
66 # Apply the patch methods
67 self._patched_preprocessor.start_handling_includes = start_handling_includes
68 self._patched_preprocessor.stop_handling_includes = stop_handling_includes
69
70 def get_patched_preprocessor(self):
71 return self._patched_preprocessor
72
73 def create_preprocessor_instance(self):
74 return self._patched_preprocessor()
75
76# Global instance for easy access
77_preprocessor_patch = None

Callers 3

get_patched_preprocessorFunction · 0.85
test_preprocessor_patchFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_preprocessor_patchFunction · 0.68