📄 sig.c
字号:
/* Functions dealing with signatures and signature pointers/references. Copyright (C) 1992, 1993, 1994, 1995 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 <stdio.h>#include "obstack.h"#include "tree.h"#include "cp-tree.h"#include "flags.h"#include "assert.h"extern struct obstack *current_obstack;extern struct obstack permanent_obstack;extern struct obstack *saveable_obstack;extern void error ();extern void sorry ();extern void compiler_error ();extern void make_decl_rtl PROTO((tree, char *, int));/* 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, constp, volatilep, refp) tree to_type; int constp, volatilep, refp;{ char * sig_name = TYPE_NAME_STRING (to_type); int name_len = TYPE_NAME_LENGTH (to_type) + constp + volatilep; char * name; if (refp) { name = (char *) alloca (name_len + sizeof (SIGNATURE_REFERENCE_NAME) +2); sprintf (name, SIGNATURE_REFERENCE_NAME_FORMAT, constp ? "C" : "", volatilep ? "V": "", sig_name); } else { name = (char *) alloca (name_len + sizeof (SIGNATURE_POINTER_NAME) + 2); sprintf (name, SIGNATURE_POINTER_NAME_FORMAT, constp ? "C" : "", volatilep ? "V": "", 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 CONSTP or VOLATILEP is specified, make the `optr' const or volatile, respectively. 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, constp, volatilep, refp) tree to_type; int constp, volatilep, 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 && (constp || volatilep)) m = build_signature_pointer_or_reference_type (to_type, 0, 0, refp); /* Treat any nonzero argument as 1. */ constp = !!constp; volatilep = !!volatilep; 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 (constp == TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (t)))) && volatilep == TYPE_VOLATILE (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_type_variant (void_type_node, constp, volatilep); 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_type_variant (to_type, 1, 0); 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; TYPE_ALIGN (t) = TYPE_ALIGN (optr_type); /* A signature pointer/reference type isn't a `real' class type. */ IS_AGGR_TYPE (t) = 0; } { tree name = build_signature_pointer_or_reference_name (to_type, constp, volatilep, 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, constp, volatilep) tree to_type; int constp, volatilep;{ return build_signature_pointer_or_reference_type (to_type, constp, volatilep, 0);}/* Construct, lay out and return the type of pointers to signature TO_TYPE. */treebuild_signature_reference_type (to_type, constp, volatilep) tree to_type; int constp, volatilep;{ return build_signature_pointer_or_reference_type (to_type, constp, volatilep, 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); char *sig_ptr = IDENTIFIER_POINTER (sig_type_id); 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;{ 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), TYPE_MAIN_VARIANT (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.' 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 (list_of_fieldlists) tree list_of_fieldlists;{ tree l, x; tree last_x = NULL_TREE; tree mfptr; tree last_mfptr; tree mfptr_list = NULL_TREE; /* For signatures it should actually be only a list with one element. */ for (l = list_of_fieldlists; l; l = TREE_CHAIN (l)) { for (x = TREE_VALUE (l); x; x = TREE_CHAIN (x)) { if (TREE_CODE (x) == FUNCTION_DECL) { mfptr = build_member_function_pointer (x); DECL_MEMFUNC_POINTER_TO (x) = mfptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -