📄 type.h
字号:
#ifndef TYPE_H#define TYPE_Htypedef struct type Type;#include "bool.h"#include "expression.h"#include "io.h"typedef enum{ bool_type = 1, char_type = 2, int_type = 4, real_type = 8, subprog_type = 16, array_type = 32, null_type = 64, void_type = 128, record_type = 256 /* add new record type */}Type_subtype; /* Only one of these types is selected. * The reason for using seperate bits for the types is that it makes * checking whether a type is, for instance, a scalar type easier. */#define any_type (~0)#define scalar_type (char_type | int_type | real_type)#define arithmetic_type (int_type | real_type)#define reference_type (array_type | null_type)#define basic_or_ref_type (~(subprog_type | void_type))/* Types are stored in 'Type' structures. The subtype field * indicates what sort of type it is (see Type_subtype). * Depending on sub_type, the union un may contain fields specific for * array or subprogram types. * These should be accessed using the ARRAY_TYPE and SUBPROG_TYPE defines! */struct type{ Type_subtype subtype; unsigned ref_count; Bool call_by_ref; union { struct { Type *base_type; } array_type; struct { Declaration *decl; /* arg types and return type can be found here */ } subprog_type; struct { Declaration *decl; /* add record declaration and members of record can be found here */ } record_type; } un;};#define ARRAY_TYPE(t) ((t)->un.array_type)#define SUBPROG_TYPE(t) ((t)->un.subprog_type)#define RECORD_TYPE(t) ((t)->un.record_type) /*add new macro of record type to access to struct record_type */Type *new_simple_type(Type_subtype);Type *new_array_type(Type *base_type);Type *new_null_type();Type *new_subprog_type(Declaration *decl);Type *new_record_type(Declaration *decl); /*add new function for record type *//* Because multiple nodes in the AST may point to the same type structure * (in constrast to statements, declarations, etc which always have a single * parent), we keep a reference count which is increased whenever a reference * to that type is made in the AST. * This allows us to delay deleting the type until the last node in the AST that * references to it is also deleted. */void inc_ref_count(Type *, int n);void delete_type(Type *);Bool types_compatible(const Type *to, const Type *from);void generate_type(FILE *, Type *);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -