jack-compiler/compiler/compiler-scopes.h

53 lines
1.1 KiB
C
Raw Normal View History

2020-12-21 13:05:49 -05:00
#ifndef COMPILER_SCOPES_H
#define COMPILER_SCOPES_H
2020-12-21 19:56:59 -05:00
#include "parser-tree.h"
2020-12-21 13:05:49 -05:00
/* compiler-scopes
* Tools for dealing with scopes.
*
* They can be used to create, expand and stack scopes, as well as to enforce
* certain semantic rules. */
// Data types
typedef struct scope {
2020-12-21 18:35:41 -05:00
SUBROUTDEC* subroutines;
2020-12-21 13:05:49 -05:00
CLASSVARDEC* classvardecs;
VARDEC* vardecs;
CLASS* classes;
2020-12-22 13:45:12 -05:00
int condlabelcount;
2020-12-21 13:05:49 -05:00
struct scope* previous;
} SCOPE;
typedef enum {
2020-12-21 18:35:41 -05:00
subroutdec, classvardec, vardec, class
2020-12-21 13:05:49 -05:00
} OBJTYPE;
typedef struct object {
OBJTYPE type;
union {
2020-12-21 18:35:41 -05:00
SUBROUTDEC* subroutdec;
2020-12-21 13:05:49 -05:00
CLASSVARDEC* classvardec;
VARDEC* vardec;
CLASS* class;
};
DEBUGINFO* (*getdebug)(struct object*);
} OBJ;
// Group adding
void addclassvardecs(SCOPE* s, CLASSVARDEC* vs);
void addvardecs(SCOPE* s, VARDEC* vs);
2020-12-21 18:35:41 -05:00
void addsubroutdecs(SCOPE* s, SUBROUTDEC* ss);
2020-12-21 13:05:49 -05:00
void addclasses(SCOPE* s, CLASS* c);
// Scope handling
SCOPE* mkscope(SCOPE* prev);
// Single type getters
2020-12-21 19:50:55 -05:00
SUBROUTDEC* getsubroutdec(SCOPE* s, const char* name);
2020-12-21 18:35:41 -05:00
SUBROUTDEC* getsubroutdecfromcall(SCOPE* s, SUBROUTCALL* call);
2020-12-21 19:50:55 -05:00
CLASS* getclass(SCOPE* s, const char* name);
2020-12-21 13:05:49 -05:00
// Generic getters
2020-12-21 19:50:55 -05:00
OBJ* getbyname(SCOPE* s, const char* name);
2020-12-21 13:05:49 -05:00
#endif