diff options
Diffstat (limited to 'gcc/tree.h')
-rw-r--r-- | gcc/tree.h | 131 |
1 files changed, 99 insertions, 32 deletions
@@ -43,25 +43,103 @@ enum tree_code { /* Number of language-independent tree codes. */ #define NUM_TREE_CODES ((int) LAST_AND_UNUSED_TREE_CODE) -/* Indexed by enum tree_code, contains a character which is - `<' for a comparison expression, `1', for a unary arithmetic - expression, `2' for a binary arithmetic expression, `e' for - other types of expressions, `r' for a reference, `c' for a - constant, `d' for a decl, `t' for a type, `s' for a statement, - and `x' for anything else (TREE_LIST, IDENTIFIER, etc). */ +/* Tree code classes. */ + +/* Each tree_code has an associated code class represented by a + TREE_CODE_CLASS. */ + +enum tree_code_class { + tcc_exceptional, /* An exceptional code (fits no category). */ + tcc_constant, /* A constant. */ + tcc_type, /* A type object code. */ + tcc_declaration, /* A declaration (also serving as variable refs). */ + tcc_reference, /* A reference to storage. */ + tcc_comparison, /* A comparison expression. */ + tcc_unary, /* A unary arithmetic expression. */ + tcc_binary, /* A binary arithmetic expression. */ + tcc_statement, /* A statement expression, which have side effects + but usually no interesting value. */ + tcc_expression /* Any other expression. */ +}; + +/* Each tree code class has an associated string representation. + These must correspond to the tree_code_class entries. */ + +extern const char* tree_code_class_strings[]; + +/* Returns the string representing CLASS. */ + +#define TREE_CODE_CLASS_STRING(CLASS)\ + tree_code_class_strings[(int) (CLASS)] #define MAX_TREE_CODES 256 -extern const char tree_code_type[]; +extern const enum tree_code_class tree_code_type[]; #define TREE_CODE_CLASS(CODE) tree_code_type[(int) (CODE)] +/* Nonzero if CODE represents an exceptional code. */ + +#define EXCEPTIONAL_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_exceptional) + +/* Nonzero if CODE represents a constant. */ + +#define CONSTANT_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_constant) + +/* Nonzero if CODE represents a type. */ + +#define TYPE_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_type) + +/* Nonzero if CODE represents a declaration. */ + +#define DECL_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_declaration) + +/* Nonzero if CODE represents a reference. */ + +#define REFERENCE_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_reference) + +/* Nonzero if CODE represents a comparison. */ + +#define COMPARISON_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_comparison) + +/* Nonzero if CODE represents a unary arithmetic expression. */ + +#define UNARY_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_unary) + +/* Nonzero if CODE represents a binary arithmetic expression. */ + +#define BINARY_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_binary) + +/* Nonzero if CODE represents a statement expression. */ + +#define STATEMENT_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_statement) + +/* Nonzero if CODE represents any other expression. */ + +#define EXPRESSION_CLASS_P(CODE)\ + (TREE_CODE_CLASS (TREE_CODE (CODE)) == tcc_expression) + /* Returns nonzero iff CLASS is not the tree code of a type. */ -#define IS_NON_TYPE_CODE_CLASS(CLASS) ((CLASS) != 't') +#define IS_NON_TYPE_CODE_CLASS(CLASS) ((CLASS) != tcc_type) + +/* Returns nonzero iff CODE represents a type or declaration. */ + +#define IS_TYPE_OR_DECL_P(CODE)\ + (TYPE_P (CODE) || DECL_P (CODE)) /* Returns nonzero iff CLASS is the tree-code class of an expression. */ -#define IS_EXPR_CODE_CLASS(CLASS) (strchr ("<12ers", (CLASS)) != 0) +#define IS_EXPR_CODE_CLASS(CLASS)\ + (((CLASS) >= tcc_reference) && ((CLASS) <= tcc_expression)) /* Returns nonzero iff NODE is an expression of some kind. */ @@ -448,7 +526,7 @@ struct tree_common GTY(()) ({ const tree __t = (T); \ char const __c = TREE_CODE_CLASS (TREE_CODE (__t)); \ if (!IS_EXPR_CODE_CLASS (__c)) \ - tree_class_check_failed (__t, 'E', __FILE__, __LINE__, \ + tree_class_check_failed (__t, tcc_expression, __FILE__, __LINE__, \ __FUNCTION__); \ __t; }) @@ -457,7 +535,7 @@ struct tree_common GTY(()) ({ const tree __t = (T); \ char const __c = TREE_CODE_CLASS (TREE_CODE (__t)); \ if (!IS_NON_TYPE_CODE_CLASS (__c)) \ - tree_class_check_failed (__t, 'T', __FILE__, __LINE__, \ + tree_class_check_failed (__t, tcc_type, __FILE__, __LINE__, \ __FUNCTION__); \ __t; }) @@ -517,7 +595,7 @@ extern void tree_check_failed (const tree, const char *, int, const char *, ...) ATTRIBUTE_NORETURN; extern void tree_not_check_failed (const tree, const char *, int, const char *, ...) ATTRIBUTE_NORETURN; -extern void tree_class_check_failed (const tree, int, +extern void tree_class_check_failed (const tree, const enum tree_code_class, const char *, int, const char *) ATTRIBUTE_NORETURN; extern void tree_vec_elt_check_failed (int, int, const char *, @@ -557,10 +635,10 @@ extern void tree_operand_check_failed (int, enum tree_code, #include "tree-check.h" -#define TYPE_CHECK(T) TREE_CLASS_CHECK (T, 't') -#define DECL_CHECK(T) TREE_CLASS_CHECK (T, 'd') -#define CST_CHECK(T) TREE_CLASS_CHECK (T, 'c') -#define STMT_CHECK(T) TREE_CLASS_CHECK (T, 's') +#define TYPE_CHECK(T) TREE_CLASS_CHECK (T, tcc_type) +#define DECL_CHECK(T) TREE_CLASS_CHECK (T, tcc_declaration) +#define CST_CHECK(T) TREE_CLASS_CHECK (T, tcc_constant) +#define STMT_CHECK(T) TREE_CLASS_CHECK (T, tcc_statement) #define FUNC_OR_METHOD_CHECK(T) TREE_CHECK2 (T, FUNCTION_TYPE, METHOD_TYPE) #define PTR_OR_REF_CHECK(T) TREE_CHECK2 (T, POINTER_TYPE, REFERENCE_TYPE) @@ -712,9 +790,6 @@ extern void tree_operand_check_failed (int, enum tree_code, #define COMPLETE_OR_UNBOUND_ARRAY_TYPE_P(NODE) \ (COMPLETE_TYPE_P (TREE_CODE (NODE) == ARRAY_TYPE ? TREE_TYPE (NODE) : (NODE))) -/* Nonzero if TYPE represents a type. */ - -#define TYPE_P(TYPE) (TREE_CODE_CLASS (TREE_CODE (TYPE)) == 't') /* Define many boolean fields that all tree nodes have. */ @@ -839,7 +914,8 @@ extern void tree_operand_check_failed (int, enum tree_code, #define TREE_READONLY(NODE) (NON_TYPE_CHECK (NODE)->common.readonly_flag) /* Nonzero if NODE is a _DECL with TREE_READONLY set. */ -#define TREE_READONLY_DECL_P(NODE) (DECL_P (NODE) && TREE_READONLY (NODE)) +#define TREE_READONLY_DECL_P(NODE)\ + (DECL_P (NODE) && TREE_READONLY (NODE)) /* Value of expression is constant. Always on in all ..._CST nodes. May also appear in an expression or decl where the value is constant. */ @@ -1091,17 +1167,13 @@ struct tree_vec GTY(()) decls and constants can be shared among multiple locations, so return nothing. */ #define EXPR_LOCATION(NODE) \ - (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE))) \ - ? (NODE)->exp.locus \ - : UNKNOWN_LOCATION) + (EXPR_P (NODE) ? (NODE)->exp.locus : UNKNOWN_LOCATION) #define SET_EXPR_LOCATION(NODE, FROM) \ (EXPR_CHECK (NODE)->exp.locus = (FROM)) #define EXPR_HAS_LOCATION(NODE) (EXPR_LOCATION (NODE) != UNKNOWN_LOCATION) /* EXPR_LOCUS and SET_EXPR_LOCUS are deprecated. */ #define EXPR_LOCUS(NODE) \ - (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE))) \ - ? &(NODE)->exp.locus \ - : (location_t *)NULL) + (EXPR_P (NODE) ? &(NODE)->exp.locus : (location_t *)NULL) #define SET_EXPR_LOCUS(NODE, FROM) \ do { source_location *loc_tmp = FROM; \ EXPR_CHECK (NODE)->exp.locus \ @@ -1115,9 +1187,7 @@ struct tree_vec GTY(()) decls and constants can be shared among multiple locations, so return nothing. */ #define EXPR_LOCUS(NODE) \ - (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (NODE))) \ - ? (NODE)->exp.locus \ - : (location_t *)NULL) + (EXPR_P (NODE) ? (NODE)->exp.locus : (location_t *)NULL) #define SET_EXPR_LOCUS(NODE, FROM) \ (EXPR_CHECK (NODE)->exp.locus = (FROM)) #define SET_EXPR_LOCATION(NODE, FROM) annotate_with_locus (NODE, FROM) @@ -1753,9 +1823,6 @@ struct tree_binfo GTY (()) /* Define fields and accessors for nodes representing declared names. */ -/* Nonzero if DECL represents a decl. */ -#define DECL_P(DECL) (TREE_CODE_CLASS (TREE_CODE (DECL)) == 'd') - /* Nonzero if DECL represents a variable for the SSA passes. */ #define SSA_VAR_P(DECL) \ (TREE_CODE (DECL) == VAR_DECL \ |