| 1107 | } |
| 1108 | |
| 1109 | bool reshadefx::preprocessor::evaluate_identifier_as_macro() |
| 1110 | { |
| 1111 | if (_token.literal_as_string == "__LINE__") |
| 1112 | { |
| 1113 | push(std::to_string(_token.location.line)); |
| 1114 | return true; |
| 1115 | } |
| 1116 | if (_token.literal_as_string == "__FILE__") |
| 1117 | { |
| 1118 | push(escape_string(_token.location.source)); |
| 1119 | return true; |
| 1120 | } |
| 1121 | if (_token.literal_as_string == "__FILE_STEM__") |
| 1122 | { |
| 1123 | const std::filesystem::path file_stem = std::filesystem::u8path(_token.location.source).stem(); |
| 1124 | push(escape_string(file_stem.u8string())); |
| 1125 | return true; |
| 1126 | } |
| 1127 | if (_token.literal_as_string == "__FILE_STEM_HASH__") |
| 1128 | { |
| 1129 | const std::filesystem::path file_stem = std::filesystem::u8path(_token.location.source).stem(); |
| 1130 | push(std::to_string(std::hash<std::string>()(file_stem.u8string()) & 0xFFFFFFFF)); |
| 1131 | return true; |
| 1132 | } |
| 1133 | if (_token.literal_as_string == "__FILE_NAME__") |
| 1134 | { |
| 1135 | const std::filesystem::path file_name = std::filesystem::u8path(_token.location.source).filename(); |
| 1136 | push(escape_string(file_name.u8string())); |
| 1137 | return true; |
| 1138 | } |
| 1139 | if (_token.literal_as_string == "__FILE_NAME_HASH__") |
| 1140 | { |
| 1141 | const std::filesystem::path file_name = std::filesystem::u8path(_token.location.source).filename(); |
| 1142 | push(std::to_string(std::hash<std::string>()(file_name.u8string()) & 0xFFFFFFFF)); |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
| 1146 | const auto macro_it = _macros.find(_token.literal_as_string); |
| 1147 | if (macro_it == _macros.end()) |
| 1148 | return false; |
| 1149 | |
| 1150 | if (!_input_stack.empty()) |
| 1151 | { |
| 1152 | const std::unordered_set<std::string> &hidden_macros = _input_stack[_current_input_index].hidden_macros; |
| 1153 | if (hidden_macros.find(_token.literal_as_string) != hidden_macros.end()) |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
| 1157 | const location macro_location = _token.location; |
| 1158 | if (_recursion_count++ >= 256) |
| 1159 | return error(macro_location, "macro recursion too high"), false; |
| 1160 | |
| 1161 | std::vector<std::string> arguments; |
| 1162 | if (macro_it->second.is_function_like) |
| 1163 | { |
| 1164 | if (!accept(tokenid::parenthesis_open)) |
| 1165 | return false; // Function like macro used without arguments, handle that like a normal identifier instead |
| 1166 |
nothing calls this directly
no test coverage detected