jackc/compiler/compiler-scopes.h

59 lines
1.2 KiB
C
Raw Normal View History

2021-01-04 15:00:48 -05:00
#ifndef COMPILER_SCOPES_H
#define COMPILER_SCOPES_H
#include "parser-tree.h"
#include "compiler.h"
/* 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 var {
DEBUGINFO* debug;
char* memsegment;
char* type;
char* name;
int index;
bool primitive;
struct var* next;
} VAR;
typedef struct scope {
struct compiler* compiler;
CLASS* currclass;
CLASS* classes;
SUBROUTDEC* subroutines;
VAR* fields;
VAR* staticvars;
VAR* localvars;
VAR* parameters;
struct scope* previous;
} SCOPE;
struct compiler;
// Group adding
void addclassvardecs(SCOPE* s, CLASSVARDEC* classvardecs);
void addlocalvars(SCOPE* s, VARDEC* localvars);
void addparameters(SCOPE* s, bool isformethod, PARAMETER* params);
// Scope handling
SCOPE* mkscope(SCOPE* prev);
// Single type getters
SUBROUTDEC* getsubroutdecfromcall(SCOPE* s, SUBROUTCALL* call, VAR** varret);
CLASS* getclass(SCOPE* s, const char* name);
// Generic getters
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-04 15:00:48 -05:00
// Freeing
void freescope(SCOPE* s);
#endif