📄 decl.c
字号:
/* These are irrelevant for Chill, but are referenced from from c-typeck.c. */int warn_format;int warn_traditional;int warn_bad_function_cast;/* Identifiers that hold VAR_LENGTH and VAR_DATA. */tree var_length_id, var_data_id;tree case_else_node;/* For each binding contour we allocate a scope structure * which records the names defined in that contour. * Contours include: * 0) the global one * 1) one for each function definition, * where internal declarations of the parameters appear. * 2) one for each compound statement, * to record its declarations. * * The current meaning of a name can be found by searching the levels from * the current one out to the global one. *//* To communicate between pass 1 and 2, we maintain a list of "scopes". Each scope corrresponds to a nested source scope/block that contain that can contain declarations. The TREE_VALUE of the scope points to the list of declarations declared in that scope. The TREE_PURPOSE of the scope points to the surrounding scope. (We may need to handle nested modules later. FIXME) The TREE_CHAIN field contains a list of scope as they are seen in chronological order. (Reverse order during first pass, but it is reverse before pass 2.) */struct scope{ /* The enclosing scope. */ struct scope *enclosing; /* The next scope, in chronlogical order. */ struct scope *next; /* A chain of DECLs constructed using save_decl during pass 1. */ tree remembered_decls; /* A chain of _DECL nodes for all variables, constants, functions, and typedef types belong to this scope. */ tree decls; /* List of declarations that have been granted into this scope. */ tree granted_decls; /* List of implied (weak) names. */ tree weak_decls; /* For each level, a list of shadowed outer-level local definitions to be restored when this level is popped. Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ tree shadowed; /* For each level (except not the global one), a chain of BLOCK nodes for all the levels that were entered and exited one level down. */ tree blocks; /* The BLOCK node for this level, if one has been preallocated. If 0, the BLOCK is allocated (if needed) when the level is popped. */ tree this_block; /* The binding level which this one is contained in (inherits from). */ struct scope *level_chain; /* Nonzero for a level that corresponds to a module. */ char module_flag; /* Zero means called from backend code. */ char two_pass; /* The modules that are directly enclosed by this scope are chained together. */ struct scope* first_child_module; struct scope** tail_child_module; struct scope* next_sibling_module;};/* The outermost binding level, for pre-defined (builtin) names. */static struct scope builtin_scope = { NULL, NULL, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL, 0, 0, NULL, NULL, NULL};struct scope *global_scope;/* The binding level currently in effect. */static struct scope *current_scope = &builtin_scope;/* The most recently seen scope. */struct scope *last_scope = &builtin_scope;/* Binding level structures are initialized by copying this one. */static struct scope clear_scope = { NULL, NULL, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL, 0, 0, NULL, NULL, NULL};/* Chain of decls accessible through IDENTIFIER_OUTER_VALUE. Decls with the same DECL_NAME are adjacent in the chain. */static tree outer_decls = NULL_TREE;/* C-specific option variables. *//* Nonzero means allow type mismatches in conditional expressions; just make their values `void'. */int flag_cond_mismatch;/* Nonzero means give `double' the same size as `float'. */int flag_short_double;/* Nonzero means don't recognize the keyword `asm'. */int flag_no_asm;/* Nonzero means don't recognize any builtin functions. */int flag_no_builtin;/* Nonzero means don't recognize the non-ANSI builtin functions. -ansi sets this. */int flag_no_nonansi_builtin;/* Nonzero means do some things the same way PCC does. */int flag_traditional;/* Nonzero means to allow single precision math even if we're generally being traditional. */int flag_allow_single_precision = 0;/* Nonzero means to treat bitfields as signed unless they say `unsigned'. */int flag_signed_bitfields = 1;int explicit_flag_signed_bitfields = 0;/* Nonzero means warn about implicit declarations. */int warn_implicit;/* Nonzero means give string constants the type `const char *' to get extra warnings from them. These warnings will be too numerous to be useful, except in thoroughly ANSIfied programs. */int warn_write_strings;/* Nonzero means warn about pointer casts that can drop a type qualifier from the pointer target type. */int warn_cast_qual;/* Nonzero means warn about sizeof(function) or addition/subtraction of function pointers. */int warn_pointer_arith;/* Nonzero means warn for non-prototype function decls or non-prototyped defs without previous prototype. */int warn_strict_prototypes;/* Nonzero means warn for any global function def without separate previous prototype decl. */int warn_missing_prototypes;/* Nonzero means warn about multiple (redundant) decls for the same single variable or function. */int warn_redundant_decls = 0;/* Nonzero means warn about extern declarations of objects not at file-scope level and about *all* declarations of functions (whether extern or static) not at file-scope level. Note that we exclude implicit function declarations. To get warnings about those, use -Wimplicit. */int warn_nested_externs = 0;/* Warn about a subscript that has type char. */int warn_char_subscripts = 0;/* Warn if a type conversion is done that might have confusing results. */int warn_conversion;/* Warn if adding () is suggested. */int warn_parentheses;/* Warn if initializer is not completely bracketed. */int warn_missing_braces;/* Define the special tree codes that we use. *//* Table indexed by tree code giving a string containing a character classifying the tree code. Possibilities are t, d, s, c, r, <, 1 and 2. See ch-tree.def for details. */#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, char chill_tree_code_type[] = { 'x',#include "ch-tree.def" };#undef DEFTREECODE/* Table indexed by tree code giving number of expression operands beyond the fixed part of the node structure. Not used for types or decls. */#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, int chill_tree_code_length[] = { 0,#include "ch-tree.def" };#undef DEFTREECODE/* Names of tree components. Used for printing out the tree and error messages. */#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, char *chill_tree_code_name[] = { "@@dummy",#include "ch-tree.def" };#undef DEFTREECODE/* Nonzero means `$' can be in an identifier. See cccp.c for reasons why this breaks some obscure ANSI C programs. */#ifndef DOLLARS_IN_IDENTIFIERS#define DOLLARS_IN_IDENTIFIERS 0#endifint dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1;/* An identifier that is used internally to indicate an "ALL" prefix for granting or seizing. We use "*" rather than the external name "ALL", partly for convenience, and partly to avoid case senstivity problems. */tree ALL_POSTFIX;voidallocate_lang_decl (t) tree t ATTRIBUTE_UNUSED;{ /* Nothing needed */}voidcopy_lang_decl (node) tree node ATTRIBUTE_UNUSED;{ /* Nothing needed */}treebuild_lang_decl (code, name, type) enum chill_tree_code code; tree name; tree type;{ return build_decl (code, name, type);}/* Decode the string P as a language-specific option for C. Return the number of strings consumed for a valid option. Return 0 for an invalid option. */intc_decode_option (argc, argv) int argc ATTRIBUTE_UNUSED; char **argv;{ char *p = argv[0]; if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) { flag_traditional = 1; flag_writable_strings = 1;#if DOLLARS_IN_IDENTIFIERS > 0 dollars_in_ident = 1;#endif } else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional")) { flag_traditional = 0; flag_writable_strings = 0; dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1; } else if (!strcmp (p, "-fsigned-char")) flag_signed_char = 1; else if (!strcmp (p, "-funsigned-char")) flag_signed_char = 0; else if (!strcmp (p, "-fno-signed-char")) flag_signed_char = 0; else if (!strcmp (p, "-fno-unsigned-char")) flag_signed_char = 1; else if (!strcmp (p, "-fsigned-bitfields") || !strcmp (p, "-fno-unsigned-bitfields")) { flag_signed_bitfields = 1; explicit_flag_signed_bitfields = 1; } else if (!strcmp (p, "-funsigned-bitfields") || !strcmp (p, "-fno-signed-bitfields")) { flag_signed_bitfields = 0; explicit_flag_signed_bitfields = 1; } else if (!strcmp (p, "-fshort-enums")) flag_short_enums = 1; else if (!strcmp (p, "-fno-short-enums")) flag_short_enums = 0; else if (!strcmp (p, "-fcond-mismatch")) flag_cond_mismatch = 1; else if (!strcmp (p, "-fno-cond-mismatch")) flag_cond_mismatch = 0; else if (!strcmp (p, "-fshort-double")) flag_short_double = 1; else if (!strcmp (p, "-fno-short-double")) flag_short_double = 0; else if (!strcmp (p, "-fasm")) flag_no_asm = 0; else if (!strcmp (p, "-fno-asm")) flag_no_asm = 1; else if (!strcmp (p, "-fbuiltin")) flag_no_builtin = 0; else if (!strcmp (p, "-fno-builtin")) flag_no_builtin = 1; else if (!strcmp (p, "-ansi")) flag_no_asm = 1, flag_no_nonansi_builtin = 1, dollars_in_ident = 0; else if (!strcmp (p, "-Wimplicit")) warn_implicit = 1; else if (!strcmp (p, "-Wno-implicit")) warn_implicit = 0; else if (!strcmp (p, "-Wwrite-strings")) warn_write_strings = 1; else if (!strcmp (p, "-Wno-write-strings")) warn_write_strings = 0; else if (!strcmp (p, "-Wcast-qual")) warn_cast_qual = 1; else if (!strcmp (p, "-Wno-cast-qual")) warn_cast_qual = 0; else if (!strcmp (p, "-Wpointer-arith")) warn_pointer_arith = 1; else if (!strcmp (p, "-Wno-pointer-arith")) warn_pointer_arith = 0; else if (!strcmp (p, "-Wstrict-prototypes")) warn_strict_prototypes = 1; else if (!strcmp (p, "-Wno-strict-prototypes")) warn_strict_prototypes = 0; else if (!strcmp (p, "-Wmissing-prototypes")) warn_missing_prototypes = 1; else if (!strcmp (p, "-Wno-missing-prototypes")) warn_missing_prototypes = 0; else if (!strcmp (p, "-Wredundant-decls")) warn_redundant_decls = 1; else if (!strcmp (p, "-Wno-redundant-decls")) warn_redundant_decls = 0; else if (!strcmp (p, "-Wnested-externs")) warn_nested_externs = 1; else if (!strcmp (p, "-Wno-nested-externs")) warn_nested_externs = 0; else if (!strcmp (p, "-Wchar-subscripts")) warn_char_subscripts = 1; else if (!strcmp (p, "-Wno-char-subscripts")) warn_char_subscripts = 0; else if (!strcmp (p, "-Wconversion")) warn_conversion = 1; else if (!strcmp (p, "-Wno-conversion")) warn_conversion = 0; else if (!strcmp (p, "-Wparentheses")) warn_parentheses = 1; else if (!strcmp (p, "-Wno-parentheses")) warn_parentheses = 0; else if (!strcmp (p, "-Wreturn-type")) warn_return_type = 1; else if (!strcmp (p, "-Wno-return-type")) warn_return_type = 0; else if (!strcmp (p, "-Wcomment")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wno-comment")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wcomments")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wno-comments")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wtrigraphs")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wno-trigraphs")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wimport")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wno-import")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wmissing-braces")) warn_missing_braces = 1; else if (!strcmp (p, "-Wno-missing-braces")) warn_missing_braces = 0; else if (!strcmp (p, "-Wall")) { extra_warnings = 1; /* We save the value of warn_uninitialized, since if they put -Wuninitialized on the command line, we need to generate a warning about not using it without also specifying -O. */ if (warn_uninitialized != 1) warn_uninitialized = 2; warn_implicit = 1; warn_return_type = 1; warn_unused = 1; warn_char_subscripts = 1; warn_parentheses = 1; warn_missing_braces = 1; } else return 0; return 1;}/* Hooks for print_node. */voidprint_lang_decl (file, node, indent) FILE *file; tree node; int indent;{ indent_to (file, indent + 3); fputs ("nesting_level ", file); fprintf (file, HOST_WIDE_INT_PRINT_DEC, DECL_NESTING_LEVEL (node));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -