⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-decl.c

📁 这是完整的gcc源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Process declarations and variables for C compiler.   Copyright (C) 1988 Free Software Foundation, Inc.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 1, 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 "tree.h"#include "flags.h"#include "c-tree.h"#include "c-parse.h"#include <stdio.h>/* In grokdeclarator, distinguish syntactic contexts of declarators.  */enum decl_context{ NORMAL,			/* Ordinary declaration */  FUNCDEF,			/* Function definition */  PARM,				/* Declaration of parm before function body */  FIELD,			/* Declaration inside struct or union */  TYPENAME};			/* Typename (inside cast or sizeof)  */#undef NULL#define NULL 0#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))#ifndef CHAR_TYPE_SIZE#define CHAR_TYPE_SIZE BITS_PER_UNIT#endif#ifndef SHORT_TYPE_SIZE#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))#endif#ifndef INT_TYPE_SIZE#define INT_TYPE_SIZE BITS_PER_WORD#endif#ifndef LONG_TYPE_SIZE#define LONG_TYPE_SIZE BITS_PER_WORD#endif#ifndef LONG_LONG_TYPE_SIZE#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)#endif#ifndef FLOAT_TYPE_SIZE#define FLOAT_TYPE_SIZE BITS_PER_WORD#endif#ifndef DOUBLE_TYPE_SIZE#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)#endif#ifndef LONG_DOUBLE_TYPE_SIZE#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)#endif/* a node which has tree code ERROR_MARK, and whose type is itself.   All erroneous expressions are replaced with this node.  All functions   that accept nodes as arguments should avoid generating error messages   if this node is one of the arguments, since it is undesirable to get   multiple error messages from one error in the input.  */tree error_mark_node;/* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */tree short_integer_type_node;tree integer_type_node;tree long_integer_type_node;tree long_long_integer_type_node;tree short_unsigned_type_node;tree unsigned_type_node;tree long_unsigned_type_node;tree long_long_unsigned_type_node;tree unsigned_char_type_node;tree signed_char_type_node;tree char_type_node;tree float_type_node;tree double_type_node;tree long_double_type_node;/* a VOID_TYPE node.  */tree void_type_node;/* A node for type `void *'.  */tree ptr_type_node;/* A node for type `char *'.  */tree string_type_node;/* Type `char[256]' or something like it.   Used when an array of char is needed and the size is irrelevant.  */tree char_array_type_node;/* Type `int[256]' or something like it.   Used when an array of int needed and the size is irrelevant.  */tree int_array_type_node;/* type `int ()' -- used for implicit declaration of functions.  */tree default_function_type;/* function types `double (double)' and `double (double, double)', etc.  */tree double_ftype_double, double_ftype_double_double;tree int_ftype_int, long_ftype_long;/* Function type `void (void *, void *, int)' and similar ones */tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;/* Two expressions that are constants with value zero.   The first is of type `int', the second of type `void *'.  */tree integer_zero_node;tree null_pointer_node;/* A node for the integer constant 1.  */tree integer_one_node;/* An identifier whose name is <value>.  This is used as the "name"   of the RESULT_DECLs for values of functions.  */tree value_identifier;/* A permanent tree_list whose value slot is the void type.  */static tree void_list_node;/* While defining an enum type, this is 1 plus the last enumerator   constant value.  */static tree enum_next_value;/* Parsing a function declarator leaves a list of parameter names   or a chain or parameter decls here.  */static tree last_function_parms;/* Parsing a function declarator leaves here a chain of structure   and enum types declared in the parmlist.  */static tree last_function_parm_tags;/* After parsing the declarator that starts a function definition,   `start_function' puts here the list of parameter names or chain of decls.   `store_parm_decls' finds it here.  */static tree current_function_parms;/* Similar, for last_function_parm_tags.  */static tree current_function_parm_tags;/* A list (chain of TREE_LIST nodes) of all LABEL_STMTs in the function   that have names.  Here so we can clear out their names' definitions   at the end of the function.  */static tree named_labels;/* The FUNCTION_DECL for the function currently being compiled,   or 0 if between functions.  */tree current_function_decl;/* Set to 0 at beginning of a function definition, set to 1 if   a return statement that specifies a return value is seen.  */int current_function_returns_value;/* Set to 0 at beginning of a function definition, set to 1 if   a return statement with no argument is seen.  */int current_function_returns_null;/* Set to nonzero by `grokdeclarator' for a function   whose return type is defaulted, if warnings for this are desired.  */static int warn_about_return_type;/* Nonzero when starting a function delcared `extern inline'.  */static int current_extern_inline;/* For each binding contour we allocate a binding_level 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. *//* Note that the information in the `names' component of the global contour   is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */struct binding_level  {    /* A chain of _DECL nodes for all variables, constants, functions,       and typedef types.  These are in the reverse of the order supplied.     */    tree names;    /* A list of structure, union and enum definitions,     * for looking up tag names.     * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,     * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,     * or ENUMERAL_TYPE node.     */    tree tags;    /* 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 LET_STMT nodes for all the levels       that were entered and exited one level down.  */    tree blocks;    /* The binding level which this one is contained in (inherits from).  */    struct binding_level *level_chain;    /* Nonzero for the level that holds the parameters of a function.  */    char parm_flag;    /* Nonzero if this level "doesn't exist" for tags.  */    char tag_transparent;    /* Nonzero means make a LET_STMT for this level regardless of all else.  */    char keep;    /* Nonzero means make a LET_STMT if this level has any subblocks.  */    char keep_if_subblocks;    /* Number of decls in `names' that have incomplete        structure or union types.  */    int n_incomplete;  };#define NULL_BINDING_LEVEL (struct binding_level *) NULL  /* The binding level currently in effect.  */static struct binding_level *current_binding_level;/* A chain of binding_level structures awaiting reuse.  */static struct binding_level *free_binding_level;/* The outermost binding level, for names of file scope.   This is created when the compiler is started and exists   through the entire run.  */static struct binding_level *global_binding_level;/* Binding level structures are initialized by copying this one.  */static struct binding_level clear_binding_level  = {NULL, NULL, NULL, NULL, NULL, 0, 0, 0};/* Nonzero means unconditionally make a LET_STMT for the next level pushed.  */static int keep_next_level_flag;/* Nonzero means make a LET_STMT for the next level pushed   if it has subblocks.  */static int keep_next_if_subblocks;/* Forward declarations.  */static tree grokparms (), grokdeclarator ();tree pushdecl ();static void builtin_function ();static tree lookup_tag ();static tree lookup_tag_reverse ();static tree lookup_name_current_level ();static char *redeclaration_error_message ();static void layout_array_type ();/* C-specific option variables.  *//* Nonzero means allow type mismatches in conditional expressions;   just make their values `void'.   */int flag_cond_mismatch;/* Nonzero means don't recognize the keyword `asm'.  */int flag_no_asm;/* Nonzero means do some things the same way PCC does.  */int flag_traditional;/* Nonzero means warn about implicit declarations.  */int warn_implicit;/* Nonzero means warn about function definitions that default the return type   or that use a null return and have a return-type other than void.  */int 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;/* Nonzero means warn about sizeof(function) or addition/subtraction   of function pointers.  */int warn_pointer_arith;/* Nonzero means warn for all old-style non-prototype function decls.  */int warn_strict_prototypes;/* 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;char *language_string = "GNU C";/* Decode the string P as a language-specific option.   Return 1 if it is recognized (and handle it);   return 0 if not recognized.  */   intlang_decode_option (p)     char *p;{  if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))    flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 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, "-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, "-fasm"))    flag_no_asm = 0;  else if (!strcmp (p, "-fno-asm"))    flag_no_asm = 1;  else if (!strcmp (p, "-ansi"))    flag_no_asm = 1, dollars_in_ident = 0;  else if (!strcmp (p, "-Wimplicit"))    warn_implicit = 1;  else if (!strcmp (p, "-Wreturn-type"))    warn_return_type = 1;  else if (!strcmp (p, "-Wwrite-strings"))    warn_write_strings = 1;  else if (!strcmp (p, "-Wcast-qual"))    warn_cast_qual = 1;  else if (!strcmp (p, "-Wpointer-arith"))    warn_pointer_arith = 1;  else if (!strcmp (p, "-Wstrict-prototypes"))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -