📄 c-decl.c
字号:
tree static_ctors, static_dtors;/* Forward declarations. */static struct binding_level * make_binding_level PROTO((void));static void clear_limbo_values PROTO((tree));static int duplicate_decls PROTO((tree, tree, int));static char *redeclaration_error_message PROTO((tree, tree));static void storedecls PROTO((tree));static void storetags PROTO((tree));static tree lookup_tag PROTO((enum tree_code, tree, struct binding_level *, int));static tree lookup_tag_reverse PROTO((tree));static tree grokdeclarator PROTO((tree, tree, enum decl_context, int));static tree grokparms PROTO((tree, int));static int field_decl_cmp PROTO((const GENERIC_PTR, const GENERIC_PTR));static void layout_array_type PROTO((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 that we have builtin functions, and main is an int */int flag_hosted = 1;/* 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 handle `#ident' directives. 0 means ignore them. */int flag_no_ident = 0;/* Nonzero means warn about use of implicit int. */int warn_implicit_int;/* Nonzero means message about use of implicit function declarations; 1 means warning; 2 means error. */int mesg_implicit_function_declaration;/* 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 when casting a function call to a type that does not match the return type (e.g. (float)sqrt() or (anything*)malloc() when there is no previous declaration of sqrt or malloc. */int warn_bad_function_cast;/* Warn about traditional constructs whose meanings changed in ANSI C. */int warn_traditional;/* 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 for any global function def without separate previous decl. */int warn_missing_declarations;/* 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 *printf or *scanf format/argument anomalies. */int warn_format;/* 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;/* Warn if main is suspicious. */int warn_main;/* Warn about comparison of signed and unsigned values. If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified. */int warn_sign_compare = -1;/* Nonzero means `$' can be in an identifier. */#ifndef DOLLARS_IN_IDENTIFIERS#define DOLLARS_IN_IDENTIFIERS 1#endifint dollars_in_ident = DOLLARS_IN_IDENTIFIERS;/* Decode the string P as a language-specific option for C. Return 1 if it is recognized (and handle it); return 0 if not recognized. */ intc_decode_option (p) char *p;{ if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) { flag_traditional = 1; flag_writable_strings = 1; } else if (!strcmp (p, "-fallow-single-precision")) flag_allow_single_precision = 1; else if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding")) { flag_hosted = 1; flag_no_builtin = 0; } else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted")) { flag_hosted = 0; flag_no_builtin = 1; /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */ if (warn_main == 2) warn_main = 0; } else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional")) { flag_traditional = 0; flag_writable_strings = 0; } else if (!strcmp (p, "-fdollars-in-identifiers")) dollars_in_ident = 1; else if (!strcmp (p, "-fno-dollars-in-identifiers")) dollars_in_ident = 0; 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, "-fno-ident")) flag_no_ident = 1; else if (!strcmp (p, "-fident")) flag_no_ident = 0; else if (!strcmp (p, "-ansi")) flag_no_asm = 1, flag_no_nonansi_builtin = 1; else if (!strcmp (p, "-Werror-implicit-function-declaration")) mesg_implicit_function_declaration = 2; else if (!strcmp (p, "-Wimplicit-function-declaration")) mesg_implicit_function_declaration = 1; else if (!strcmp (p, "-Wno-implicit-function-declaration")) mesg_implicit_function_declaration = 0; else if (!strcmp (p, "-Wimplicit-int")) warn_implicit_int = 1; else if (!strcmp (p, "-Wno-implicit-int")) warn_implicit_int = 0; else if (!strcmp (p, "-Wimplicit")) { warn_implicit_int = 1; if (mesg_implicit_function_declaration != 2) mesg_implicit_function_declaration = 1; } else if (!strcmp (p, "-Wno-implicit")) warn_implicit_int = 0, mesg_implicit_function_declaration = 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, "-Wbad-function-cast")) warn_bad_function_cast = 1; else if (!strcmp (p, "-Wno-bad-function-cast")) warn_bad_function_cast = 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, "-Wmissing-declarations")) warn_missing_declarations = 1; else if (!strcmp (p, "-Wno-missing-declarations")) warn_missing_declarations = 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, "-Wtraditional")) warn_traditional = 1; else if (!strcmp (p, "-Wno-traditional")) warn_traditional = 0; else if (!strcmp (p, "-Wformat")) warn_format = 1; else if (!strcmp (p, "-Wno-format")) warn_format = 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, "-Wundef")) ; /* cpp handles this one. */ else if (!strcmp (p, "-Wno-undef")) ; /* 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, "-Wmain")) warn_main = 1; else if (!strcmp (p, "-Wno-main")) warn_main = 0; else if (!strcmp (p, "-Wsign-compare")) warn_sign_compare = 1; else if (!strcmp (p, "-Wno-sign-compare")) warn_sign_compare = 0; else if (!strcmp (p, "-Wall")) { /* 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_int = 1; mesg_implicit_function_declaration = 1; warn_return_type = 1; warn_unused = 1; warn_switch = 1; warn_format = 1; warn_char_subscripts = 1; warn_parentheses = 1; warn_missing_braces = 1; /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn it off only if it's not explicit. */ warn_main = 2; } else return 0; return 1;}/* Hooks for print_node. */voidprint_lang_decl (file, node, indent) FILE *file; tree node; int indent;{}voidprint_lang_type (file, node, indent) FILE *file; tree node; int indent;{}voidprint_lang_identifier (file, node, indent) FILE *file; tree node; int indent;{ print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -