Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:C and C++ Trees   [Contents][Index]


10.10.3 Classes

Besides namespaces, the other high-level scoping construct in C++ is theclass. (Throughout this manual the termclass is used to mean thetypes referred to in the ANSI/ISO C++ Standard as classes; these includetypes defined with theclass,struct, andunionkeywords.)

A class type is represented by either aRECORD_TYPE or aUNION_TYPE. A class declared with theunion tag isrepresented by aUNION_TYPE, while classes declared with eitherthestruct or theclass tag are represented byRECORD_TYPEs. You can use theCLASSTYPE_DECLARED_CLASSmacro to discern whether or not a particular type is aclass asopposed to astruct. This macro will be true only for classesdeclared with theclass tag.

Almost all members are available on theTYPE_FIELDSlist. Given one member, the next can be found by following theTREE_CHAIN. You should not depend in any way on the order inwhich fields appear on this list. All nodes on this list will be‘DECL’ nodes. AFIELD_DECL is used to represent a non-staticdata member, aVAR_DECL is used to represent a static datamember, and aTYPE_DECL is used to represent a type. Note thattheCONST_DECL for an enumeration constant will appear on thislist, if the enumeration type was declared in the class. (Of course,theTYPE_DECL for the enumeration type will appear here as well.)There are no entries for base classes on this list. In particular,there is noFIELD_DECL for the “base-class portion” of anobject. If a function member is overloaded, each of the overloadedfunctions appears; noOVERLOAD nodes appear on theTYPE_FIELDSlist. Implicitly declared functions (including default constructors,copy constructors, assignment operators, and destructors) will appear onthis list as well.

TheTYPE_VFIELD is a compiler-generated field used to point tovirtual function tables. It may or may not appear on theTYPE_FIELDS list. However, back ends should handle theTYPE_VFIELD just like all the entries on theTYPE_FIELDSlist.

Every class has an associatedbinfo, which can be obtained withTYPE_BINFO. Binfos are used to represent base-classes. Thebinfo given byTYPE_BINFO is the degenerate case, whereby everyclass is considered to be its own base-class. The base binfos for aparticular binfo are held in a vector, whose length is obtained withBINFO_N_BASE_BINFOS. The base binfos themselves are obtainedwithBINFO_BASE_BINFO andBINFO_BASE_ITERATE. To add anew binfo, useBINFO_BASE_APPEND. The vector of base binfos canbe obtained withBINFO_BASE_BINFOS, but normally you do not needto use that. The class type associated with a binfo is given byBINFO_TYPE. It is not always the case thatBINFO_TYPE(TYPE_BINFO (x)), because of typedefs and qualified types. Neither isit the case thatTYPE_BINFO (BINFO_TYPE (y)) is the same binfo asy. The reason is that ify is a binfo representing abase-classB of a derived classD, thenBINFO_TYPE(y) will beB, andTYPE_BINFO (BINFO_TYPE (y)) will beB as its own base-class, rather than as a base-class ofD.

The access to a base type can be found withBINFO_BASE_ACCESS.This will produceaccess_public_node,access_private_nodeoraccess_protected_node. If bases are always public,BINFO_BASE_ACCESSES may beNULL.

BINFO_VIRTUAL_P is used to specify whether the binfo is inheritedvirtually or not. The other flags,BINFO_FLAG_0 toBINFO_FLAG_6, can be used for language specific use.

The following macros can be used on a tree node representing a class-type.

LOCAL_CLASS_P

This predicate holds if the class is local classi.e. declaredinside a function body.

TYPE_POLYMORPHIC_P

This predicate holds if the class has at least one virtual function(declared or inherited).

TYPE_HAS_DEFAULT_CONSTRUCTOR

This predicate holds whenever its argument represents a class-type withdefault constructor.

CLASSTYPE_HAS_MUTABLE
TYPE_HAS_MUTABLE_P

These predicates hold for a class-type having a mutable data member.

CLASSTYPE_NON_POD_P

This predicate holds only for class-types that are not PODs.

TYPE_HAS_NEW_OPERATOR

This predicate holds for a class-type that definesoperator new.

TYPE_HAS_ARRAY_NEW_OPERATOR

This predicate holds for a class-type for whichoperator new[] is defined.

TYPE_OVERLOADS_CALL_EXPR

This predicate holds for class-type for which the function calloperator() is overloaded.

TYPE_OVERLOADS_ARRAY_REF

This predicate holds for a class-type that overloadsoperator[]

TYPE_OVERLOADS_ARROW

This predicate holds for a class-type for whichoperator-> isoverloaded.


Next:Functions for C++, Previous:Namespaces, Up:C and C++ Trees   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp