jack-compiler/compiler/compiler-scopes.h

59 lines
1.2 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-31 11:39:07 -05:00
#include "compiler.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 {
2021-01-03 14:08:54 -05:00
struct compiler* compiler;
2020-12-27 16:52:28 -05:00
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-31 11:39:07 -05:00
struct compiler;
2020-12-21 13:05:49 -05:00
// Group adding
2021-01-03 14:08:54 -05:00
void addclassvardecs(SCOPE* s, CLASSVARDEC* classvardecs);
2020-12-27 16:52:28 -05:00
void addlocalvars(SCOPE* s, VARDEC* localvars);
2020-12-31 15:38:41 -05:00
void addparameters(SCOPE* s, bool isformethod, 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);
2021-01-06 19:18:52 -05:00
VAR* getvarmustexist(SCOPE* s, DEBUGINFO* d, const char* name);
2021-01-03 14:08:54 -05:00
// Freeing
void freescope(SCOPE* s);
2020-12-21 13:05:49 -05:00
#endif