48
48
BLOCK_REGEX ,
49
49
CALL_REGEX ,
50
50
CONTAINS_REGEX ,
51
+ DEFINED_REGEX ,
51
52
DO_REGEX ,
52
53
END_ASSOCIATE_REGEX ,
53
54
END_BLOCK_REGEX ,
@@ -1034,7 +1035,7 @@ def preprocess_file(
1034
1035
# Look for and mark excluded preprocessor paths in file
1035
1036
# Initial implementation only looks for "if" and "ifndef" statements.
1036
1037
# For "if" statements all blocks are excluded except the "else" block if present
1037
- # For "ifndef" statements all blocks excluding the first block are exlucded
1038
+ # For "ifndef" statements all blocks excluding the first block are excluded
1038
1039
def eval_pp_if (text , defs = {}):
1039
1040
def replace_ops (expr ):
1040
1041
expr = expr .replace ("&&" , " and " )
@@ -1045,9 +1046,6 @@ def replace_ops(expr):
1045
1046
return expr
1046
1047
1047
1048
def replace_defined (line ):
1048
- DEFINED_REGEX = re .compile (
1049
- r"defined[ ]*\([ ]*([a-z_][a-z0-9_]*)[ ]*\)" , re .I
1050
- )
1051
1049
i0 = 0
1052
1050
out_line = ""
1053
1051
for match in DEFINED_REGEX .finditer (line ):
@@ -1106,7 +1104,7 @@ def replace_vars(line):
1106
1104
continue
1107
1105
# Handle conditional statements
1108
1106
match = PP_REGEX .match (line )
1109
- if match is not None :
1107
+ if match :
1110
1108
output_file .append (line )
1111
1109
def_name = None
1112
1110
if_start = False
@@ -1192,6 +1190,9 @@ def replace_vars(line):
1192
1190
log .debug (f"{ line .strip ()} !!! Include statement({ i + 1 } )" )
1193
1191
include_filename = match .group (1 ).replace ('"' , "" )
1194
1192
include_path = None
1193
+ # Intentionally keep this as a list and not a set. There are cases
1194
+ # where projects play tricks with the include order of their headers
1195
+ # to get their codes to compile. Using a set would not permit that.
1195
1196
for include_dir in include_dirs :
1196
1197
include_path_tmp = os .path .join (include_dir , include_filename )
1197
1198
if os .path .isfile (include_path_tmp ):
@@ -1221,7 +1222,7 @@ def replace_vars(line):
1221
1222
else :
1222
1223
log .debug (f"{ line .strip ()} !!! Could not locate include file ({ i + 1 } )" )
1223
1224
1224
- #
1225
+ # Substitute (if any) read in preprocessor macros
1225
1226
for def_tmp , value in defs_tmp .items ():
1226
1227
def_regex = def_regexes .get (def_tmp )
1227
1228
if def_regex is None :
0 commit comments