mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2026-01-25 13:07:13 +00:00
literals type check
This commit is contained in:
parent
43dfa75b74
commit
5f8d5c5569
3 changed files with 77 additions and 0 deletions
12
include/basic_type_check.hpp
Normal file
12
include/basic_type_check.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basic_nodes.hpp"
|
||||||
|
#include "sources_manager.hpp"
|
||||||
|
|
||||||
|
namespace type_check {
|
||||||
|
|
||||||
|
// IN PROGRESS: modifiers ??
|
||||||
|
nodes::TypeCheckResult type_check_literal(const nodes::Literal &literal,
|
||||||
|
SourcesManager &sources_manager);
|
||||||
|
|
||||||
|
} // namespace type_check
|
||||||
64
src/basic_type_check.cpp
Normal file
64
src/basic_type_check.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include "basic_type_check.hpp"
|
||||||
|
|
||||||
|
namespace type_check {
|
||||||
|
|
||||||
|
nodes::TypeCheckResult type_check_literal(const nodes::Literal &literal,
|
||||||
|
SourcesManager &sources_manager) {
|
||||||
|
switch (literal.get_any()->index()) {
|
||||||
|
case 0: // float
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::FLOAT));
|
||||||
|
case 1: // double
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::DOUBLE));
|
||||||
|
case 2: // int32_t
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::INT));
|
||||||
|
case 3: // int64_t
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::LONG));
|
||||||
|
case 4: // size_t
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::INDEX));
|
||||||
|
case 5: // std::string
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->add_array_of(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::CHAR)));
|
||||||
|
case 6: // unicode_string
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->add_array_of(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::UNICODE)));
|
||||||
|
case 7: // char
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::CHAR));
|
||||||
|
case 8: // unicode
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::UNICODE));
|
||||||
|
case 9: // bool
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::BOOL));
|
||||||
|
case 10: // unit
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::UNIT));
|
||||||
|
case 11: // null
|
||||||
|
return nodes::TypeCheckResult(
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::NULL_OPTION));
|
||||||
|
}
|
||||||
|
|
||||||
|
error_handling::handle_general_error("Unreachable");
|
||||||
|
exit(1); // unreachable
|
||||||
|
} // IN PROGRESS: modifiers ??
|
||||||
|
|
||||||
|
} // namespace type_check
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "expression_type_check.hpp"
|
#include "expression_type_check.hpp"
|
||||||
|
|
||||||
#include "basic_nodes.hpp"
|
#include "basic_nodes.hpp"
|
||||||
|
#include "basic_type_check.hpp"
|
||||||
#include "builtin_types.hpp"
|
#include "builtin_types.hpp"
|
||||||
#include "error_log.hpp"
|
#include "error_log.hpp"
|
||||||
#include "sources_manager.hpp"
|
#include "sources_manager.hpp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue