Share the Reference analysis task with the Define one
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
2c0cec16d6
commit
dbb08a5299
|
@ -35,11 +35,7 @@ private:
|
|||
),
|
||||
share_task(Reference, Function),
|
||||
share_task(Reference, Class),
|
||||
make_nonlocal_task(Define,
|
||||
const optional previousDefinition = parsedTree.findReferenceByName<Define>(parseComponent.name).value();
|
||||
if (&previousDefinition.value().get() != &parseComponent && (previousDefinition.value().get().final || parseComponent.final))
|
||||
error(parseComponent.name + string(previousDefinition->get().final ? " cannot be redefined as it is final" : " cannot be made final after it has been declared"));
|
||||
)
|
||||
share_task(Reference, Define<true>),
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -105,12 +105,12 @@ public:
|
|||
#undef IS_PARSECOMPONENT
|
||||
|
||||
namespace StandardComponents {
|
||||
struct Define: NamedIdentifier<true> {
|
||||
const bool final;
|
||||
template<bool BOOL>
|
||||
struct Define: NamedIdentifier<BOOL> {
|
||||
const bool final = BOOL;
|
||||
ParseTree content;
|
||||
explicit Define(const bool& isFinal, string_view nameText, ParseTree&& content): NamedIdentifier(nameText), final(isFinal), content(move(content)) {}
|
||||
explicit Define(string_view nameText, ParseTree&& content): Define(false, nameText, move(content)) {}
|
||||
Define(Define&& define) noexcept: Define(define.final, define.name, move(define.content)) {}
|
||||
explicit Define(string_view nameText, ParseTree&& content): NamedIdentifier<BOOL>(nameText), content(move(content)) {}
|
||||
Define(Define&& define) noexcept: Define(define.name, move(define.content)) {}
|
||||
};
|
||||
struct Reference: NamedIdentifier<false> {
|
||||
using NamedIdentifier::NamedIdentifier;
|
||||
|
|
|
@ -142,7 +142,12 @@ namespace Parser {
|
|||
const auto end = find_if(beginning, lexed.end(), [¤t](const tok& it){
|
||||
return it.toktype == SEMICOLON || it.line != current.line;
|
||||
});
|
||||
parseTree << Define(isFinalDefine, current.toktext, parse(beginning, end));
|
||||
if (isFinalDefine) {
|
||||
parseTree << Define<true>(current.toktext, parse(beginning, end));
|
||||
} else {
|
||||
parseTree << Define<false>(current.toktext, parse(beginning, end));
|
||||
}
|
||||
|
||||
i += 1 + isFinalDefine + distance(beginning, end);
|
||||
} else {
|
||||
const bool method = nextAre({DOT, IDENTIFIER, LPAR});
|
||||
|
|
|
@ -132,7 +132,8 @@ public:
|
|||
output << ')';
|
||||
),
|
||||
make_task(StandardComponents::types::Integer, output << setprecision(parseComponent.precision) << fixed << parseComponent.value;),
|
||||
make_task(StandardComponents::Condition, output << '('; transpileTree(parseComponent); output << ')';)
|
||||
make_task(StandardComponents::Condition, output << '('; transpileTree(parseComponent); output << ')';),
|
||||
share_task(StandardComponents::Define<false>, StandardComponents::Define<true>)
|
||||
}));
|
||||
return fullMap;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@ struct GsTarget: Target {
|
|||
print_functions_pair printFunctions() final { return make_pair("printraw", "print"); }
|
||||
unordered_task_map getTaskMap() final {
|
||||
return {
|
||||
make_task(Define,
|
||||
make_task(Define<false>,
|
||||
output << (parseComponent.final ? "const " : "var ") << parseComponent.name << " = ";
|
||||
transpileTree(parseComponent.content);
|
||||
),
|
||||
|
|
|
@ -7,7 +7,7 @@ struct JsTarget: Target {
|
|||
bool use_uniqueLineSeparator() final { return true; }
|
||||
unordered_task_map getTaskMap() final {
|
||||
return {
|
||||
make_task(Define,
|
||||
make_task(Define<false>,
|
||||
output << (parseComponent.final ? "const " : "let ") << parseComponent.name << " = ";
|
||||
transpileTree(parseComponent.content);
|
||||
),
|
||||
|
|
|
@ -7,7 +7,7 @@ struct LuaTarget: Target {
|
|||
optional_string uniqueLineSeparator() final { return " "; }
|
||||
unordered_task_map getTaskMap() final {
|
||||
return {
|
||||
make_task(Define,
|
||||
make_task(Define<false>,
|
||||
if (parseComponent.final) output << "local ";
|
||||
output << parseComponent.name;
|
||||
if (parseComponent.final) output << " <const>"; // TODO Find an alternative to <const> for lua <5.4
|
||||
|
|
|
@ -7,7 +7,7 @@ struct PyTarget: Target {
|
|||
optional_string uniqueLineSeparator() final { return {}; }
|
||||
unordered_task_map getTaskMap() final {
|
||||
return {
|
||||
make_task(Define, output << parseComponent.name << " = "; transpileTree(parseComponent.content);),
|
||||
make_task(Define<false>, output << parseComponent.name << " = "; transpileTree(parseComponent.content);),
|
||||
make_task(types::String, stringInterpolation(R"(""")", parseComponent.content);),
|
||||
make_task(Function,
|
||||
output << "def " << parseComponent.name << '(';
|
||||
|
|
Loading…
Reference in New Issue