Gyoji Compiler
Loading...
Searching...
No Matches
symbols.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#pragma once
16
17#include <gyoji-misc/pointers.hpp>
18#include <gyoji-mir/types.hpp>
19
20#include <string>
21#include <map>
22#include <vector>
23
24namespace Gyoji::mir {
25
38 class Symbol {
39 public:
40 typedef enum {
41 SYMBOL_STATIC_FUNCTION,
42 SYMBOL_MEMBER_METHOD,
43 SYMBOL_MEMBER_DESTRUCTOR
44 } SymbolType;
52 Symbol(std::string _name, SymbolType _type, const Type *_mir_type);
53
60 ~Symbol();
61
65 std::string get_name() const;
70 const Type *get_mir_type() const;
71
72 SymbolType get_type() const;
73 private:
74 std::string name;
75 SymbolType type;
76 const Type *mir_type;
77 };
78
94 class Symbols {
95 public:
99 Symbols();
106 ~Symbols();
107
117 void define_symbol(
118 std::string name,
119 Symbol::SymbolType _sym_type,
120 const Type *symbol_type);
121
130 const Symbol * get_symbol(std::string name) const;
131
136 void dump(FILE *out) const;
137 private:
139 };
140
141};
142
A symbol defined globally inside a namespace.
Definition symbols.hpp:38
~Symbol()
Move along, nothing to see here.
Definition symbols.cpp:28
std::string get_name() const
Definition symbols.cpp:32
const Type * get_mir_type() const
Definition symbols.cpp:36
Symbol table for the intermediate representation (MIR)
Definition symbols.hpp:94
void define_symbol(std::string name, Symbol::SymbolType _sym_type, const Type *symbol_type)
Create a new global symbol.
Definition symbols.cpp:51
const Symbol * get_symbol(std::string name) const
Look up a symbol by name.
Definition symbols.cpp:89
Symbols()
Definition symbols.cpp:44
void dump(FILE *out) const
Definition symbols.cpp:64
~Symbols()
Move along, nothing to see here.
Definition symbols.cpp:47
This represents a type as declared in a translation unit.
Definition types.hpp:313
Middle intermediate representation (MIR) of a translation unit.
Definition gyoji-mir.hpp:51