GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/SymbolTable.h
Date: 2025-02-05 01:09:36
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 19644 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 SymbolTableEntry *lookupStrict(const std::string &symbolName);
44 SymbolTableEntry *lookupInComposedFields(const std::string &name, std::vector<size_t> &indexPath);
45 SymbolTableEntry *lookupStrictByIndex(unsigned int orderIndex);
46 SymbolTableEntry *lookupAnonymous(const CodeLoc &codeLoc, size_t numericSuffix = 0);
47 Capture *lookupCapture(const std::string &name);
48 Capture *lookupCaptureStrict(const std::string &name);
49 void setCapturingRequired();
50 void deleteAnonymous(const std::string &name);
51 [[nodiscard]] nlohmann::json toJSON() const;
52
53 // Public members
54 SymbolTable *parent;
55 Scope *scope;
56 SymbolMap symbols;
57 CaptureMap captures;
58 bool capturingRequired = false;
59 };
60
61 } // namespace spice::compiler
62