File: symtab.h

package info (click to toggle)
icmake 13.05.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,132 kB
  • sloc: cpp: 11,595; fortran: 883; makefile: 853; sh: 546; pascal: 342
file content (82 lines) | stat: -rw-r--r-- 2,682 bytes parent folder | download | duplicates (2)
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
73
74
75
76
77
78
79
80
81
82
#ifndef INCLUDED_SYMTAB_
#define INCLUDED_SYMTAB_

#include <cstdint>
#include <string>
#include <vector>

#include "../exprtype/exprtype.h"

class SemVal;
class Functions;

// see README.stackframe for the construction of stackframes

struct Symtab
{
    struct Var
    {
        std::string name;               // var's name
        ExprType    varType;            // int, string, list:  | e_var
        uint16_t    location;           // the variable's location 
                                        // (xx, 0xc0xx, 0xbfxx)
    };

    using VarVect = std::vector<Var>;

    private:
        Functions &d_functions;
    
        std::vector<VarVect> d_var;         // globals are at index 0
                                            // function params are at index 1
                                            // local vars are at index >= 2

        std::vector<ExprType> d_locals;     // types of all local variables
                                            // of a function.
        
        std::string d_globalCode;           // initialization code of 
                                            // global variables

    public:
        Symtab(Functions &functions);

        void defineFunction(ExprType type, std::string const &name);

        void functionParams();          // forward the parameter-types to
                                        // d_functions, and check the
                                        // uniqueness of the parameters

        SemVal defineVar(ExprType type, std::string const &name);

                                        // 0xc000: not found
        Var const &findVar(std::string const &name) const;

        ExprType globalType(unsigned idx) const; 
        
        VarVect const &globalVars() const;  // all global vars          .f

        void push();                        // next level of variables
        void pop();                         // previous level of variables

        SemVal functionDefined(SemVal &statements);
        SemVal makeFrame() const;

        void globalCode(std::string const &code);   // add initialization 1.f
                                                    // code
        std::string const &globalCode() const;  // initialization code of 2.f
                                                // global variables
    private:
                                            // -1 if not found or the var's
                                            // in d_var.back()
        int find(VarVect const &vect, std::string const &name) const;
};

#include "globaltype.f"
#include "pop.f"
#include "push.f"
#include "globalcode1.f"
#include "globalcode2.f"
#include "globalvars.f"

#endif