| 257 | } |
| 258 | |
| 259 | static Macro *getParentMacro(const Macro *targetMacro, |
| 260 | const std::vector<Macro *> ¯os) |
| 261 | { |
| 262 | if (!targetMacro) { |
| 263 | return nullptr; |
| 264 | } |
| 265 | |
| 266 | if (macros.empty()) { |
| 267 | return nullptr; |
| 268 | } |
| 269 | |
| 270 | std::vector<Macro *> newMacros; |
| 271 | for (const auto ¯o : macros) { |
| 272 | for (const auto &action : macro->Actions()) { |
| 273 | const auto nestedMacroAction = |
| 274 | dynamic_cast<MacroActionMacro *>(action.get()); |
| 275 | if (!nestedMacroAction) { |
| 276 | continue; |
| 277 | } |
| 278 | |
| 279 | if (nestedMacroAction->_nestedMacro.get() == |
| 280 | targetMacro) { |
| 281 | return nestedMacroAction->GetMacro(); |
| 282 | } |
| 283 | |
| 284 | newMacros.emplace_back( |
| 285 | nestedMacroAction->_nestedMacro.get()); |
| 286 | } |
| 287 | for (const auto &action : macro->ElseActions()) { |
| 288 | const auto nestedMacroAction = |
| 289 | dynamic_cast<MacroActionMacro *>(action.get()); |
| 290 | if (!nestedMacroAction) { |
| 291 | continue; |
| 292 | } |
| 293 | |
| 294 | if (nestedMacroAction->_nestedMacro.get() == |
| 295 | targetMacro) { |
| 296 | return nestedMacroAction->GetMacro(); |
| 297 | } |
| 298 | |
| 299 | newMacros.emplace_back( |
| 300 | nestedMacroAction->_nestedMacro.get()); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | return getParentMacro(targetMacro, newMacros); |
| 305 | } |
| 306 | |
| 307 | static Macro *getParentMacro(const Macro *macro) |
| 308 | { |