diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-01-27 19:59:29 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-01-27 19:59:29 -0800 |
commit | 0d3f30c21164b9fd722455e9fc60cdb0add2a866 (patch) | |
tree | c8b87736fd7c330f2b305923cb992998266f459f /043space.cc | |
parent | 50689bff2ed59814a67e74e90a33717552d69df0 (diff) | |
download | mu-0d3f30c21164b9fd722455e9fc60cdb0add2a866.tar.gz |
2610 - warn when recipes don't use default-space
Somehow this never transferred over from the Arc version until now.
Diffstat (limited to '043space.cc')
-rw-r--r-- | 043space.cc | 44 |
1 files changed, 44 insertions, 0 deletions
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<string, long long int>::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; +} |