jack-compiler/compiler/compiler-scopes.h

52 lines
1.0 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
2020-12-27 16:52:28 -05:00
typedef struct var {
2020-12-24 14:22:22 -05:00
DEBUGINFO* debug;
2020-12-27 16:52:28 -05:00
char* memsegment;
char* type;
char* name;
int index;
bool primitive;
struct var* next;
} VAR;
2020-12-21 13:05:49 -05:00
2020-12-24 14:22:22 -05:00
typedef struct scope {
2020-12-27 16:52:28 -05:00
DEBUGINFO* currdebug;
CLASS* currclass;
CLASS* classes;
SUBROUTDEC* subroutines;
VAR* fields;
VAR* staticvars;
VAR* localvars;
VAR* parameters;
2020-12-24 14:22:22 -05:00
struct scope* previous;
} SCOPE;
2020-12-21 13:05:49 -05:00
// Group adding
2020-12-27 16:52:28 -05:00
void addclassvardecs(SCOPE* s, CLASSVARDEC* classvardecs);
void addlocalvars(SCOPE* s, VARDEC* localvars);
void addparameters(SCOPE* s, PARAMETER* params);
2020-12-21 13:05:49 -05:00
// Scope handling
SCOPE* mkscope(SCOPE* prev);
// Single type getters
SUBROUTDEC* getsubroutdecfromcall(SCOPE* s, SUBROUTCALL* call, VAR** varret);
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-27 16:52:28 -05:00
VAR* getvar(SCOPE* s, const char* name);
2020-12-21 13:05:49 -05:00
#endif