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

📄 sig.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Functions dealing with signatures and signature pointers/references.   Copyright (C) 1992, 93-97, 1998 Free Software Foundation, Inc.   Contributed by Gerald Baumgartner (gb@cs.purdue.edu)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, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  */#include "config.h"#include "system.h"#include "obstack.h"#include "tree.h"#include "cp-tree.h"#include "flags.h"#include "assert.h"#include "toplev.h"extern struct obstack *current_obstack;extern struct obstack permanent_obstack;extern struct obstack *saveable_obstack;static tree save_this PROTO((tree));static tree build_sptr_ref PROTO((tree));static tree build_member_function_pointer PROTO((tree));static void undo_casts PROTO((tree));static tree build_signature_pointer_or_reference_name	PROTO((tree, int, int));static void build_signature_pointer_or_reference_decl	PROTO((tree, tree));static tree build_signature_pointer_or_reference_type 	PROTO((tree, int, int));static tree get_sigtable_name PROTO((tree, tree));static tree build_signature_table_constructor PROTO((tree, tree));static int match_method_types PROTO((tree, tree));static tree build_sigtable PROTO((tree, tree, tree));/* Used to help generate globally unique names for signature tables.  */static int global_sigtable_name_counter;/* Build an identifier for a signature pointer or reference, so we   can use it's name in function name mangling.  */static treebuild_signature_pointer_or_reference_name (to_type, type_quals, refp)     tree to_type;     int type_quals;     int refp;{  const char * sig_name = TYPE_NAME_STRING (to_type);  int name_len = TYPE_NAME_LENGTH (to_type) + 3 /* Enough room for						   C,V,R.  */;  char * name;  const char *const_rep = (type_quals & TYPE_QUAL_CONST) ? "C" : "";  const char *restrict_rep = (type_quals & TYPE_QUAL_RESTRICT) ? "R" : "";   const char *volatile_rep = (type_quals & TYPE_QUAL_VOLATILE) ? "C" : "";  if (refp)    {      name = (char *) alloca (name_len + sizeof (SIGNATURE_REFERENCE_NAME) +2);      sprintf (name, SIGNATURE_REFERENCE_NAME_FORMAT,	       const_rep, volatile_rep, restrict_rep, sig_name);    }  else    {      name = (char *) alloca (name_len + sizeof (SIGNATURE_POINTER_NAME) + 2);      sprintf (name, SIGNATURE_POINTER_NAME_FORMAT,	       const_rep, volatile_rep, restrict_rep, sig_name);    }  return get_identifier (name);}/* Build a DECL node for a signature pointer or reference, so we can   tell the debugger the structure of signature pointers/references.   This function is called at most eight times for a given signature,   once for each [const] [volatile] signature pointer/reference.  */static voidbuild_signature_pointer_or_reference_decl (type, name)     tree type, name;{  tree decl;  /* We don't enter this declaration in any sort of symbol table.  */  decl = build_decl (TYPE_DECL, name, type);  TYPE_NAME (type) = decl;  TREE_CHAIN (type) = decl;}/* Construct, lay out and return the type of pointers or references to   signature TO_TYPE.  If such a type has already been constructed,   reuse it. If TYPE_QUALS are specified, qualify the `optr'.  If we   are constructing a const/volatile type variant and the main type   variant doesn't exist yet, it is built as well.  If REFP is 1, we   construct a signature reference, otherwise a signature pointer is   constructed.   This function is a subroutine of `build_signature_pointer_type' and   `build_signature_reference_type'.  */static treebuild_signature_pointer_or_reference_type (to_type, type_quals, refp)     tree to_type;     int type_quals;     int refp;{  register tree t, m;  register struct obstack *ambient_obstack = current_obstack;  register struct obstack *ambient_saveable_obstack = saveable_obstack;  m = refp ? SIGNATURE_REFERENCE_TO (to_type) : SIGNATURE_POINTER_TO (to_type);  /* If we don't have the main variant yet, construct it.  */  if (m == NULL_TREE && type_quals != TYPE_UNQUALIFIED)    m = build_signature_pointer_or_reference_type (to_type, 						   TYPE_UNQUALIFIED, refp);  /* Treat any nonzero argument as 1.  */  refp = !!refp;  /* If not generating auxiliary info, search the chain of variants to see     if there is already one there just like the one we need to have.  If so,     use that existing one.     We don't do this in the case where we are generating aux info because     in that case we want each typedef names to get it's own distinct type     node, even if the type of this new typedef is the same as some other     (existing) type.  */  if (m && !flag_gen_aux_info)    for (t = m; t; t = TYPE_NEXT_VARIANT (t))      if (type_quals == CP_TYPE_QUALS (TREE_TYPE (TREE_TYPE						  (TYPE_FIELDS (t)))))        return t;  /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */  if (TREE_PERMANENT (to_type))    {      current_obstack = &permanent_obstack;      saveable_obstack = &permanent_obstack;    }  /* A signature pointer or reference to a signature `s' looks like this:       struct {         void * optr;	 const s * sptr;       };     A `const' signature pointer/reference is a       struct {         const void * optr;	 const s * sptr;       };     Similarly, for `volatile' and `const volatile'.  */  t = make_lang_type (RECORD_TYPE);  {    tree obj_type = build_qualified_type (void_type_node, type_quals);    tree optr_type = build_pointer_type (obj_type);    tree optr, sptr;    optr = build_lang_field_decl (FIELD_DECL,				  get_identifier (SIGNATURE_OPTR_NAME),				  optr_type);    DECL_FIELD_CONTEXT (optr) = t;    DECL_CLASS_CONTEXT (optr) = t;    if (m)      /* We can share the `sptr' field among type variants.  */      sptr = TREE_CHAIN (TYPE_FIELDS (m));    else      {	tree sig_tbl_type = 	  cp_build_qualified_type (to_type, TYPE_QUAL_CONST);		sptr = build_lang_field_decl (FIELD_DECL,				      get_identifier (SIGNATURE_SPTR_NAME),				      build_pointer_type (sig_tbl_type));	DECL_FIELD_CONTEXT (sptr) = t;	DECL_CLASS_CONTEXT (sptr) = t;	TREE_CHAIN (sptr) = NULL_TREE;      }    TREE_CHAIN (optr) = sptr;    TYPE_FIELDS (t) = optr;    /* Allow signature pointers/references to be grabbed 2 words at a time.       For this to work on a Sparc, we need 8-byte alignment.  */    TYPE_ALIGN (t) = MAX (TYPE_ALIGN (double_type_node),			  TYPE_ALIGN (optr_type));    /* A signature pointer/reference type isn't a `real' class type.  */    SET_IS_AGGR_TYPE (t, 0);  }  {    tree name = build_signature_pointer_or_reference_name (to_type, 							   type_quals,							   refp);    /* Build a DECL node for this type, so the debugger has access to it.  */    build_signature_pointer_or_reference_decl (t, name);  }  CLASSTYPE_GOT_SEMICOLON (t) = 1;  IS_SIGNATURE_POINTER (t) = ! refp;  IS_SIGNATURE_REFERENCE (t) = refp;  SIGNATURE_TYPE (t) = to_type;  if (m)    {      /* Add this type to the chain of variants of TYPE.	 Every type has to be its own TYPE_MAIN_VARIANT.  */      TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);      TYPE_NEXT_VARIANT (m) = t;    }  else if (refp)    /* Record this type as the reference to TO_TYPE.  */    SIGNATURE_REFERENCE_TO (to_type) = t;  else    /* Record this type as the pointer to TO_TYPE.  */    SIGNATURE_POINTER_TO (to_type) = t;  /* Lay out the type.  This function has many callers that are concerned     with expression-construction, and this simplifies them all.     Also, it guarantees the TYPE_SIZE is permanent if the type is.  */  layout_type (t);  current_obstack = ambient_obstack;  saveable_obstack = ambient_saveable_obstack;  /* Output debug information for this type.  */  rest_of_type_compilation (t, 1);  return t;}/* Construct, lay out and return the type of pointers to signature TO_TYPE.  */treebuild_signature_pointer_type (to_type)     tree to_type;{  return    build_signature_pointer_or_reference_type (TYPE_MAIN_VARIANT (to_type),					       CP_TYPE_QUALS (to_type), 0);}/* Construct, lay out and return the type of pointers to signature TO_TYPE.  */treebuild_signature_reference_type (to_type)     tree to_type;{  return    build_signature_pointer_or_reference_type (TYPE_MAIN_VARIANT (to_type),					       CP_TYPE_QUALS (to_type), 1);}/* Return the name of the signature table (as an IDENTIFIER_NODE)   for the given signature type SIG_TYPE and rhs type RHS_TYPE.  */static treeget_sigtable_name (sig_type, rhs_type)     tree sig_type, rhs_type;{  tree sig_type_id = build_typename_overload (sig_type);  tree rhs_type_id = build_typename_overload (rhs_type);  char *buf = (char *) alloca (sizeof (SIGTABLE_NAME_FORMAT_LONG)			       + IDENTIFIER_LENGTH (sig_type_id)			       + IDENTIFIER_LENGTH (rhs_type_id) + 20);  const char *sig_ptr = IDENTIFIER_POINTER (sig_type_id);  const char *rhs_ptr = IDENTIFIER_POINTER (rhs_type_id);  int i, j;  for (i = 0; sig_ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++)    /* do nothing */;  while (sig_ptr[i] >= '0' && sig_ptr[i] <= '9')    i += 1;  for (j = 0; rhs_ptr[j] == OPERATOR_TYPENAME_FORMAT[j]; j++)    /* do nothing */;  while (rhs_ptr[j] >= '0' && rhs_ptr[j] <= '9')    j += 1;  if (IS_SIGNATURE (rhs_type))    sprintf (buf, SIGTABLE_NAME_FORMAT_LONG, sig_ptr+i, rhs_ptr+j,	     global_sigtable_name_counter++);  else    sprintf (buf, SIGTABLE_NAME_FORMAT, sig_ptr+i, rhs_ptr+j);  return get_identifier (buf);}/* Build a field decl that points to a signature member function.  */static treebuild_member_function_pointer (member)     tree member;{  const char *namstr = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (member));  int namlen = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (member));  char *name;  tree entry;    name = (char *) alloca (namlen + sizeof (SIGNATURE_FIELD_NAME) + 2);  sprintf (name, SIGNATURE_FIELD_NAME_FORMAT, namstr);  /* @@ Do we really want to xref signature table fields?  */  GNU_xref_ref (current_function_decl, name);  entry = build_lang_field_decl (FIELD_DECL, get_identifier (name),				 sigtable_entry_type);  TREE_CONSTANT (entry) = 1;  TREE_READONLY (entry) = 1;  /* @@ Do we really want to xref signature table fields?  */  GNU_xref_decl (current_function_decl, entry);  return entry;}/* For each FUNCTION_DECL in a signature we construct a member function   pointer of the appropriate type.  We also need two flags to test   whether the member function pointer points to a virtual function or   to a default implementation.  Those flags will be the two lower order   bits of the member function pointer (or the two higher order bits,   based on the configuration).   The new FIELD_DECLs are appended at the end of the last (and only)   sublist of `list_of_fieldlists.'   T is the signature type.     As a side effect, each member function in the signature gets the   `decl.ignored' bit turned on, so we don't output debug info for it.  */voidappend_signature_fields (t)     tree t;

⌨️ 快捷键说明

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