📄 expression.h
字号:
#ifndef EXPRESSION_H#define EXPRESSION_Htypedef struct expression Expression;#include "bool.h"#include "list.h"#include "scope.h"#include "token.h"#include "type.h"typedef enum{ expr_and, expr_bool_const, expr_char_const, expr_div, expr_eq, expr_func_call, expr_ge, expr_gt, expr_ident, expr_index, expr_int_const, expr_min, expr_mul, expr_ne, expr_new, expr_not, expr_null, expr_or, expr_plus, expr_real_const, expr_se, expr_size, expr_st, expr_string_const, expr_unary_min, expr_unary_plus, expr_dot expr_record /* add a new record type of an expression*/ }Expr_subtype;/* Expressions are stored in 'Expression'-type structures. The subtype * field indicates the type of the expression (listed in Expr_subtype). * Depending on this type, the union un may contain fields specific to * function call, indentifier, or string constant expressions. These * should be accessed using the EXPR_FUNC_CALL, EXPR_IDENT, * EXPR_STRING_CONSTANT defines! For most expressions all necessary data * is stored in the two operand fields, which point to other expressions. * For example, '3+4' would be represented as an expression of type * expr_plus, with operand[0] and operand[1] pointing to two expressions * of type expr_int_const. */struct expression{ int number; int struct_equal; Expr_subtype subtype; Token *token; Expression *operand [2]; Type *type; union { struct { List *formal_args; /* List<Declaration *> */ List *actual_args; /* List<Expression *> */ } func_call; struct { Scope *scope; } identifier; struct { unsigned index; } string_const; } un;};#define EXPR_FUNC_CALL(e) ((e)->un.func_call)#define EXPR_IDENT(e) ((e)->un.identifier)#define EXPR_STRING_CONST(e) ((e)->un.string_const)Expression *new_expression(Expr_subtype, Token *, Expression *left, Expression *right);void delete_expression(Expression *);Type *type_check_expression(Expression *);Bool is_lvalue_(Expression *, char **);#define is_lvalue(e) is_lvalue_((e), NULL)void generate_expression(Expression *);Scope *bepaal_scope(Expression *expr, Bool isrvalue);Token *bepaal_token(Expression *expr, Bool isrvalue);/* During type checking, all string constants are listed in 'string_list'. * At code generation time, this list is converted to a C as an array of * strings. */void generate_string_list(void);extern List *string_list;extern int global_equal;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -