Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2021-2024 ChilliBits. All rights reserved. | ||
2 | |||
3 | #pragma once | ||
4 | |||
5 | #include <stack> | ||
6 | #include <string> | ||
7 | #include <utility> | ||
8 | |||
9 | #include <symboltablebuilder/Lifecycle.h> | ||
10 | #include <symboltablebuilder/QualType.h> | ||
11 | |||
12 | #include <llvm/IR/Value.h> | ||
13 | |||
14 | #include "../../lib/json/json.hpp" | ||
15 | |||
16 | namespace spice::compiler { | ||
17 | |||
18 | // Forward declarations | ||
19 | class Scope; | ||
20 | class ASTNode; | ||
21 | struct CodeLoc; | ||
22 | struct CompileTimeValue; | ||
23 | |||
24 | /** | ||
25 | * Entry of a symbol table, representing an individual symbol with all its properties | ||
26 | */ | ||
27 | class SymbolTableEntry final { | ||
28 | public: | ||
29 | // Constructors | ||
30 | 37176 | SymbolTableEntry(std::string name, const QualType &qualType, Scope *scope, ASTNode *declNode, size_t orderIndex, bool global) | |
31 |
1/2✓ Branch 3 taken 37176 times.
✗ Branch 4 not taken.
|
37176 | : name(std::move(name)), scope(scope), declNode(declNode), orderIndex(orderIndex), global(global), qualType(qualType){}; |
32 | |||
33 | // Public methods | ||
34 | [[nodiscard]] const QualType &getQualType() const; | ||
35 | void updateType(const QualType &newType, bool overwriteExistingType); | ||
36 | void updateState(const LifecycleState &newState, const ASTNode *node, bool force = false); | ||
37 | [[nodiscard]] const CodeLoc &getDeclCodeLoc() const; | ||
38 | [[nodiscard]] virtual llvm::Value *getAddress() const; | ||
39 | void updateAddress(llvm::Value *address); | ||
40 | void pushAddress(llvm::Value *address); | ||
41 | void popAddress(); | ||
42 | [[nodiscard]] bool isField() const; | ||
43 | 5106 | [[nodiscard]] const Lifecycle &getLifecycle() const { return lifecycle; } | |
44 | [[nodiscard]] bool isInitialized() const { return lifecycle.isInitialized(); } | ||
45 | [[nodiscard]] nlohmann::ordered_json toJSON() const; | ||
46 | |||
47 | // Public members | ||
48 | const std::string name; | ||
49 | Scope *scope; | ||
50 | ASTNode *declNode; | ||
51 | const size_t orderIndex; | ||
52 | const bool global; | ||
53 | bool isVolatile = false; | ||
54 | bool isParam = false; | ||
55 | bool anonymous = false; | ||
56 | bool used = false; | ||
57 | bool omitDtorCall = false; | ||
58 | bool isImplicitField = false; | ||
59 | |||
60 | private: | ||
61 | // Members | ||
62 | QualType qualType; | ||
63 | std::stack<llvm::Value *> memAddress; | ||
64 | Lifecycle lifecycle; | ||
65 | }; | ||
66 | |||
67 | } // namespace spice::compiler | ||
68 |