OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [i386/] [winnt-cxx.c] - Blame information for rev 868

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Target support for C++ classes on Windows.
2
   Contributed by Danny Smith (dannysmith@users.sourceforge.net)
3
   Copyright (C) 2005, 2007
4
   Free Software Foundation, Inc.
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify it under
9
the terms of the GNU General Public License as published by the Free
10
Software Foundation; either version 3, or (at your option) any later
11
version.
12
 
13
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14
WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16
for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "rtl.h"
27
#include "regs.h"
28
#include "hard-reg-set.h"
29
#include "output.h"
30
#include "tree.h"
31
#include "cp/cp-tree.h" /* this is why we're a separate module */
32
#include "flags.h"
33
#include "tm_p.h"
34
#include "toplev.h"
35
#include "hashtab.h"
36
 
37
bool
38
i386_pe_type_dllimport_p (tree decl)
39
{
40
   gcc_assert (TREE_CODE (decl) == VAR_DECL
41
               || TREE_CODE (decl) == FUNCTION_DECL);
42
 
43
   if (TARGET_NOP_FUN_DLLIMPORT && TREE_CODE (decl) == FUNCTION_DECL)
44
     return false;
45
 
46
   /* We ignore the dllimport attribute for inline member functions.
47
      This differs from MSVC behavior which treats it like GNUC
48
      'extern inline' extension.  Also ignore for template
49
      instantiations with linkonce semantics and artificial methods.  */
50
    if (TREE_CODE (decl) ==  FUNCTION_DECL
51
        && (DECL_DECLARED_INLINE_P (decl)
52
            || DECL_TEMPLATE_INSTANTIATION (decl)
53
            || DECL_ARTIFICIAL (decl)))
54
      return false;
55
 
56
   /* Since we can't treat a pointer to a dllimport'd symbol as a
57
       constant address, we turn off the attribute on C++ virtual
58
       methods to allow creation of vtables using thunks.  */
59
    else if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
60
             && DECL_VIRTUAL_P (decl))
61
      {
62
        /* Even though we ignore the attribute from the start, warn if we later see
63
           an out-of class definition, as we do for other member functions in
64
           tree.c:merge_dllimport_decl_attributes.  If this is the key method, the
65
           definition may affect the import-export status of vtables, depending
66
           on how we handle MULTIPLE_SYMBOL_SPACES in cp/decl2.c.   */
67
        if (DECL_INITIAL (decl))
68
          {
69
            warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
70
                    "previous dllimport ignored", decl);
71
#ifdef PE_DLL_DEBUG
72
            if (decl == CLASSTYPE_KEY_METHOD (DECL_CONTEXT (decl)))
73
              warning (OPT_Wattributes, "key method %q+D of dllimport'd class defined"
74
                       decl);
75
#endif
76
          }
77
        return false;
78
      }
79
 
80
      /* Don't mark defined functions as dllimport.  This code will only be
81
         reached if we see a non-inline function defined out-of-class.  */
82
    else if (TREE_CODE (decl) ==  FUNCTION_DECL
83
             && (DECL_INITIAL (decl)))
84
      return false;
85
 
86
    /*  Don't allow definitions of static data members in dllimport class,
87
        If vtable data is marked as DECL_EXTERNAL, import it; otherwise just
88
        ignore the class attribute.  */
89
    else if (TREE_CODE (decl) == VAR_DECL
90
             && TREE_STATIC (decl) && TREE_PUBLIC (decl)
91
             && !DECL_EXTERNAL (decl))
92
      {
93
        if (!DECL_VIRTUAL_P (decl))
94
             error ("definition of static data member %q+D of "
95
                    "dllimport'd class", decl);
96
        return false;
97
      }
98
 
99
    return true;
100
}
101
 
102
 
103
bool
104
i386_pe_type_dllexport_p (tree decl)
105
{
106
   gcc_assert (TREE_CODE (decl) == VAR_DECL
107
               || TREE_CODE (decl) == FUNCTION_DECL);
108
   /* Avoid exporting compiler-generated default dtors and copy ctors.
109
      The only artificial methods that need to be exported are virtual
110
      and non-virtual thunks.  */
111
   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
112
       && DECL_ARTIFICIAL (decl) && !DECL_THUNK_P (decl))
113
     return false;
114
   return true;
115
}
116
 
117
static inline void maybe_add_dllimport (tree decl)
118
{
119
  if (i386_pe_type_dllimport_p (decl))
120
    DECL_DLLIMPORT_P (decl) = 1;
121
}
122
 
123
void
124
i386_pe_adjust_class_at_definition (tree t)
125
{
126
  tree member;
127
 
128
  gcc_assert (CLASS_TYPE_P (t));
129
 
130
 /* We only look at dllimport.  The only thing that dllexport does is
131
    add stuff to a '.drectiv' section at end-of-file, so no need to do
132
    anything for dllexport'd classes until we generate RTL. */
133
  if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (t)) == NULL_TREE)
134
    return;
135
 
136
  /* We don't actually add the attribute to the decl, just set the flag
137
     that signals that the address of this symbol is not a compile-time
138
     constant.   Any subsequent out-of-class declaration of members wil
139
     cause the DECL_DLLIMPORT_P flag to be unset.
140
     (See  tree.c: merge_dllimport_decl_attributes).
141
     That is just right since out-of class declarations can only be a
142
     definition.  We recheck the class members  at RTL generation to
143
     emit warnings if this has happened.  Definition of static data member
144
     of dllimport'd class always causes an error (as per MS compiler).
145
     */
146
 
147
  /* Check static VAR_DECL's.  */
148
  for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
149
    if (TREE_CODE (member) == VAR_DECL)
150
      maybe_add_dllimport (member);
151
 
152
  /* Check FUNCTION_DECL's.  */
153
  for (member = TYPE_METHODS (t); member;  member = TREE_CHAIN (member))
154
    if (TREE_CODE (member) == FUNCTION_DECL)
155
      maybe_add_dllimport (member);
156
 
157
  /* Check vtables  */
158
  for (member = CLASSTYPE_VTABLES (t); member;  member = TREE_CHAIN (member))
159
    if (TREE_CODE (member) == VAR_DECL)
160
      maybe_add_dllimport (member);
161
 
162
/* We leave typeinfo tables alone.  We can't mark TI objects as
163
     dllimport, since the address of a secondary VTT may be needed
164
     for static initialization of a primary VTT.  VTT's  of
165
     dllimport'd classes should always be link-once COMDAT.  */
166
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.