mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-09 00:18:44 +00:00
better global_info API, better const/var/static handling, const typeclass requirements, fixes
This commit is contained in:
parent
047ead6fa3
commit
4f54bb4bd7
15 changed files with 381 additions and 213 deletions
|
|
@ -58,12 +58,14 @@ void BuildVisitor::Visit(Namespace* node) {
|
|||
if (child_count > 3) { // "namespace", ["var"/"const",] type, scope
|
||||
std::string modifier = parse_node.NthChild(1).GetValue();
|
||||
if (modifier == "const") {
|
||||
node->modifier = utils::IsConstModifier::Const;
|
||||
node->modifier = utils::ClassInternalsModifier::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = utils::IsConstModifier::Var;
|
||||
node->modifier = utils::ClassInternalsModifier::Var;
|
||||
} else {
|
||||
error_handling::HandleInternalError("Can't parse namespace modifier", "BuildVisitor.Namespace");
|
||||
}
|
||||
} else {
|
||||
node->modifier = utils::ClassInternalsModifier::Static;
|
||||
}
|
||||
|
||||
node->type = parse_node.ChildByFieldName("type").GetValue();
|
||||
|
|
@ -273,15 +275,26 @@ void BuildVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
if (current_node_.PreviousSibling().GetValue() != "var") {
|
||||
node->function_requirements.push_back(std::make_unique<FunctionDeclaration>());
|
||||
Visit(node->function_requirements.back().get());
|
||||
} else {
|
||||
node->method_requirements.push_back(std::make_unique<FunctionDeclaration>());
|
||||
Visit(node->method_requirements.back().get());
|
||||
}
|
||||
if (child_count > 1) {
|
||||
node->requirements.reserve(child_count - 1);
|
||||
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
|
||||
std::string modifier_name = current_node_.PreviousSibling().GetValue();
|
||||
utils::ClassInternalsModifier modifier;
|
||||
if (modifier_name == "const") {
|
||||
modifier = utils::ClassInternalsModifier::Const;
|
||||
} else if (modifier_name == "var") {
|
||||
modifier = utils::ClassInternalsModifier::Var;
|
||||
} else {
|
||||
modifier = utils::ClassInternalsModifier::Static;
|
||||
}
|
||||
node->requirements.push_back({modifier,
|
||||
std::make_unique<FunctionDeclaration>()});
|
||||
Visit(node->requirements.back().second.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue