GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/SymbolTable.h
Date: 2025-02-09 04:23:07
Exec Total Coverage
Lines: 1 1 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8
9 #include <model/GenericType.h>
10 #include <symboltablebuilder/Capture.h>
11 #include <symboltablebuilder/SymbolTableEntry.h>
12
13 #include "../../lib/json/json.hpp"
14
15 namespace spice::compiler {
16
17 // Forward declarations
18 class Scope;
19 class Type;
20 struct CodeLoc;
21
22 using CaptureMap = std::unordered_map<std::string /*name*/, Capture /*capture*/>;
23 using SymbolMap = std::unordered_map<std::string /*name*/, SymbolTableEntry /*entry*/>;
24
25 /**
26 * Class for storing information about symbols of the program.
27 * Symbol tables are arranged in a tree structure, so that you can navigate with the .parent property and getChild() method up
28 * and down the tree.
29 */
30 class SymbolTable {
31 public:
32 // Constructors
33 19646 SymbolTable(SymbolTable *parent, Scope *scope) : parent(parent), scope(scope) {}
34
35 // Friend classes
36 friend class Scope;
37
38 // Public methods
39 SymbolTableEntry *insert(const std::string &name, ASTNode *declNode, bool isAnonymousSymbol = false);
40 SymbolTableEntry *insertAnonymous(const QualType &qualType, ASTNode *declNode, size_t numericSuffix = 0);
41 SymbolTableEntry *copySymbol(const std::string &originalName, const std::string &newName);
42 SymbolTableEntry *lookup(const std::string &name);
43 std::pair<SymbolTableEntry *, bool> lookupWithAliasResolution(const std::string &name);
44 SymbolTableEntry *lookupStrict(const std::string &symbolName);
45 SymbolTableEntry *lookupInComposedFields(const std::string &name, std::vector<size_t> &indexPath);
46 SymbolTableEntry *lookupStrictByIndex(unsigned int orderIndex);
47 SymbolTableEntry *lookupAnonymous(const CodeLoc &codeLoc, size_t numericSuffix = 0);
48 Capture *lookupCapture(const std::string &name);
49 Capture *lookupCaptureStrict(const std::string &name);
50 void setCapturingRequired();
51 void deleteAnonymous(const std::string &name);
52 [[nodiscard]] nlohmann::json toJSON() const;
53
54 // Public members
55 SymbolTable *parent;
56 Scope *scope;
57 SymbolMap symbols;
58 CaptureMap captures;
59 bool capturingRequired = false;
60 };
61
62 } // namespace spice::compiler
63