-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemantics.hpp
77 lines (69 loc) · 2 KB
/
semantics.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by tate on 02-05-20.
//
#ifndef SCL_SEMANTICS_HPP
#define SCL_SEMANTICS_HPP
#include <cinttypes>
#include <string>
#include <unordered_map>
#include <vector>
#include <filesystem>
#include "../parse/parse.hpp"
/* Semantic Analysis
*
* Reduce Syntax:
* - Convert Builtin-identifiers/constants (ie - print)
* - Handle operator associativity
* - Convert complex let expressions
* + let a = 2, b = 4;
* --->
* + let a; a = 2; let b; b = 4;
* - remove PAREN_EXPRs
* - Convert function calls on CSV's to list
*
* Check Safety:
* - basic typechecking and type deduction
* - use before declaration (maybe remove in future)
* -
*
* Optimize performance:
* - Simplify Const-exprs
* - macro inlining
* - no construction-call-destruction for arguments
* - replace object member requests with index operation (compile-time IC)
*/
// TODO make this use the token instead
class SemanticError {
public:
std::string msg;
unsigned long long int pos;
std::filesystem::path file;
bool is_warn;
// if only I could just do
// template <typename FILE_PATH_T> ...
SemanticError(
std::string message,
const unsigned long long position,
const char* file_name,
bool is_warning = false):
msg(std::move(message)), pos(position), file(file_name), is_warn(is_warning) {}
SemanticError(
std::string message,
const unsigned long long position,
std::string file_name,
bool is_warning = false):
msg(std::move(message)), pos(position), file(std::move(file_name)), is_warn(is_warning) {}
SemanticError(
std::string message,
const unsigned long long position,
std::filesystem::path file = std::filesystem::current_path(),
bool is_warning = false):
msg(std::move(message)), pos(position), file(std::move(file)), is_warn(is_warning) {}
SemanticError(
std::string message,
const Token& t,
bool is_warning = false):
msg(std::move(message)), pos(t.pos), file(t.file), is_warn(is_warning) {}
};
std::vector<SemanticError> process_tree(AST& tree);
#endif //SCL_SEMANTICS_HPP