29 lines
671 B
C
29 lines
671 B
C
#ifndef SCOPE_H
|
||
#define SCOPE_H
|
||
|
||
#include "hashmap.h"
|
||
|
||
struct Scope {
|
||
HashMap symbols; // 当前作用域符号表
|
||
struct Scope* parent; // 上层作用域
|
||
int base_offset;
|
||
int cur_offset;
|
||
};
|
||
|
||
// 创建新作用域(父作用域可为NULL)
|
||
struct Scope* scope_create(struct Scope* parent);
|
||
|
||
// 销毁作用域
|
||
void scope_destroy(struct Scope* scope);
|
||
|
||
// 在当前作用域插入符号
|
||
void scope_insert(struct Scope* scope, const char* name, void* symbol);
|
||
|
||
// 逐级查找符号
|
||
void* scope_lookup(struct Scope* scope, const char* name);
|
||
|
||
// 仅在当前作用域查找
|
||
void* scope_lookup_current(struct Scope* scope, const char* name);
|
||
|
||
#endif
|