📄 cp-decl2.c
字号:
/* Process declarations and variables for C compiler. Copyright (C) 1988, 1992 Free Software Foundation, Inc. Hacked by Michael Tiemann (tiemann@cygnus.com)This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING. If not, write tothe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. *//* Process declarations and symbol lookup for C front end. Also constructs types; the standard scalar types at initialization, and structure, union, array and enum types when they are declared. *//* ??? not all decl nodes are given the most useful possible line numbers. For example, the CONST_DECLs for enum values. */#include "config.h"#include <stdio.h>#include "tree.h"#include "rtl.h"#include "flags.h"#include "cp-tree.h"#include "cp-lex.h"#include "cp-decl.h"extern tree grokdeclarator ();static void grok_function_init ();/* A list of virtual function tables we must make sure to write out. */tree pending_vtables;/* A list of static class variables. This is needed, because a static class variable can be declared inside the class without an initializer, and then initialized, staticly, outside the class. */tree pending_statics;extern tree pending_addressable_inlines;/* Used to help generate temporary names which are unique within a function. Reset to 0 by start_function. */static int temp_name_counter;/* Same, but not reset. Local temp variables and global temp variables can have the same name. */static int global_temp_name_counter;/* The (assembler) name of the first globally-visible object output. */extern char * first_global_object_name;/* Flag used when debugging cp-spew.c */extern int spew_debug;/* C (and C++) language-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 the non-ANSI builtin functions. */int flag_no_builtin;/* Nonzero means do some things the same way PCC does. */int flag_traditional;/* Nonzero means to treat bitfields as unsigned unless they say `signed'. */int flag_signed_bitfields = 1;/* Nonzero means handle `#ident' directives. 0 means ignore them. */int flag_no_ident = 0;/* Nonzero means handle things in ANSI, instead of GNU fashion. This flag should be tested for language behavior that's different between ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */int flag_ansi = 0;/* Nonzero means warn about implicit declarations. */int warn_implicit = 1;/* Like `warn_return_type', but this is set by users, whereas `warn_return_type' is set by the compiler. */int explicit_warn_return_type;/* 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;/* 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 function def without prototype decl. */int warn_missing_prototypes;/* Nonzero means warn about multiple (redundant) decls for the same single variable or function. */int warn_redundant_decls;/* 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 = 1;/* Non-zero means warn in function declared in derived class has the same name as a virtual in the base class, but fails to match the type signature of any virtual function in the base class. */int warn_overloaded_virtual;/* Non-zero means warn when converting between different enumeral types. */int warn_enum_clash;/* Non-zero means warn when declaring a class that has a non virtual destructor, when it really ought to have a virtual one. */int warn_nonvdtor = 1;/* 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 1#endifint dollars_in_ident = DOLLARS_IN_IDENTIFIERS;/* Nonzero for -no-strict-prototype switch: do not consider empty argument prototype to mean function takes no arguments. */int strict_prototype = 1;int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;/* Nonzero means that labels can be used as first-class objects */int flag_labels_ok;/* Non-zero means to collect statistics which might be expensive and to print them when we are done. */int flag_detailed_statistics;/* C++ specific flags. */ /* Nonzero for -fall-virtual: make every member function (except constructors) lay down in the virtual function table. Calls can then either go through the virtual function table or not, depending. */int flag_all_virtual;/* Zero means that `this' is a *const. This gives nice behavior in the 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. -2 means we're constructing an object and it has fixed type. */int flag_this_is_variable;/* Nonzero means memoize our member lookups. */int flag_memoize_lookups; int flag_save_memoized_contexts;/* 3 means write out only virtuals function tables `defined' in this implementation file. 2 means write out only specific virtual function tables and give them (C) public visibility. 1 means write out virtual function tables and give them (C) public visibility. 0 means write out virtual function tables and give them (C) static visibility (default). -1 means declare virtual function tables extern. */int write_virtuals;/* Nonzero means we should attempt to elide constructors when possible. */int flag_elide_constructors;/* Same, but for inline functions: nonzero means write out debug info for inlines. Zero means do not. */int flag_inline_debug;/* Nonzero means recognize and handle exception handling constructs. 2 means handle exceptions the way Spring wants them handled. */int flag_handle_exceptions;/* Nonzero means recognize and handle exception handling constructs. Use ansi syntax and semantics. WORK IN PROGRESS! 2 means handle exceptions the way Spring wants them handled. */int flag_ansi_exceptions;/* Nonzero means that member functions defined in class scope are inline by default. */int flag_default_inline = 1;/* Controls whether enums and ints freely convert. 1 means with complete freedom. 0 means enums can convert to ints, but not vice-versa. */int flag_int_enum_equivalence;/* Controls whether compiler is operating under LUCID's Cadillac system. 1 means yes, 0 means no. */int flag_cadillac;/* Controls whether compiler generates code to build objects that can be collected when they become garbage. */int flag_gc;/* Controls whether compiler generates 'dossiers' that give run-time type information. */int flag_dossier;/* Nonzero if we wish to output cross-referencing information for the GNU class browser. */extern int flag_gnu_xref;/* Nonzero if compiler can make `reasonable' assumptions about references and objects. For example, the compiler must be conservative about the following and not assume that `a' is nonnull: obj &a = g (); a.f (2); In general, it is `reasonable' to assume that for many programs, and better code can be generated in that case. */int flag_assume_nonnull_objects;/* Table of language-dependent -f options. STRING is the option name. VARIABLE is the address of the variable. ON_VALUE is the value to store in VARIABLE if `-fSTRING' is seen as an option. (If `-fno-STRING' is seen as an option, the opposite value is stored.) */static struct { char *string; int *variable; int on_value;} lang_f_options[] ={ {"signed-char", &flag_signed_char, 1}, {"unsigned-char", &flag_signed_char, 0}, {"signed-bitfields", &flag_signed_bitfields, 1}, {"unsigned-bitfields", &flag_signed_bitfields, 0}, {"short-enums", &flag_short_enums, 1}, {"short-double", &flag_short_double, 1}, {"cond-mismatch", &flag_cond_mismatch, 1}, {"asm", &flag_no_asm, 0}, {"builtin", &flag_no_builtin, 0}, {"ident", &flag_no_ident, 0}, {"labels-ok", &flag_labels_ok, 1}, {"stats", &flag_detailed_statistics, 1}, {"this-is-variable", &flag_this_is_variable, 1}, {"strict-prototype", &strict_prototypes_lang_cplusplus, 1}, {"all-virtual", &flag_all_virtual, 1}, {"memoize-lookups", &flag_memoize_lookups, 1}, {"elide-constructors", &flag_elide_constructors, 1}, {"inline-debug", &flag_inline_debug, 0}, {"handle-exceptions", &flag_handle_exceptions, 1}, {"ansi-exceptions", &flag_ansi_exceptions, 1}, {"spring-exceptions", &flag_handle_exceptions, 2}, {"default-inline", &flag_default_inline, 1}, {"dollars-in-identifiers", &dollars_in_ident, 1}, {"enum-int-equiv", &flag_int_enum_equivalence, 1}, {"gc", &flag_gc, 1}, {"dossier", &flag_dossier, 1}, {"xref", &flag_gnu_xref, 1}, {"nonnull-objects", &flag_assume_nonnull_objects, 1},};/* Decode the string P as a language-specific option. Return 1 if it is recognized (and handle it); return 0 if not recognized. */int lang_decode_option (p) char *p;{ if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1, flag_this_is_variable = 1; /* The +e options are for cfront compatibility. They come in as `-+eN', to kludge around gcc.c's argument handling. */ else if (p[0] == '-' && p[1] == '+' && p[2] == 'e') { int old_write_virtuals = write_virtuals; if (p[3] == '1') write_virtuals = 1; else if (p[3] == '0') write_virtuals = -1; else if (p[3] == '2') write_virtuals = 2; else error ("invalid +e option"); if (old_write_virtuals != 0 && write_virtuals != old_write_virtuals) error ("conflicting +e options given"); } else if (p[0] == '-' && p[1] == 'f') { /* Some kind of -f option. P's value is the option sans `-f'. Search for it in the table of options. */ int found = 0, j; p += 2; /* Try special -f options. */ if (!strcmp (p, "save-memoized")) { flag_memoize_lookups = 1; flag_save_memoized_contexts = 1; found = 1; } if (!strcmp (p, "no-save-memoized")) { flag_memoize_lookups = 0; flag_save_memoized_contexts = 0; found = 1; } else if (!strcmp (p, "SOS")) { flag_all_virtual = 2; found = 1; } else if (!strcmp (p, "no-SOS")) { flag_all_virtual = 0; found = 1; } else if (! strncmp (p, "cadillac", 8)) { flag_cadillac = atoi (p+9); found = 1; } else if (! strncmp (p, "no-cadillac", 11)) { flag_cadillac = 0; found = 1; } else if (! strcmp (p, "gc")) { flag_gc = 1; /* This must come along for the ride. */ flag_dossier = 1; found = 1; } else if (! strcmp (p, "no-gc")) { flag_gc = 0; /* This must come along for the ride. */ flag_dossier = 0; found = 1; } else for (j = 0; !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]); j++) { if (!strcmp (p, lang_f_options[j].string)) { *lang_f_options[j].variable = lang_f_options[j].on_value; /* A goto here would be cleaner, but breaks the vax pcc. */ found = 1; } if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' && ! strcmp (p+3, lang_f_options[j].string)) { *lang_f_options[j].variable = ! lang_f_options[j].on_value; found = 1; } } return found; } else if (p[0] == '-' && p[1] == 'W') { int setting = 1; /* The -W options control the warning behavior of the compiler. */ p += 2; if (p[0] == 'n' && p[1] == 'o' && p[2] == '-') setting = 0, p += 3; if (!strcmp (p, "implicit")) warn_implicit = setting; else if (!strcmp (p, "return-type")) explicit_warn_return_type = setting; else if (!strcmp (p, "write-strings")) warn_write_strings = setting; else if (!strcmp (p, "cast-qual")) warn_cast_qual = setting;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -