📄 declaration.h
字号:
#ifndef DECLARATION_H#define DECLARATION_Htypedef struct declaration Declaration;#include "bool.h"#include "list.h"#include "scope.h"#include "statement.h"#include "token.h"#include "type.h"typedef enum{ subprog_decl, var_decl, record_decl}Decl_subtype;/* Declarations are stored in 'Declaration'-type structures. The * subtype field indicates whether the declaration is a subprogram or * a variable. Depending on the type, the union un contains fields * specific to variables or subprogrammes. These should be accessed * using the VAR_DECL and SUBPROG_DECL defines! */struct declaration{ Decl_subtype subtype; Token *token; union { struct subprog_decl { Statement *body; Scope *formal_args_scope; List *formal_args; Type *type; Type *return_type; /* void_type if procedure */ Declaration *redeclaration; Bool has_been_defined; int offset; } subprog_decl; struct { Type *type; int offset; } var_decl; struct { Scope *member_scope; List *var_list; Type *type; int offset; } record_decl; } un;};#define SUBPROG_DECL(d) ((d)->un.subprog_decl)#define VAR_DECL(d) ((d)->un.var_decl)#define RECORD_DECL(d) ((d)->un.record_decl)/* The global_declarations pointer is used to store the AST; it is a list * containing Declaration structures. It is set by the start rule 'program' in * the yacc specification (grammar.y). */extern List *global_declarations;Declaration *new_subprogram_declaration(Token *);Declaration *new_var_declaration(Token *);Declaration *new_record_declaration(Token *, List *);void delete_declaration(Declaration *);void delete_declaration_list(List *);void bepaal_offset(Declaration *decl);void arguments_offset(Expression *expr);void type_check_declaration(Declaration *);void arguments_on_stack(Declaration *decl, int offset); /* Calling type_check_declaration_list(global_declarations) * is the start of the type checking phase. It recursively * type checks all the nodes in the AST. When this function * returns, the type checking phase has completed */void type_check_declaration_list(List *);void generate_declaration(Declaration *); /* Calling generate_declaration_list(global_declarations) * is the start of the code generation phase. It generates * code for every node in the AST by (recursively) calling * other generate_ functions. When this function returns, * all code is generated, except for the string constant * list, which is generated seperately. */void generate_declaration_list(List *);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -