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

📄 c-decl.c

📁 这是完整的gcc源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  return decl;}/* Return zero if the declaration NEWDECL is valid   when the declaration OLDDECL (assumed to be for the same name)   has already been seen.   Otherwise return an error message format string with a %s   where the identifier should go.  */static char *redeclaration_error_message (newdecl, olddecl)     tree newdecl, olddecl;{  if (TREE_CODE (newdecl) == TYPE_DECL)    {      if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl))	return 0;      return "redefinition of `%s'";    }  else if (TREE_CODE (newdecl) == FUNCTION_DECL)    {      /* Declarations of functions can insist on internal linkage	 but they can't be inconsistent with internal linkage,	 so there can be no error on that account.	 However defining the same name twice is no good.  */      if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0	  /* However, defining once as extern inline and a second	     time in another way is ok.  */	  && !(TREE_INLINE (olddecl) && TREE_EXTERNAL (olddecl)	       && !(TREE_INLINE (newdecl) && TREE_EXTERNAL (newdecl))))	return "redefinition of `%s'";      return 0;    }  else if (current_binding_level == global_binding_level)    {      /* Objects declared at top level:  */      /* If at least one is a reference, it's ok.  */      if (TREE_EXTERNAL (newdecl) || TREE_EXTERNAL (olddecl))	return 0;      /* Reject two definitions.  */      if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)	return "redefinition of `%s'";      /* Now we have two tentative defs, or one tentative and one real def.  */      /* Insist that the linkage match.  */      if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))	return "conflicting declarations of `%s'";      return 0;    }  else    {      /* Objects declared with block scope:  */      /* Reject two definitions, and reject a definition	 together with an external reference.  */       if (!(TREE_EXTERNAL (newdecl) && TREE_EXTERNAL (olddecl)))	return "redeclaration of `%s'";      return 0;    }}/* Get the LABEL_DECL corresponding to identifier ID as a label.   Create one if none exists so far for the current function.   This function is called for both label definitions and label references.  */treelookup_label (id)     tree id;{  register tree decl = IDENTIFIER_LABEL_VALUE (id);  if (decl != 0)    return decl;  decl = build_decl (LABEL_DECL, id, NULL_TREE);  DECL_MODE (decl) = VOIDmode;  /* Mark that the label's definition has not been seen.  */  DECL_SOURCE_LINE (decl) = 0;  IDENTIFIER_LABEL_VALUE (id) = decl;  named_labels    = tree_cons (NULL_TREE, decl, named_labels);  return decl;}/* Define a label, specifying the location in the source file.   Return the LABEL_DECL node for the label, if the definition is valid.   Otherwise return 0.  */treedefine_label (filename, line, name)     char *filename;     int line;     tree name;{  tree decl = lookup_label (name);  if (DECL_SOURCE_LINE (decl) != 0)    {      error_with_decl (decl, "duplicate label `%s'");      return 0;    }  else    {      /* Mark label as having been defined.  */      DECL_SOURCE_FILE (decl) = filename;      DECL_SOURCE_LINE (decl) = line;      return decl;    }}/* Return the list of declarations of the current level.   Note that this list is in reverse order unless/until   you nreverse it; and when you do nreverse it, you must   store the result back using `storedecls' or you will lose.  */treegetdecls (){  return current_binding_level->names;}/* Return the list of type-tags (for structs, etc) of the current level.  */treegettags (){  return current_binding_level->tags;}/* Store the list of declarations of the current level.   This is done for the parameter declarations of a function being defined,   after they are modified in the light of any missing parameters.  */static voidstoredecls (decls)     tree decls;{  current_binding_level->names = decls;}/* Similarly, store the list of tags of the current level.  */static voidstoretags (tags)     tree tags;{  current_binding_level->tags = tags;}/* Given NAME, an IDENTIFIER_NODE,   return the structure (or union or enum) definition for that name.   Searches binding levels from BINDING_LEVEL up to the global level.   If THISLEVEL_ONLY is nonzero, searches only the specified context   (but skips any tag-transparent contexts to find one that is   meaningful for tags).   FORM says which kind of type the caller wants;   it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.   If the wrong kind of type is found, an error is reported.  */static treelookup_tag (form, name, binding_level, thislevel_only)     enum tree_code form;     struct binding_level *binding_level;     tree name;     int thislevel_only;{  register struct binding_level *level;  for (level = binding_level; level; level = level->level_chain)    {      register tree tail;      for (tail = level->tags; tail; tail = TREE_CHAIN (tail))	{	  if (TREE_PURPOSE (tail) == name)	    {	      if (TREE_CODE (TREE_VALUE (tail)) != form)		{		  /* Definition isn't the kind we were looking for.  */		  error ("`%s' defined as wrong kind of tag",			 IDENTIFIER_POINTER (name));		}	      return TREE_VALUE (tail);	    }	}      if (thislevel_only && ! level->tag_transparent)	return NULL_TREE;    }  return NULL_TREE;}/* Given a type, find the tag that was defined for it and return the tag name.   Otherwise return 0.  However, the value can never be 0   in the cases in which this is used.  */static treelookup_tag_reverse (type)     tree type;{  register struct binding_level *level;  for (level = current_binding_level; level; level = level->level_chain)    {      register tree tail;      for (tail = level->tags; tail; tail = TREE_CHAIN (tail))	{	  if (TREE_VALUE (tail) == type)	    return TREE_PURPOSE (tail);	}    }  return NULL_TREE;}/* Look up NAME in the current binding level and its superiors   in the namespace of variables, functions and typedefs.   Return a ..._DECL node of some kind representing its definition,   or return 0 if it is undefined.  */treelookup_name (name)     tree name;{  register tree val;  if (current_binding_level != global_binding_level      && IDENTIFIER_LOCAL_VALUE (name))    val = IDENTIFIER_LOCAL_VALUE (name);  else    val = IDENTIFIER_GLOBAL_VALUE (name);  if (val && TREE_TYPE (val) == error_mark_node)    return error_mark_node;  return val;}/* Similar to `lookup_name' but look only at current binding level.  */static treelookup_name_current_level (name)     tree name;{  register tree t;  if (current_binding_level == global_binding_level)    return IDENTIFIER_GLOBAL_VALUE (name);  if (IDENTIFIER_LOCAL_VALUE (name) == 0)    return 0;  for (t = current_binding_level->names; t; t = TREE_CHAIN (t))    if (DECL_NAME (t) == name)      break;  return t;}/* Create the predefined scalar types of C,   and some nodes representing standard constants (0, 1, (void *)0).   Initialize the global binding level.   Make definitions for built-in primitive functions.  */voidinit_decl_processing (){  register tree endlink;  /* Make identifier nodes long enough for the language-specific slots.  */  set_identifier_size (sizeof (struct lang_identifier));  current_function_decl = NULL;  named_labels = NULL;  current_binding_level = NULL_BINDING_LEVEL;  free_binding_level = NULL_BINDING_LEVEL;  pushlevel (0);	/* make the binding_level structure for global names */  global_binding_level = current_binding_level;  value_identifier = get_identifier ("<value>");  /* Define `int' and `char' first so that dbx will output them first.  */  integer_type_node = make_signed_type (INT_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],			integer_type_node));  /* Define `char', which is like either `signed char' or `unsigned char'     but not the same as either.  */  char_type_node =    (flag_signed_char     ? make_signed_type (CHAR_TYPE_SIZE)     : make_unsigned_type (CHAR_TYPE_SIZE));  pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),			char_type_node));  long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),			long_integer_type_node));  unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),			unsigned_type_node));  long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),			long_unsigned_type_node));  /* `unsigned long' or `unsigned int' is the standard type for sizeof.     Traditionally, use a signed type.  */  if (INT_TYPE_SIZE != LONG_TYPE_SIZE)    sizetype = flag_traditional ? long_integer_type_node : long_unsigned_type_node;  else    sizetype = flag_traditional ? integer_type_node : unsigned_type_node;  TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;  TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;  TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;  TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;  TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;  error_mark_node = make_node (ERROR_MARK);  TREE_TYPE (error_mark_node) = error_mark_node;  short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),			short_integer_type_node));  long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),			long_long_integer_type_node));  short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),			short_unsigned_type_node));  long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),			long_long_unsigned_type_node));  /* Define both `signed char' and `unsigned char'.  */  signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),			signed_char_type_node));  unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);  pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),			unsigned_char_type_node));  float_type_node = make_node (REAL_TYPE);  TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],			float_type_node));  layout_type (float_type_node);  double_type_node = make_node (REAL_TYPE);  TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],			double_type_node));  layout_type (double_type_node);  long_double_type_node = make_node (REAL_TYPE);  TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;  pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),			long_double_type_node));  layout_type (long_double_type_node);  integer_zero_node = build_int_2 (0, 0);  TREE_TYPE (integer_zero_node) = integer_type_node;  integer_one_node = build_int_2 (1, 0);  TREE_TYPE (integer_one_node) = integer_type_node;  size_zero_node = build_int_2 (0, 0);  TREE_TYPE (size_zero_node) = sizetype;  size_one_node = build_int_2 (1, 0);  TREE_TYPE (size_one_node) = sizetype;  void_type_node = make_node (VOID_TYPE);  pushdecl (build_decl (TYPE_DECL,			ridpointers[(int) RID_VOID], void_type_node));  layout_type (void_type_node);	/* Uses integer_zero_node */  null_pointer_node = build_int_2 (0, 0);  TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);  layout_type (TREE_TYPE (null_pointer_node));  string_type_node = build_pointer_type (char_type_node);  /* make a type for arrays of 256 characters.     256 is picked randomly because we have a type for integers from 0 to 255.     With luck nothing will ever really depend on the length of this     array type.  */  char_array_type_node    = build_array_type (char_type_node, unsigned_char_type_node);  /* Likewise for arrays of ints.  */  int_array_type_node    = build_array_type (integer_type_node, unsigned_char_type_node);  default_function_type    = build_function_type (integer_type_node, NULL_TREE);  ptr_type_node = build_pointer_type (void_type_node);  endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);  double_ftype_double    = build_function_type (double_type_node,			   tree_cons (NULL_TREE, double_type_node, endlink));  double_ftype_double_double    = build_function_type (double_type_node,			   tree_cons (NULL_TREE, double_type_node,				      tree_cons (NULL_TREE,						 double_type_node, endlink)));  int_ftype_int    = build_function_type (integer_type_node,			   tree_cons (NULL_TREE, integer_type_node, endlink));  long_ftype_long    = build_function_type (long_integer_type_node,

⌨️ 快捷键说明

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