-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.h
72 lines (58 loc) · 2.42 KB
/
symbol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @file symbol.h
*
* The P/L0C Symbol table
*
* @author Randy Merkel, Slowly but Surly Software.
* @copyright (c) 2017 Slowly but Surly Software. All rights reserved.
*/
#ifndef SYMBOL_H
#define SYMBOL_H
#include <cstdint>
#include <map>
#include <sstream>
#include "datum.h"
/** A Symbol table entry
*
* Each entry describes one of the following objects:
* - Constant Datum value, type and block level, setting it's scope.
* - Variable location, as offset from a block/frame, n levels down, and its Datum type.
* - Procedure entry point, it's activation block/frame level, and vector of formal parameter kinds
* - Same as procedure, but with the additon of a return Datum type
*/
class SymValue {
public:
/// Kinds of symbol table entries
enum class Kind : char {
None, ///< Placeholder for a valid kind...
Variable, ///< A variable location
Constant, ///< A constant value
Procedure, ///< A procedure entry point
Function, ///< A function entry point and return value
};
static std::string toString(Kind k); ///< Return a kind as a string
typedef std::vector<Kind> KindVec; ///< Vector of Kinds
SymValue(); ///< Default constructor; undefined entry
SymValue(int level, Datum value); ///< Construct a constant value
/// Construct a Variable location
SymValue(int level, Datum::Integer value, Datum::Kind type);
SymValue(Kind kind, int level); ///< Construct procedure or funciton
/// Descructor
virtual ~SymValue() {}
Kind kind() const; ///< Return my kind
int level() const; ///< Return my activation frame level
Datum value(Datum value); ///< Set my value
Datum value() const; ///< Return my value
Datum::Kind type(Datum::Kind value); ///< Set my function return type
Datum::Kind type() const; ///< Return my function return type
Datum::KindVec& params(); ///< Subrountine parameter kinds
const Datum::KindVec& params() const; ///< Subrountine parameter kinds
private:
Kind k; ///< None, Variable, Procedure or Function
int l; ///< Activation frame level for Variables and subroutines.
Datum v; ///< Variable frame offset, Constant value or subroutine address
Datum::Kind t; ///< Datum value type
Datum::KindVec p; ///< Subrouuntine parameter kinds
};
/// A SymbolTable; a multimap of symbol identifiers to SymValue's
typedef std::multimap<std::string, SymValue> SymbolTable;
#endif