⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 declaration.h

📁 一个编译器修改的例子
💻 H
字号:
#ifndef DECLARATION_H#define DECLARATION_Htypedef struct declaration Declaration;#include <assert.h>#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 /*add : create a new declaration subtype*/}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;	}	subprog_decl;	struct	{	    Type	*type;	}	var_decl;      /*add*/      struct      {        List  *formal_var; /* containing list of members of a record */        Scope *formal_var_scope; /* scope of a record */      }      record_decl;    }    un;};/* Enforce that declaration d is of subtype st. The result is again d. To * prevent double evaluation of the macro argument, the argument is temporarily * stored in the __decl variable. */#define ASSERT_DECL_SUBTYPE(d,st) (__decl = (d), assert(__decl->subtype == st), __decl)extern Declaration *__decl;/* Macros for less verbose access to the members of the structs within * the union. These macros also check that they are applied to appropriate * instances of the Declaration struct. * * In essence, these macros perform (d)->un.xxx */#define SUBPROG_DECL(d)	\	(ASSERT_DECL_SUBTYPE(d, subprog_decl)->un.subprog_decl)#define VAR_DECL(d)	\	(ASSERT_DECL_SUBTYPE(d, var_decl)->un.var_decl)/*add : new marco to access to struct record_decl */#define RECORD_DECL(d)	\	(ASSERT_DECL_SUBTYPE(d, record_decl)->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 *); /* add : creating a new record declaration */void	    delete_declaration(Declaration *);void	    delete_declaration_list(List *);void	    type_check_declaration(Declaration *);		/* 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 + -