From 0d3f30c21164b9fd722455e9fc60cdb0add2a866 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 27 Jan 2016 19:59:29 -0800 Subject: 2610 - warn when recipes don't use default-space Somehow this never transferred over from the Arc version until now. --- 043space.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to '043space.cc') diff --git a/043space.cc b/043space.cc index 662e7527..5bbda699 100644 --- a/043space.cc +++ b/043space.cc @@ -243,3 +243,47 @@ void rewrite_default_space_instruction(instruction& curr) { raise_error << "new-default-space can't take any results\n" << end(); curr.products.push_back(reagent("default-space:address:shared:array:location")); } + +//:: all recipes must set default-space one way or another + +:(before "End Globals") +bool Warn_on_missing_default_space = false; +:(before "End Checks") +Transform.push_back(check_default_space); // idempotent +:(code) +void check_default_space(const recipe_ordinal r) { + if (!Warn_on_missing_default_space) return; // skip previous core tests; this is only for mu code + const recipe& caller = get(Recipe, r); + // skip scenarios (later layer) + // user code should never create recipes with underscores in their names + if (caller.name.find("scenario_") == 0) return; // skip mu scenarios which will use raw memory locations + if (caller.name.find("run_") == 0) return; // skip calls to 'run', which should be in scenarios and will also use raw memory locations + // assume recipes with only numeric addresses know what they're doing (usually tests) + if (!contains_non_special_name(r)) return; + trace(9991, "transform") << "--- check that recipe " << caller.name << " sets default-space" << end(); + if (caller.steps.empty()) return; + if (caller.steps.at(0).products.empty() + || caller.steps.at(0).products.at(0).name != "default-space") { + raise << maybe(caller.name) << " does not seem to start with default-space or local-scope\n" << end(); +//? cerr << maybe(caller.name) << " does not seem to start with default-space or local-scope\n" << '\n'; + } +} +:(after "Load .mu Core") +Warn_on_missing_default_space = true; +:(after "Test Runs") +Warn_on_missing_default_space = false; +:(after "Running Main") +Warn_on_missing_default_space = true; + +:(code) +bool contains_non_special_name(const recipe_ordinal r) { + for (map::iterator p = Name[r].begin(); p != Name[r].end(); ++p) { + if (p->first.empty()) continue; + if (p->first.find("stash_") == 0) continue; // generated by rewrite_stashes_to_text + if (!is_special_name(p->first)) { +//? cerr << " " << Recipe[r].name << ": " << p->first << '\n'; + return true; + } + } + return false; +} -- cgit 1.4.1-2-gfad0