sammine-lang
Loading...
Searching...
No Matches
ASTProperties.h
1#pragma once
2
3#include "ast/AstDecl.h"
4#include "typecheck/Types.h"
5#include "util/MonomorphizedName.h"
6#include <optional>
7#include <string>
8#include <unordered_map>
9
10namespace sammine_lang {
11namespace AST {
12
13struct CallProps {
14 std::optional<Type> callee_func_type;
15 bool is_partial = false;
16 std::optional<sammine_util::MonomorphizedName> resolved_name;
17 std::unordered_map<std::string, Type> type_bindings;
18 bool is_typeclass_call = false;
19 bool is_enum_constructor = false;
20 size_t enum_variant_index = 0;
21};
22
24 bool is_enum_unit_variant = false;
25 size_t enum_variant_index = 0;
26};
27
29 std::optional<sammine_util::MonomorphizedName> resolved_op_method;
30};
31
33 Type resolved_type = Type::NonExistent();
34};
35
37 Type concrete_type = Type::NonExistent();
38};
39
41 std::unordered_map<NodeId, CallProps> call_props_;
42 std::unordered_map<NodeId, VariableProps> variable_props_;
43 std::unordered_map<NodeId, BinaryProps> binary_props_;
44 std::unordered_map<NodeId, TypeAliasProps> type_alias_props_;
45 std::unordered_map<NodeId, TypeClassInstanceProps> type_class_instance_props_;
46 std::unordered_map<NodeId, Type> node_types_;
47
48public:
49 // Mutable accessors — auto-insert a default-constructed entry
50 CallProps &call(NodeId id) { return call_props_[id]; }
51 VariableProps &variable(NodeId id) { return variable_props_[id]; }
52 BinaryProps &binary(NodeId id) { return binary_props_[id]; }
53 TypeAliasProps &type_alias(NodeId id) { return type_alias_props_[id]; }
54 TypeClassInstanceProps &type_class_instance(NodeId id) {
55 return type_class_instance_props_[id];
56 }
57
58 // Const accessors — return pointer (nullptr if missing)
59 const CallProps *call(NodeId id) const {
60 auto it = call_props_.find(id);
61 return it != call_props_.end() ? &it->second : nullptr;
62 }
63 const VariableProps *variable(NodeId id) const {
64 auto it = variable_props_.find(id);
65 return it != variable_props_.end() ? &it->second : nullptr;
66 }
67 const BinaryProps *binary(NodeId id) const {
68 auto it = binary_props_.find(id);
69 return it != binary_props_.end() ? &it->second : nullptr;
70 }
71 const TypeAliasProps *type_alias(NodeId id) const {
72 auto it = type_alias_props_.find(id);
73 return it != type_alias_props_.end() ? &it->second : nullptr;
74 }
75 const TypeClassInstanceProps *type_class_instance(NodeId id) const {
76 auto it = type_class_instance_props_.find(id);
77 return it != type_class_instance_props_.end() ? &it->second : nullptr;
78 }
79
80 // Type accessors (for future AstBase::type migration)
81 void set_type(NodeId id, const Type &t) { node_types_[id] = t; }
82 Type get_type(NodeId id) const {
83 auto it = node_types_.find(id);
84 return it != node_types_.end() ? it->second : Type::NonExistent();
85 }
86 bool has_type(NodeId id) const { return node_types_.contains(id); }
87};
88
89} // namespace AST
90} // namespace sammine_lang
Holds declaration for all the AST Nodes.
Defines the core Type system for Sammine.
Definition ASTProperties.h:40
Definition Types.h:139
Definition ASTProperties.h:28
Definition ASTProperties.h:13
Definition ASTProperties.h:32
Definition ASTProperties.h:36
Definition ASTProperties.h:23