mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 16:58:45 +00:00
access syntax changed, sync with grammar, type_chack_visitor in progress
This commit is contained in:
parent
3d74b1383e
commit
6fc91aafa0
19 changed files with 110221 additions and 102967 deletions
|
|
@ -606,6 +606,12 @@ void BuildVisitor::Visit(SubExpressionToken& node) {
|
|||
} else if (current_node_type == parser::tokens::ScopedStatement) {
|
||||
node = std::make_unique<ScopedStatement>();
|
||||
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
||||
} if (current_node_type == parser::tokens::AccessExpression) {
|
||||
node = std::make_unique<AccessExpression>();
|
||||
Visit(std::get<std::unique_ptr<AccessExpression>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::Literal) {
|
||||
node = std::make_unique<Literal>();
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
|
@ -766,9 +772,9 @@ void BuildVisitor::Visit(ReferenceExpression* node) {
|
|||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
std::string reference = parse_node.NthChild(i).GetValue();
|
||||
if (reference == "~") {
|
||||
node->references[i] = ReferenceType::Reference;
|
||||
node->references[i] = utils::ReferenceType::Reference;
|
||||
} else if (reference == "@") {
|
||||
node->references[i] = ReferenceType::UniqueReference;
|
||||
node->references[i] = utils::ReferenceType::UniqueReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -780,6 +786,18 @@ void BuildVisitor::Visit(ReferenceExpression* node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(AccessExpression* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
Visit(node->name.get());
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("id");
|
||||
Visit(node->id);
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
// Other expressions
|
||||
|
||||
void BuildVisitor::Visit(FunctionArgument& node) {
|
||||
|
|
@ -964,25 +982,8 @@ void BuildVisitor::Visit(NameExpression* node) {
|
|||
current_node_ = parse_node.NthNamedChild(i);
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type != parser::tokens::TypeSubExpression && !namespaces_ended) {
|
||||
if (current_node_type != parser::tokens::TypeSubExpression) {
|
||||
namespaces_ended = true;
|
||||
|
||||
if (i + 1 == child_count) {
|
||||
node->expressions.emplace_back();
|
||||
|
||||
if (current_node_type == parser::tokens::ExtendedName) {
|
||||
node->expressions.back() = std::make_unique<ExtendedName>();
|
||||
Visit(node->expressions.back());
|
||||
} else if (current_node_type == parser::tokens::Literal) {
|
||||
node->expressions.back() = std::make_unique<Literal>();
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node->expressions.back()));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
}
|
||||
|
||||
if (!namespaces_ended) {
|
||||
|
|
@ -990,7 +991,7 @@ void BuildVisitor::Visit(NameExpression* node) {
|
|||
Visit(node->namespaces.back());
|
||||
} else {
|
||||
node->expressions.emplace_back();
|
||||
Visit(node->expressions.back());
|
||||
Visit(&node->expressions.back());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1249,9 +1250,9 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
std::string reference = parse_node.NthChild(i).GetValue();
|
||||
if (reference == "~") {
|
||||
node->references[i] = ReferenceType::Reference;
|
||||
node->references[i] = utils::ReferenceType::Reference;
|
||||
} else if (reference == "@") {
|
||||
node->references[i] = ReferenceType::UniqueReference;
|
||||
node->references[i] = utils::ReferenceType::UniqueReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1428,27 +1429,4 @@ void BuildVisitor::Visit(Literal& node) {
|
|||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
void BuildVisitor::Visit(NameSubExpression& node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.NthNamedChild(0);
|
||||
|
||||
std::string current_node_type = current_node_.GetType();
|
||||
|
||||
if (current_node_type == parser::tokens::ExtendedName) {
|
||||
node = std::make_unique<ExtendedName>();
|
||||
Visit(std::get<std::unique_ptr<ExtendedName>>(node).get());
|
||||
} else if (current_node_type == parser::tokens::Literal) {
|
||||
node = std::make_unique<Literal>();
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
} else if (current_node_type == parser::tokens::SuperExpression) {
|
||||
node = std::make_unique<SuperExpression>();
|
||||
Visit(*std::get<std::unique_ptr<SuperExpression>>(node));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
} // namespace interpreter
|
||||
|
|
|
|||
|
|
@ -146,6 +146,8 @@ void FindSymbolsVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
node->argument_graph_ids_[i] = namespace_visitor_.GetAbstractTypeGraph()->AddVertex();
|
||||
}
|
||||
|
||||
node->return_type_graph_id_ = namespace_visitor_.GetAbstractTypeGraph()->AddVertex();
|
||||
|
||||
info.expression = &node->value;
|
||||
|
||||
node->function_id_ = namespace_visitor_.AddFunctionDefinition(definition->name, std::move(info));
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ void LinkSymbolsVisitor::Visit(Partition* node) {
|
|||
}
|
||||
|
||||
void LinkSymbolsVisitor::Visit(Namespace* node) {
|
||||
node->type_id_ = namespace_visitor_.FindType({}, node->type);
|
||||
|
||||
if (node->name.has_value() && !node->type_id_.has_value()) {
|
||||
error_handling::HandleTypecheckError("Variable namespace type not found");
|
||||
}
|
||||
|
||||
namespace_visitor_.EnterNamespace(node->type);
|
||||
Visit(node->scope.get());
|
||||
namespace_visitor_.ExitNamespace();
|
||||
|
|
@ -203,6 +209,11 @@ void LinkSymbolsVisitor::Visit(ReferenceExpression* node) {
|
|||
Visit(node->expression.get());
|
||||
}
|
||||
|
||||
void LinkSymbolsVisitor::Visit(AccessExpression* node) {
|
||||
Visitor::Visit(node->name.get());
|
||||
Visitor::Visit(node->id);
|
||||
}
|
||||
|
||||
// Other Expressions
|
||||
|
||||
void LinkSymbolsVisitor::Visit(FunctionCallExpression* node) {
|
||||
|
|
@ -257,9 +268,9 @@ void LinkSymbolsVisitor::Visit(NameExpression* node) {
|
|||
for (auto& variable_namespace : node->namespaces) {
|
||||
Visitor::Visit(variable_namespace);
|
||||
}
|
||||
for (auto& expression : node->expressions) {
|
||||
Visitor::Visit(expression);
|
||||
}
|
||||
// for (auto& expression : node->expressions) {
|
||||
// Visit(expression);
|
||||
// }
|
||||
}
|
||||
|
||||
void LinkSymbolsVisitor::Visit(TupleName* node) {
|
||||
|
|
|
|||
212584
src/parser.c
212584
src/parser.c
File diff suppressed because it is too large
Load diff
|
|
@ -389,10 +389,10 @@ void PrintVisitor::Visit(ReferenceExpression* node) {
|
|||
out_ << "[ReferenceExpression ";
|
||||
for (auto& reference : node->references) {
|
||||
switch (reference) {
|
||||
case ReferenceType::Reference:
|
||||
case utils::ReferenceType::Reference:
|
||||
out_ << '~';
|
||||
break;
|
||||
case ReferenceType::UniqueReference:
|
||||
case utils::ReferenceType::UniqueReference:
|
||||
out_ << '@';
|
||||
break;
|
||||
}
|
||||
|
|
@ -402,6 +402,14 @@ void PrintVisitor::Visit(ReferenceExpression* node) {
|
|||
out_ << ')';
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(AccessExpression* node) {
|
||||
out_ << "[AccessExpression] (";
|
||||
Visit(node->name.get());
|
||||
out_ << ") : (";
|
||||
Visitor::Visit(node->id);
|
||||
out_ << ')';
|
||||
}
|
||||
|
||||
// Other Expressions
|
||||
|
||||
void PrintVisitor::Visit(FunctionCallExpression* node) {
|
||||
|
|
@ -499,7 +507,7 @@ void PrintVisitor::Visit(NameExpression* node) {
|
|||
out_ << '.';
|
||||
}
|
||||
for (size_t i = 0; i < node->expressions.size(); ++i) {
|
||||
Visitor::Visit(node->expressions[i]);
|
||||
Visit(&node->expressions[i]);
|
||||
if (i + 1 < node->expressions.size()) {
|
||||
out_ << '.';
|
||||
}
|
||||
|
|
@ -619,10 +627,10 @@ void PrintVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
out_ << "[ExtendedScopedAnyType ";
|
||||
for (auto& reference : node->references) {
|
||||
switch (reference) {
|
||||
case ReferenceType::Reference:
|
||||
case utils::ReferenceType::Reference:
|
||||
out_ << '~';
|
||||
break;
|
||||
case ReferenceType::UniqueReference:
|
||||
case utils::ReferenceType::UniqueReference:
|
||||
out_ << '@';
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "../include/type_check_visitor.hpp"
|
||||
#include <memory>
|
||||
|
||||
// TODO
|
||||
|
||||
|
|
@ -32,75 +33,36 @@ void TypeCheckVisitor::Visit(Partition* node) {
|
|||
|
||||
void TypeCheckVisitor::Visit(Namespace* node) {
|
||||
if (node->name.has_value()) {
|
||||
if (node->modifier.has_value()) {
|
||||
switch (node->modifier.value()) { // TODO
|
||||
case Namespace::Const:
|
||||
// TODO
|
||||
break;
|
||||
case Namespace::Var:
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
Visit(&node->name.value());
|
||||
// TODO: add modifiers
|
||||
node->variable_type_ = info::type::Type {info::type::DefinedType {node->type_id_.value()}};
|
||||
context_manager_.EnterVariableContext(node->name.value().name,
|
||||
global_info_.FindType(std::nullopt, node->type).value()); // TODO ??
|
||||
&node->variable_type_.value());
|
||||
}
|
||||
// global_info_.FindType(std::nullopt, node->type); // ??
|
||||
|
||||
global_info_.EnterNamespace(node->type);
|
||||
namespace_visitor_.EnterNamespace(node->type);
|
||||
|
||||
Visit(node->scope.get());
|
||||
|
||||
global_info_.ExitNamespace();
|
||||
namespace_visitor_.ExitNamespace();
|
||||
}
|
||||
|
||||
// Definitions -----------------
|
||||
|
||||
void TypeCheckVisitor::Visit(ImportStatement* node) { // TODO
|
||||
// if (node->name.has_value()) {
|
||||
// }
|
||||
// if (!node->symbols.empty()) {
|
||||
// for (auto& symbol : node->symbols) {
|
||||
// Visit(&symbol);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
void TypeCheckVisitor::Visit(ImportStatement* node) {}
|
||||
|
||||
void TypeCheckVisitor::Visit(AliasDefinitionStatement* node) {
|
||||
switch (node->modifier) {
|
||||
case AliasDefinitionStatement::Alias:
|
||||
break;
|
||||
case AliasDefinitionStatement::Type:
|
||||
break;
|
||||
case AliasDefinitionStatement::Let:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Visit(&node->type);
|
||||
// TODO check, that all paramaters used
|
||||
Visit(node->value.get());
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
||||
switch (node->modifier) {
|
||||
case VariableDefinitionStatement::Const:
|
||||
break;
|
||||
case VariableDefinitionStatement::Var:
|
||||
break;
|
||||
}
|
||||
Visitor::Visit(node->name);
|
||||
// TODO: add modifiers
|
||||
Visitor::Visit(node->value);
|
||||
Visitor::Visit(node->name);
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
||||
Visit(&node->name);
|
||||
for (auto& parameter : node->parameters) {
|
||||
Visit(parameter.get());
|
||||
}
|
||||
Visit(node->type.get());
|
||||
// later check, that function definition requirements are satisfied
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||
|
|
@ -304,6 +266,11 @@ void TypeCheckVisitor::Visit(ReferenceExpression* node) {
|
|||
out_ << ')';
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(AccessExpression* node) { // TODO
|
||||
Visitor::Visit(node->name);
|
||||
Visitor::Visit(node->id);
|
||||
}
|
||||
|
||||
// Other Expressions
|
||||
|
||||
void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
||||
|
|
@ -315,6 +282,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
|||
out_ << ", ";
|
||||
}
|
||||
out_ << ")";
|
||||
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(TupleExpression* node) {
|
||||
|
|
@ -336,9 +304,7 @@ void TypeCheckVisitor::Visit(VariantExpression* node) {
|
|||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(ReturnExpression* node) {
|
||||
out_ << "[Return] (";
|
||||
Visitor::Visit(node->expression);
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(TypeConstructor* node) {
|
||||
|
|
@ -410,31 +376,48 @@ void TypeCheckVisitor::Visit(NameExpression* node) {
|
|||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(TupleName* node) {
|
||||
out_ << "[TupleName] (";
|
||||
utils::IdType type = current_type_;
|
||||
|
||||
auto type_value = std::get_if<info::type::TupleType>(context_manager_.GetType(type));
|
||||
|
||||
if (type_value = nullptr) {
|
||||
error_handling::HandleTypecheckError("Mismatched types in tuple variable definition");
|
||||
}
|
||||
|
||||
if (type_value->constructors.size() != node->names.size()) {
|
||||
error_handling::HandleTypecheckError("Mismatched field count in tuple variable definition");
|
||||
}
|
||||
for (auto& name : node->names) {
|
||||
out_ << "& ";
|
||||
current_type_ = type_value->fields[i];
|
||||
Visitor::Visit(name);
|
||||
}
|
||||
out_ << ')';
|
||||
current_type_ = type;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(VariantName* node) {
|
||||
out_ << "[VariantName] (";
|
||||
for (auto& name : node->names) {
|
||||
out_ << "| ";
|
||||
void TypeCheckVisitor::Visit(VariantName* node) { // TODO
|
||||
utils::IdType type = current_type_;
|
||||
|
||||
auto type_value = std::get_if<info::type::VariantType>(context_manager_.GetType(type));
|
||||
|
||||
if (type_value = nullptr) {
|
||||
error_handling::HandleTypecheckError("Mismatched types in variant variable definition");
|
||||
}
|
||||
|
||||
if (type_value->constructors.size() != node->names.size()) {
|
||||
error_handling::HandleTypecheckError("Mismatched variant count in variant variable definition");
|
||||
}
|
||||
for (size_t i = 0; i < node->names.size(); ++i) {
|
||||
current_type_ = info::type::VariantType::MakeOptional(type_value->constructors[i]);
|
||||
Visitor::Visit(name);
|
||||
}
|
||||
out_ << ')';
|
||||
|
||||
current_type_ = type;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(AnnotatedName* node) {
|
||||
out_ << "[AnnotatedName ";
|
||||
Visit(&node->name);
|
||||
out_ << ']';
|
||||
context_manager_.DefineVariable(node->name, current_type_);
|
||||
if (node->type.has_value()) {
|
||||
out_ << " : (";
|
||||
Visitor::Visit(node->type.value());
|
||||
out_ << ')';
|
||||
// TODO: ?? check, that types are equal, add type requirement ??
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -443,135 +426,104 @@ void TypeCheckVisitor::Visit(AnnotatedName* node) {
|
|||
// Type
|
||||
|
||||
void TypeCheckVisitor::Visit(FunctionType* node) {
|
||||
out_ << "[FunctionType] (";
|
||||
bool is_first = true;
|
||||
info::type::FunctionType type;
|
||||
|
||||
type.argument_type_ids.reserve(node->types.size());
|
||||
for (auto& type : node->types) {
|
||||
if (!is_first) {
|
||||
out_ << " -> ";
|
||||
}
|
||||
is_first = false;
|
||||
Visitor::Visit(type);
|
||||
type.argument_types.push_back(current_type_);
|
||||
}
|
||||
out_ << ')';
|
||||
|
||||
current_type_ = context_manager_.AddType(std::move(type));
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(TupleType* node) {
|
||||
out_ << "[TupleType ";
|
||||
if (node->type.has_value()) {
|
||||
Visit(&node->type.value());
|
||||
}
|
||||
out_ << "] (";
|
||||
info::type::TupleType type;
|
||||
|
||||
type.type = node->type;
|
||||
|
||||
type.fields.reserve(node->entities.size());
|
||||
for (auto& entity : node->entities) {
|
||||
out_ << "& ";
|
||||
if (entity.first.has_value()) {
|
||||
Visit(&entity.first.value());
|
||||
out_ << " : ";
|
||||
}
|
||||
Visit(entity.second.get());
|
||||
type.fields.emplace_back(entity.first, current_type_);
|
||||
}
|
||||
out_ << ')';
|
||||
|
||||
current_type_ = context_manager_.AddType(std::move(type));
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(VariantType* node) {
|
||||
out_ << "[VariantType ";
|
||||
if (node->type.has_value()) {
|
||||
Visit(&node->type.value());
|
||||
}
|
||||
out_ << "] (";
|
||||
info::type::VariantType type;
|
||||
|
||||
type.type = node->type;
|
||||
|
||||
type.constructors.reserve(node->constructors.size());
|
||||
for (auto& constructor : node->constructors) {
|
||||
out_ << "| ";
|
||||
if (std::holds_alternative<Constructor>(constructor)) {
|
||||
Visit(&std::get<Constructor>(constructor));
|
||||
type.constructors.emplace_back(std::get<Constructor>(constructor));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TupleType>>(constructor)) {
|
||||
Visit(std::get<std::unique_ptr<TupleType>>(constructor).get());
|
||||
type.constructors.emplace_back(context_manager_.GetType(current_type_));
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
}
|
||||
out_ << ')';
|
||||
|
||||
current_type_ = context_manager_.AddType(std::move(type));
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(ParametrizedType* node) {
|
||||
out_ << "[ParametrizedType] (";
|
||||
info::type::DefinedType type;
|
||||
|
||||
Visit(node->type_expression.get());
|
||||
for (auto& parameter : node->parameters) {
|
||||
out_ << ' ';
|
||||
Visitor::Visit(parameter);
|
||||
type.type = current_type_;
|
||||
|
||||
type.paramaters.reserve(node->parameters.size());
|
||||
for (auto& paramater : node->parameters) {
|
||||
Visitor::Visit(paramater);
|
||||
type.paramaters.push_back(current_type_);
|
||||
}
|
||||
out_ << ')';
|
||||
|
||||
current_type_ = context_manager_.AddType(std::move(type));
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(TypeExpression* node) {
|
||||
out_ << "[TypeExpression ";
|
||||
|
||||
if (node->array_size.has_value()) {
|
||||
out_ << "[array size: " << node->array_size.value() << ']';
|
||||
}
|
||||
|
||||
out_ << "] (";
|
||||
for (auto& type_namespace : node->namespaces) {
|
||||
Visitor::Visit(type_namespace);
|
||||
out_ << '.';
|
||||
}
|
||||
Visit(&node->type);
|
||||
out_ << ')';
|
||||
current_type_ = context_manager_.AddType(info::type::DefinedType {node->type_id_, {}});
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(ExtendedScopedAnyType* node) {
|
||||
out_ << "[ExtendedScopedAnyType ";
|
||||
for (auto& reference : node->references) {
|
||||
switch (reference) {
|
||||
case ReferenceType::Reference:
|
||||
out_ << '~';
|
||||
break;
|
||||
case ReferenceType::UniqueReference:
|
||||
out_ << '@';
|
||||
break;
|
||||
}
|
||||
}
|
||||
out_ << "] (";
|
||||
info::type::ReferenceToType type;
|
||||
|
||||
type.references = node->references;
|
||||
Visitor::Visit(node->type);
|
||||
out_ << ')';
|
||||
type.type = current_type_;
|
||||
|
||||
current_type_ = context_manager_.AddType(std::move(type));
|
||||
}
|
||||
|
||||
// Typeclass
|
||||
|
||||
void TypeCheckVisitor::Visit(ParametrizedTypeclass* node) {
|
||||
out_ << "[ParametrizedTypeclass] (";
|
||||
Visit(node->typeclass_expression.get());
|
||||
for (auto& paramater : node->parameters) {
|
||||
out_ << ' ';
|
||||
Visitor::Visit(paramater);
|
||||
}
|
||||
out_ << ')';
|
||||
}
|
||||
void TypeCheckVisitor::Visit(ParametrizedTypeclass* node) {}
|
||||
|
||||
void TypeCheckVisitor::Visit(TypeclassExpression* node) {
|
||||
out_ << "[TypeclassExpression] (";
|
||||
for (auto& typeclass_namespace : node->namespaces) {
|
||||
Visitor::Visit(typeclass_namespace);
|
||||
out_ << '.';
|
||||
}
|
||||
Visit(&node->typeclass);
|
||||
out_ << ')';
|
||||
}
|
||||
void TypeCheckVisitor::Visit(TypeclassExpression* node) {}
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
// TODO don't make dublicates of the same types
|
||||
|
||||
void TypeCheckVisitor::Visit(FloatNumberLiteral* node) {
|
||||
current_type_ = info::BuiltInTypeInfo::FloatT;
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Float);
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(NumberLiteral* node) {
|
||||
out_ << "[Number " << node->value << "] ";
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Int);
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(StringLiteral* node) {
|
||||
out_ << "[String " << node->value << "] ";
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::String);
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(CharLiteral* node) {
|
||||
out_ << "[Char " << node->value << "] ";
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Char);
|
||||
}
|
||||
|
||||
} // namespace interpreter
|
||||
|
|
|
|||
|
|
@ -97,6 +97,12 @@ void Visitor::Visit(SubExpressionToken& node) {
|
|||
case 1:
|
||||
Visit(std::get<std::unique_ptr<ScopedStatement>>(node).get());
|
||||
break;
|
||||
case 2:
|
||||
Visit(std::get<std::unique_ptr<AccessExpression>>(node).get());
|
||||
break;
|
||||
case 3:
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
|
|
@ -313,23 +319,4 @@ void Visitor::Visit(Literal& node) {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void Visitor::Visit(NameSubExpression& node) {
|
||||
switch (node.index()) {
|
||||
case 0:
|
||||
Visit(std::get<std::unique_ptr<ExtendedName>>(node).get());
|
||||
break;
|
||||
case 1:
|
||||
Visit(*std::get<std::unique_ptr<Literal>>(node));
|
||||
break;
|
||||
case 2:
|
||||
Visit(*std::get<std::unique_ptr<SuperExpression>>(node));
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace interpreter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue