cppStructType.cxx 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cppStructType.cxx
  10. * @author drose
  11. * @date 1999-10-19
  12. */
  13. #include "cppStructType.h"
  14. #include "cppTypedefType.h"
  15. #include "cppReferenceType.h"
  16. #include "cppScope.h"
  17. #include "cppTypeProxy.h"
  18. #include "cppTemplateScope.h"
  19. #include "cppFunctionGroup.h"
  20. #include "cppFunctionType.h"
  21. #include "cppParameterList.h"
  22. #include "cppTBDType.h"
  23. #include "indent.h"
  24. #include "cppParser.h"
  25. /**
  26. *
  27. */
  28. void CPPStructType::Base::
  29. output(std::ostream &out) const {
  30. if (_is_virtual) {
  31. out << "virtual ";
  32. }
  33. out << _vis << " " << *_base;
  34. }
  35. /**
  36. *
  37. */
  38. CPPStructType::
  39. CPPStructType(CPPStructType::Type type, CPPIdentifier *ident,
  40. CPPScope *current_scope, CPPScope *scope,
  41. const CPPFile &file) :
  42. CPPExtensionType(type, ident, current_scope, file),
  43. _scope(scope),
  44. _final(false)
  45. {
  46. _subst_decl_recursive_protect = false;
  47. _incomplete = true;
  48. }
  49. /**
  50. *
  51. */
  52. CPPStructType::
  53. CPPStructType(const CPPStructType &copy) :
  54. CPPExtensionType(copy),
  55. _scope(copy._scope),
  56. _incomplete(copy._incomplete),
  57. _derivation(copy._derivation),
  58. _final(copy._final)
  59. {
  60. _subst_decl_recursive_protect = false;
  61. }
  62. /**
  63. *
  64. */
  65. void CPPStructType::
  66. operator = (const CPPStructType &copy) {
  67. CPPExtensionType::operator = (copy);
  68. _scope = copy._scope;
  69. _incomplete = copy._incomplete;
  70. _derivation = copy._derivation;
  71. _final = copy._final;
  72. }
  73. /**
  74. * A handy function used while parsing to add a new base class to the list of
  75. * classes (or structs) this class derives from.
  76. */
  77. void CPPStructType::
  78. append_derivation(CPPType *base, CPPVisibility vis, bool is_virtual) {
  79. if (base != nullptr) {
  80. // Unwrap any typedefs, since we can't inherit from a typedef.
  81. CPPTypedefType *def = base->as_typedef_type();
  82. while (def != nullptr) {
  83. base = def->_type;
  84. def = base->as_typedef_type();
  85. }
  86. if (vis == V_unknown && base->as_extension_type() != nullptr) {
  87. // Default visibility.
  88. if (base->as_extension_type()->_type == T_class) {
  89. vis = V_private;
  90. } else {
  91. vis = V_public;
  92. }
  93. }
  94. Base b;
  95. b._base = base;
  96. b._vis = vis;
  97. b._is_virtual = is_virtual;
  98. _derivation.push_back(b);
  99. }
  100. }
  101. /**
  102. *
  103. */
  104. CPPScope *CPPStructType::
  105. get_scope() const {
  106. return _scope;
  107. }
  108. /**
  109. * Returns true if this struct declaration is abstract, e.g. it contains or
  110. * inherits at least one method that is pure virtual.
  111. */
  112. bool CPPStructType::
  113. is_abstract() const {
  114. VFunctions funcs;
  115. get_pure_virtual_funcs(funcs);
  116. return !funcs.empty();
  117. }
  118. /**
  119. * Returns true if this struct declaration is a base class of the other given
  120. * class, or the same class.
  121. */
  122. bool CPPStructType::
  123. is_base_of(const CPPStructType *other) const {
  124. if (this == other) {
  125. return true;
  126. }
  127. Derivation::const_iterator di;
  128. for (di = other->_derivation.begin(); di != other->_derivation.end(); ++di) {
  129. const CPPStructType *base = (*di)._base->as_struct_type();
  130. if (base != nullptr && is_base_of(base)) {
  131. return true;
  132. }
  133. }
  134. return false;
  135. }
  136. /**
  137. * Returns true if this struct declaration defines no non-static data members
  138. * other than bit-fields of size 0, no virtual functions, no virtual base
  139. * classes, and no non-empty base classes, and is not a union.
  140. */
  141. bool CPPStructType::
  142. is_empty() const {
  143. if (_type == T_union) {
  144. return false;
  145. }
  146. if (check_virtual()) {
  147. return false;
  148. }
  149. // Make sure all base classes are empty and non-virtual.
  150. Derivation::const_iterator di;
  151. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  152. CPPStructType *base = (*di)._base->as_struct_type();
  153. if ((*di)._is_virtual || (base != nullptr && !base->is_empty())) {
  154. return false;
  155. }
  156. }
  157. // Make sure there are no non-static data members.
  158. CPPScope::Variables::const_iterator vi;
  159. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  160. CPPInstance *instance = (*vi).second;
  161. assert(instance != nullptr);
  162. if (instance->_storage_class & CPPInstance::SC_static) {
  163. // Static members don't count.
  164. continue;
  165. }
  166. // Only members with a bit width of 0 are okay.
  167. if (instance->_bit_width != 0) {
  168. return false;
  169. }
  170. }
  171. return true;
  172. }
  173. /**
  174. * Returns true if this class or any of its base classes have virtual methods.
  175. */
  176. bool CPPStructType::
  177. is_polymorphic() const {
  178. if (_type == T_union) {
  179. return false;
  180. }
  181. return check_virtual();
  182. }
  183. /**
  184. * Returns true if the type is considered a standard layout type.
  185. */
  186. bool CPPStructType::
  187. is_standard_layout() const {
  188. assert(_scope != nullptr);
  189. CPPVisibility member_vis = V_unknown;
  190. // Make sure all data members have the same vis and are standard layout.
  191. CPPScope::Variables::const_iterator vi;
  192. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  193. CPPInstance *instance = (*vi).second;
  194. assert(instance != nullptr);
  195. if (instance->_storage_class & CPPInstance::SC_static) {
  196. // Static members don't count.
  197. continue;
  198. }
  199. // Finally, check if the data member itself is standard layout.
  200. assert(instance->_type != nullptr);
  201. if (!instance->_type->is_standard_layout()) {
  202. return false;
  203. }
  204. if (member_vis == V_unknown) {
  205. // The first non-static data member may not be a base class.
  206. CPPStructType *struct_type = instance->_type->remove_cv()->as_struct_type();
  207. if (struct_type != nullptr && struct_type->is_base_of(this)) {
  208. return false;
  209. }
  210. member_vis = instance->_vis;
  211. } else if (member_vis != instance->_vis) {
  212. // All members need to have the same access control.
  213. return false;
  214. }
  215. }
  216. // Make sure all base classes are standard-layout and non-virtual.
  217. Derivation::const_iterator di;
  218. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  219. CPPStructType *base = (*di)._base->as_struct_type();
  220. if ((*di)._is_virtual) {
  221. return false;
  222. }
  223. // If this class had instance members, all base classes need to be empty.
  224. if (member_vis != V_unknown) {
  225. if (!base->is_empty()) {
  226. return false;
  227. }
  228. } else {
  229. if (!base->is_standard_layout()) {
  230. return false;
  231. }
  232. }
  233. }
  234. // Make sure we have no virtual functions.
  235. return !check_virtual();
  236. }
  237. /**
  238. * Returns true if the type is considered a Plain Old Data (POD) type.
  239. */
  240. bool CPPStructType::
  241. is_trivial() const {
  242. // Make sure all base classes are trivial and non-virtual.
  243. Derivation::const_iterator di;
  244. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  245. CPPStructType *base = (*di)._base->as_struct_type();
  246. if ((*di)._is_virtual || (base != nullptr && !base->is_trivial())) {
  247. return false;
  248. }
  249. }
  250. assert(_scope != nullptr);
  251. // Make sure all members are trivial.
  252. CPPScope::Variables::const_iterator vi;
  253. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  254. CPPInstance *instance = (*vi).second;
  255. assert(instance != nullptr);
  256. if (instance->_storage_class & CPPInstance::SC_static) {
  257. // Static members don't count.
  258. continue;
  259. }
  260. if (instance->_initializer != nullptr) {
  261. // A member with an initializer means the default constructor would
  262. // assign a value. This means the type can't be trivial.
  263. return false;
  264. }
  265. // Finally, check if the data member itself is non-trivial.
  266. assert(instance->_type != nullptr);
  267. if (!instance->_type->is_trivial()) {
  268. return false;
  269. }
  270. }
  271. // Now look for functions that are virtual or con/destructors.
  272. bool is_default_constructible = true;
  273. CPPScope::Functions::const_iterator fi;
  274. for (fi = _scope->_functions.begin(); fi != _scope->_functions.end(); ++fi) {
  275. CPPFunctionGroup *fgroup = (*fi).second;
  276. CPPFunctionGroup::Instances::const_iterator ii;
  277. for (ii = fgroup->_instances.begin(); ii != fgroup->_instances.end(); ++ii) {
  278. CPPInstance *inst = (*ii);
  279. if (inst->_storage_class & CPPInstance::SC_virtual) {
  280. // Virtual functions are banned right off the bat.
  281. return false;
  282. }
  283. // The following checks don't apply for defaulted functions.
  284. if (inst->_storage_class & CPPInstance::SC_defaulted) {
  285. continue;
  286. }
  287. assert(inst->_type != nullptr);
  288. CPPFunctionType *ftype = inst->_type->as_function_type();
  289. assert(ftype != nullptr);
  290. if (ftype->_flags & (CPPFunctionType::F_destructor |
  291. CPPFunctionType::F_move_constructor |
  292. CPPFunctionType::F_copy_constructor)) {
  293. // User-provided destructors and copy/move constructors are not
  294. // trivial unless they are defaulted (and not virtual).
  295. return false;
  296. }
  297. if ((ftype->_flags & CPPFunctionType::F_constructor) != 0) {
  298. if (ftype->_parameters->_parameters.size() == 0 &&
  299. !ftype->_parameters->_includes_ellipsis) {
  300. // Same for the default constructor.
  301. return false;
  302. }
  303. // The presence of a non-default constructor makes the class not
  304. // default-constructible.
  305. is_default_constructible = false;
  306. }
  307. if (fgroup->_name == "operator =") {
  308. // Or assignment operators.
  309. return false;
  310. }
  311. }
  312. }
  313. // Finally, the class must be default-constructible.
  314. return is_default_constructible;
  315. }
  316. /**
  317. * Returns true if the type can be constructed using the given argument.
  318. * This implementation is rudimentary, as it does not attempt to follow all of
  319. * the implicit type conversion rules, but it is still useful.
  320. */
  321. bool CPPStructType::
  322. is_constructible(const CPPType *given_type) const {
  323. // Does the type match the copy constructor or move constructor?
  324. CPPType *base_type = ((CPPType *)given_type)->remove_reference();
  325. if (is_equivalent(*base_type->remove_cv())) {
  326. const CPPReferenceType *ref_type = given_type->as_reference_type();
  327. if (ref_type == nullptr ||
  328. ref_type->_value_category == CPPReferenceType::VC_rvalue) {
  329. return is_move_constructible(V_public);
  330. } else {
  331. return is_copy_constructible(V_public);
  332. }
  333. }
  334. if (is_abstract()) {
  335. return false;
  336. }
  337. // Check for a different constructor.
  338. CPPFunctionGroup *fgroup = get_constructor();
  339. if (fgroup != nullptr) {
  340. CPPFunctionGroup::Instances::const_iterator ii;
  341. for (ii = fgroup->_instances.begin();
  342. ii != fgroup->_instances.end();
  343. ++ii) {
  344. CPPInstance *inst = (*ii);
  345. assert(inst->_type != nullptr);
  346. CPPFunctionType *ftype = inst->_type->as_function_type();
  347. assert(ftype != nullptr);
  348. CPPParameterList *params = ftype->_parameters;
  349. if (params->_parameters.size() == 1 && !params->_includes_ellipsis) {
  350. CPPType *param_type = params->_parameters[0]->_type->remove_reference();
  351. if (!param_type->is_const() && base_type->is_const()) {
  352. // Can't pass a const object to a function taking a non-const.
  353. continue;
  354. }
  355. // It's deleted, anyhow.
  356. if ((inst->_storage_class & CPPInstance::SC_deleted) != 0) {
  357. continue;
  358. }
  359. if (param_type->is_equivalent(*base_type)) {
  360. return true;
  361. }
  362. }
  363. }
  364. }
  365. return false;
  366. }
  367. /**
  368. * Returns true if the type is default-constructible.
  369. */
  370. bool CPPStructType::
  371. is_default_constructible() const {
  372. return is_default_constructible(V_public);
  373. }
  374. /**
  375. * Returns true if the type is copy-constructible.
  376. */
  377. bool CPPStructType::
  378. is_copy_constructible() const {
  379. return is_copy_constructible(V_public);
  380. }
  381. /**
  382. * Returns true if the type is copy-assignable.
  383. */
  384. bool CPPStructType::
  385. is_copy_assignable() const {
  386. if (is_abstract()) {
  387. return false;
  388. }
  389. return is_copy_assignable(V_public);
  390. }
  391. /**
  392. * Returns true if the type is destructible.
  393. */
  394. bool CPPStructType::
  395. is_destructible() const {
  396. return is_destructible(V_public);
  397. }
  398. /**
  399. * Returns true if the type is default-constructible.
  400. */
  401. bool CPPStructType::
  402. is_default_constructible(CPPVisibility min_vis) const {
  403. if (is_abstract()) {
  404. return false;
  405. }
  406. CPPInstance *constructor = get_default_constructor();
  407. if (constructor != nullptr) {
  408. // It has a default constructor.
  409. if (constructor->_vis > min_vis) {
  410. // Inaccessible default constructor.
  411. return false;
  412. }
  413. if (constructor->_storage_class & CPPInstance::SC_deleted) {
  414. // Deleted default constructor.
  415. return false;
  416. }
  417. return true;
  418. }
  419. // Does it have constructors at all? If so, no implicit one is generated.
  420. if (get_constructor() != nullptr) {
  421. return false;
  422. }
  423. // Implicit default constructor. Check if the implicit default constructor
  424. // is deleted.
  425. Derivation::const_iterator di;
  426. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  427. CPPStructType *base = (*di)._base->as_struct_type();
  428. if (base != nullptr) {
  429. if (!base->is_default_constructible(V_protected)) {
  430. return false;
  431. }
  432. }
  433. }
  434. // Make sure all members are default-constructible or have default values.
  435. CPPScope::Variables::const_iterator vi;
  436. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  437. CPPInstance *instance = (*vi).second;
  438. assert(instance != nullptr);
  439. if (instance->_storage_class & CPPInstance::SC_static) {
  440. // Static members don't count.
  441. continue;
  442. }
  443. if (instance->_initializer != nullptr) {
  444. // It has a default value.
  445. continue;
  446. }
  447. if (!instance->_type->is_default_constructible()) {
  448. return false;
  449. }
  450. }
  451. return true;
  452. }
  453. /**
  454. * Returns true if the type is copy-constructible.
  455. */
  456. bool CPPStructType::
  457. is_copy_constructible(CPPVisibility min_vis) const {
  458. if (is_abstract()) {
  459. return false;
  460. }
  461. CPPInstance *constructor = get_copy_constructor();
  462. if (constructor != nullptr) {
  463. // It has a copy constructor.
  464. if (constructor->_vis > min_vis) {
  465. // Inaccessible copy constructor.
  466. return false;
  467. }
  468. if (constructor->_storage_class & CPPInstance::SC_deleted) {
  469. // Deleted copy constructor.
  470. return false;
  471. }
  472. return true;
  473. }
  474. if (get_move_constructor() != nullptr ||
  475. get_move_assignment_operator() != nullptr) {
  476. // A user-declared move constructor or move assignment operator means that
  477. // the implicitly-declared copy constructor is deleted.
  478. return false;
  479. }
  480. CPPInstance *destructor = get_destructor();
  481. if (destructor != nullptr) {
  482. if (destructor->_vis > min_vis) {
  483. // Inaccessible destructor.
  484. return false;
  485. }
  486. if (destructor->_storage_class & CPPInstance::SC_deleted) {
  487. // Deleted destructor.
  488. return false;
  489. }
  490. }
  491. // Implicit copy constructor. Check if the implicit copy constructor is
  492. // deleted.
  493. Derivation::const_iterator di;
  494. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  495. CPPStructType *base = (*di)._base->as_struct_type();
  496. if (base != nullptr) {
  497. if (!base->is_copy_constructible(V_protected)) {
  498. return false;
  499. }
  500. }
  501. }
  502. // Make sure all members are copy-constructible.
  503. CPPScope::Variables::const_iterator vi;
  504. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  505. CPPInstance *instance = (*vi).second;
  506. assert(instance != nullptr);
  507. if (instance->_storage_class & CPPInstance::SC_static) {
  508. // Static members don't count.
  509. continue;
  510. }
  511. if (!instance->_type->is_copy_constructible()) {
  512. return false;
  513. }
  514. }
  515. return true;
  516. }
  517. /**
  518. * Returns true if the type is move-constructible.
  519. */
  520. bool CPPStructType::
  521. is_move_constructible(CPPVisibility min_vis) const {
  522. CPPInstance *constructor = get_move_constructor();
  523. if (constructor != nullptr) {
  524. // It has a user-declared move constructor.
  525. if (constructor->_vis > min_vis) {
  526. // Inaccessible move constructor.
  527. return false;
  528. }
  529. if (constructor->_storage_class & CPPInstance::SC_deleted) {
  530. // It is deleted.
  531. return false;
  532. }
  533. if (is_abstract()) {
  534. return false;
  535. }
  536. return true;
  537. }
  538. return is_copy_constructible(min_vis);
  539. }
  540. /**
  541. * Returns true if the type is copy-assignable, without checking whether the
  542. * class is abstract.
  543. */
  544. bool CPPStructType::
  545. is_copy_assignable(CPPVisibility min_vis) const {
  546. CPPInstance *assignment_operator = get_copy_assignment_operator();
  547. if (assignment_operator != nullptr) {
  548. // It has a copy assignment operator.
  549. if (assignment_operator->_vis > min_vis) {
  550. // Inaccessible copy assignment operator.
  551. return false;
  552. }
  553. if (assignment_operator->_storage_class & CPPInstance::SC_deleted) {
  554. // Deleted copy assignment operator.
  555. return false;
  556. }
  557. // NB: if it's defaulted, it may still be deleted.
  558. if ((assignment_operator->_storage_class & CPPInstance::SC_defaulted) == 0) {
  559. return true;
  560. }
  561. }
  562. // Implicit copy assignment operator. Check if the implicit or defaulted
  563. // copy assignment operator is deleted.
  564. if (!assignment_operator && (get_move_constructor() || get_move_assignment_operator())) {
  565. // It's not explicitly defaulted, and there is a move constructor or move
  566. // assignment operator, so the implicitly-declared one is deleted.
  567. return false;
  568. }
  569. Derivation::const_iterator di;
  570. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  571. CPPStructType *base = (*di)._base->as_struct_type();
  572. if (base != nullptr) {
  573. if (!base->is_copy_assignable(V_protected)) {
  574. return false;
  575. }
  576. }
  577. }
  578. // Make sure all members are assignable.
  579. CPPScope::Variables::const_iterator vi;
  580. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  581. CPPInstance *instance = (*vi).second;
  582. assert(instance != nullptr);
  583. if (instance->_storage_class & CPPInstance::SC_static) {
  584. // Static members don't count.
  585. continue;
  586. }
  587. if (!instance->_type->is_copy_assignable()) {
  588. // Const or reference member, can't do it.
  589. return false;
  590. }
  591. }
  592. return true;
  593. }
  594. /**
  595. * Returns true if the type is move-assignable.
  596. */
  597. bool CPPStructType::
  598. is_move_assignable(CPPVisibility min_vis) const {
  599. CPPInstance *assignment_operator = get_move_assignment_operator();
  600. if (assignment_operator != nullptr) {
  601. // It has a user-declared move assignment_operator.
  602. if (assignment_operator->_vis > min_vis) {
  603. // Inaccessible move assignment_operator.
  604. return false;
  605. }
  606. if (assignment_operator->_storage_class & CPPInstance::SC_deleted) {
  607. // It is deleted.
  608. return false;
  609. }
  610. if (is_abstract()) {
  611. return false;
  612. }
  613. return true;
  614. }
  615. return is_copy_assignable(min_vis);
  616. }
  617. /**
  618. * Returns true if the type is destructible.
  619. */
  620. bool CPPStructType::
  621. is_destructible(CPPVisibility min_vis) const {
  622. // Do we have an explicit destructor?
  623. CPPInstance *destructor = get_destructor();
  624. if (destructor != nullptr) {
  625. if (destructor->_vis > min_vis) {
  626. // Yes, but it's inaccessible.
  627. return false;
  628. }
  629. if (destructor->_storage_class & CPPInstance::SC_deleted) {
  630. // Yes, but it's explicitly been deleted.
  631. return false;
  632. }
  633. return true;
  634. }
  635. // Make sure all base classes are destructible.
  636. Derivation::const_iterator di;
  637. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  638. CPPStructType *base = (*di)._base->as_struct_type();
  639. if (base != nullptr && !base->is_destructible(V_protected)) {
  640. return false;
  641. }
  642. }
  643. assert(_scope != nullptr);
  644. // Make sure all members are destructible.
  645. CPPScope::Variables::const_iterator vi;
  646. for (vi = _scope->_variables.begin(); vi != _scope->_variables.end(); ++vi) {
  647. CPPInstance *instance = (*vi).second;
  648. assert(instance != nullptr);
  649. if (instance->_storage_class & CPPInstance::SC_static) {
  650. // Static members don't count.
  651. continue;
  652. }
  653. // If the data member is not destructible, no go.
  654. assert(instance->_type != nullptr);
  655. if (!instance->_type->is_destructible()) {
  656. return false;
  657. }
  658. }
  659. return true;
  660. }
  661. /**
  662. * Returns true if variables of this type may be implicitly converted to
  663. * the other type.
  664. */
  665. bool CPPStructType::
  666. is_convertible_to(const CPPType *other) const {
  667. if (CPPType::is_convertible_to(other)) {
  668. return true;
  669. }
  670. // Check all typecast operators to see whether we can cast to a type that is
  671. // convertible to the other type.
  672. CPPScope::Functions::const_iterator fi;
  673. for (fi = _scope->_functions.begin(); fi != _scope->_functions.end(); ++fi) {
  674. CPPFunctionGroup *fgroup = (*fi).second;
  675. CPPFunctionGroup::Instances::const_iterator ii;
  676. for (ii = fgroup->_instances.begin(); ii != fgroup->_instances.end(); ++ii) {
  677. CPPInstance *inst = (*ii);
  678. if (inst->_storage_class & (CPPInstance::SC_deleted | CPPInstance::SC_static | CPPInstance::SC_explicit)) {
  679. // Exclude static/deleted/explicit methods.
  680. continue;
  681. }
  682. // Also, the instance needs to be publicly visible.
  683. if (inst->_vis > V_public) {
  684. continue;
  685. }
  686. assert(inst->_type != nullptr);
  687. CPPFunctionType *ftype = inst->_type->as_function_type();
  688. assert(ftype != nullptr);
  689. if (ftype->_return_type != nullptr &&
  690. (ftype->_flags & CPPFunctionType::F_operator_typecast) != 0) {
  691. // Yes, this is a typecast operator. Test using the return type.
  692. if (ftype->_return_type->is_convertible_to(other)) {
  693. return true;
  694. }
  695. }
  696. }
  697. }
  698. // Check whether any of the base classes are convertible.
  699. Derivation::const_iterator di;
  700. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  701. CPPStructType *base = (*di)._base->as_struct_type();
  702. if (base != nullptr && (*di)._vis <= V_public && !base->is_convertible_to(other)) {
  703. return true;
  704. }
  705. }
  706. return false;
  707. }
  708. /**
  709. * Ensures all functions are correctly marked with the "virtual" flag if they
  710. * are truly virtual by virtue of inheritance, rather than simply being
  711. * labeled virtual.
  712. *
  713. * This also sets the CPPInstance::SC_inherited_virtual flags on those virtual
  714. * methods that override a virtual method defined in a parent class (as
  715. * opposed to those that appear for this first time in this class). It is
  716. * sometimes useful to know whether a given virtual method represents the
  717. * first time that particular method appears.
  718. *
  719. * The return value is true if this class defines or inherits any virtual
  720. * methods (and thus requires a virtual function pointer), or false otherwise.
  721. */
  722. bool CPPStructType::
  723. check_virtual() const {
  724. VFunctions funcs;
  725. get_virtual_funcs(funcs);
  726. return !funcs.empty();
  727. }
  728. /**
  729. * Returns true if this class, or any of its base classes, has a virtual
  730. * destructor.
  731. */
  732. bool CPPStructType::
  733. has_virtual_destructor() const {
  734. CPPInstance *destructor = get_destructor();
  735. if (destructor != nullptr) {
  736. if (destructor->_storage_class & CPPInstance::SC_virtual) {
  737. return true;
  738. }
  739. }
  740. Derivation::const_iterator di;
  741. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  742. CPPStructType *base = (*di)._base->as_struct_type();
  743. if (base != nullptr && base->has_virtual_destructor()) {
  744. return true;
  745. }
  746. }
  747. return false;
  748. }
  749. /**
  750. * Returns true if this declaration is an actual, factual declaration, or
  751. * false if some part of the declaration depends on a template parameter which
  752. * has not yet been instantiated.
  753. */
  754. bool CPPStructType::
  755. is_fully_specified() const {
  756. if (_scope != nullptr && !_scope->is_fully_specified()) {
  757. return false;
  758. }
  759. return CPPType::is_fully_specified();
  760. }
  761. /**
  762. * Returns true if the type has not yet been fully specified, false if it has.
  763. */
  764. bool CPPStructType::
  765. is_incomplete() const {
  766. return _incomplete;
  767. }
  768. /**
  769. * Returns the constructor defined for the struct type, if any, or NULL if no
  770. * constructor is found.
  771. */
  772. CPPFunctionGroup *CPPStructType::
  773. get_constructor() const {
  774. // Just look for the function with the same name as the class.
  775. CPPScope::Functions::const_iterator fi;
  776. fi = _scope->_functions.find(get_simple_name());
  777. if (fi != _scope->_functions.end()) {
  778. return fi->second;
  779. } else {
  780. return nullptr;
  781. }
  782. }
  783. /**
  784. * Returns the default constructor defined for the struct type, or NULL if
  785. * there is no user-declared constructor that takes 0 arguments.
  786. */
  787. CPPInstance *CPPStructType::
  788. get_default_constructor() const {
  789. CPPFunctionGroup *fgroup = get_constructor();
  790. if (fgroup == nullptr) {
  791. return nullptr;
  792. }
  793. CPPFunctionGroup::Instances::const_iterator ii;
  794. for (ii = fgroup->_instances.begin();
  795. ii != fgroup->_instances.end();
  796. ++ii) {
  797. CPPInstance *inst = (*ii);
  798. assert(inst->_type != nullptr);
  799. CPPFunctionType *ftype = inst->_type->as_function_type();
  800. assert(ftype != nullptr);
  801. if (ftype->_parameters->_parameters.size() == 0 ||
  802. ftype->_parameters->_parameters.front()->_initializer != nullptr) {
  803. // It takes 0 parameters (or all parameters have default values).
  804. return inst;
  805. }
  806. }
  807. return nullptr;
  808. }
  809. /**
  810. * Returns the copy constructor defined for the struct type, or NULL if no
  811. * user-declared copy constructor exists.
  812. */
  813. CPPInstance *CPPStructType::
  814. get_copy_constructor() const {
  815. CPPFunctionGroup *fgroup = get_constructor();
  816. if (fgroup == nullptr) {
  817. return nullptr;
  818. }
  819. CPPFunctionGroup::Instances::const_iterator ii;
  820. for (ii = fgroup->_instances.begin();
  821. ii != fgroup->_instances.end();
  822. ++ii) {
  823. CPPInstance *inst = (*ii);
  824. assert(inst->_type != nullptr);
  825. CPPFunctionType *ftype = inst->_type->as_function_type();
  826. assert(ftype != nullptr);
  827. if ((ftype->_flags & CPPFunctionType::F_copy_constructor) != 0) {
  828. return inst;
  829. }
  830. }
  831. return nullptr;
  832. }
  833. /**
  834. * Returns the move constructor defined for the struct type, or NULL if no
  835. * user-declared move constructor exists.
  836. */
  837. CPPInstance *CPPStructType::
  838. get_move_constructor() const {
  839. CPPFunctionGroup *fgroup = get_constructor();
  840. if (fgroup == nullptr) {
  841. return nullptr;
  842. }
  843. CPPFunctionGroup::Instances::const_iterator ii;
  844. for (ii = fgroup->_instances.begin();
  845. ii != fgroup->_instances.end();
  846. ++ii) {
  847. CPPInstance *inst = (*ii);
  848. assert(inst->_type != nullptr);
  849. CPPFunctionType *ftype = inst->_type->as_function_type();
  850. assert(ftype != nullptr);
  851. if ((ftype->_flags & CPPFunctionType::F_move_constructor) != 0) {
  852. return inst;
  853. }
  854. }
  855. return nullptr;
  856. }
  857. /**
  858. * Returns the assignment operator defined for the struct type, if any, or
  859. * NULL if no assignment operator is found.
  860. */
  861. CPPFunctionGroup *CPPStructType::
  862. get_assignment_operator() const {
  863. // Just look for the function with the name "operator ="
  864. CPPScope::Functions::const_iterator fi;
  865. fi = _scope->_functions.find("operator =");
  866. if (fi != _scope->_functions.end()) {
  867. return fi->second;
  868. } else {
  869. return nullptr;
  870. }
  871. }
  872. /**
  873. * Returns the copy assignment operator defined for the struct type, or NULL
  874. * if no user-declared copy assignment operator exists.
  875. */
  876. CPPInstance *CPPStructType::
  877. get_copy_assignment_operator() const {
  878. CPPFunctionGroup *fgroup = get_assignment_operator();
  879. if (fgroup == nullptr) {
  880. return nullptr;
  881. }
  882. CPPFunctionGroup::Instances::const_iterator ii;
  883. for (ii = fgroup->_instances.begin();
  884. ii != fgroup->_instances.end();
  885. ++ii) {
  886. CPPInstance *inst = (*ii);
  887. assert(inst->_type != nullptr);
  888. CPPFunctionType *ftype = inst->_type->as_function_type();
  889. assert(ftype != nullptr);
  890. if ((ftype->_flags & CPPFunctionType::F_copy_assignment_operator) != 0) {
  891. return inst;
  892. }
  893. }
  894. return nullptr;
  895. }
  896. /**
  897. * Returns the move assignment operator defined for the struct type, or NULL
  898. * if no user-declared move assignment operator exists.
  899. */
  900. CPPInstance *CPPStructType::
  901. get_move_assignment_operator() const {
  902. CPPFunctionGroup *fgroup = get_assignment_operator();
  903. if (fgroup == nullptr) {
  904. return nullptr;
  905. }
  906. CPPFunctionGroup::Instances::const_iterator ii;
  907. for (ii = fgroup->_instances.begin();
  908. ii != fgroup->_instances.end();
  909. ++ii) {
  910. CPPInstance *inst = (*ii);
  911. assert(inst->_type != nullptr);
  912. CPPFunctionType *ftype = inst->_type->as_function_type();
  913. assert(ftype != nullptr);
  914. if ((ftype->_flags & CPPFunctionType::F_move_assignment_operator) != 0) {
  915. return inst;
  916. }
  917. }
  918. return nullptr;
  919. }
  920. /**
  921. * Returns the destructor defined for the struct type, if any, or NULL if no
  922. * user-declared destructor is found.
  923. */
  924. CPPInstance *CPPStructType::
  925. get_destructor() const {
  926. // Iterate through all the functions that begin with '~' until we find one
  927. // that claims to be a destructor. In theory, there should only be one such
  928. // function.
  929. CPPScope::Functions::const_iterator fi;
  930. fi = _scope->_functions.lower_bound("~");
  931. while (fi != _scope->_functions.end() &&
  932. (*fi).first[0] == '~') {
  933. CPPFunctionGroup *fgroup = (*fi).second;
  934. CPPFunctionGroup::Instances::const_iterator ii;
  935. for (ii = fgroup->_instances.begin();
  936. ii != fgroup->_instances.end();
  937. ++ii) {
  938. CPPInstance *inst = (*ii);
  939. assert(inst->_type != nullptr);
  940. CPPFunctionType *ftype = inst->_type->as_function_type();
  941. assert(ftype != nullptr);
  942. if ((ftype->_flags & CPPFunctionType::F_destructor) != 0) {
  943. return inst;
  944. }
  945. }
  946. ++fi;
  947. }
  948. return nullptr;
  949. }
  950. /**
  951. *
  952. */
  953. CPPDeclaration *CPPStructType::
  954. instantiate(const CPPTemplateParameterList *actual_params,
  955. CPPScope *current_scope, CPPScope *global_scope,
  956. CPPPreprocessor *error_sink) const {
  957. // I *think* this assertion is no longer valid. Who knows.
  958. // assert(!_incomplete);
  959. if (_scope == nullptr) {
  960. if (error_sink != nullptr) {
  961. error_sink->warning("Ignoring template parameters for class " +
  962. get_local_name());
  963. }
  964. return (CPPDeclaration *)this;
  965. }
  966. CPPScope *scope =
  967. _scope->instantiate(actual_params, current_scope, global_scope, error_sink);
  968. if (scope->get_struct_type()->get_scope() != scope) {
  969. // Hmm, this type seems to be not completely defined. We must be in the
  970. // middle of recursively instantiating the scope. Thus, we don't yet know
  971. // what its associated struct type will be.
  972. // Postpone the evaluation of this type.
  973. CPPIdentifier *ident = new CPPIdentifier(get_fully_scoped_name(), _file);
  974. return CPPType::new_type(new CPPTBDType(ident));
  975. }
  976. CPPType *result = scope->get_struct_type();
  977. result = CPPType::new_type(result);
  978. if (result != (CPPType *)this) {
  979. // This really means the method ought to be non-const. But I'm too lazy
  980. // to propagate this change all the way back right now, so this hack is
  981. // here.
  982. ((CPPStructType *)this)->_instantiations.insert(result);
  983. }
  984. return result;
  985. }
  986. /**
  987. *
  988. */
  989. CPPDeclaration *CPPStructType::
  990. substitute_decl(CPPDeclaration::SubstDecl &subst,
  991. CPPScope *current_scope, CPPScope *global_scope) {
  992. SubstDecl::const_iterator si = subst.find(this);
  993. if (si != subst.end()) {
  994. assert((*si).second != nullptr);
  995. return (*si).second;
  996. }
  997. if (_incomplete) {
  998. // We haven't finished defining the class yet.
  999. return this;
  1000. }
  1001. if (_subst_decl_recursive_protect) {
  1002. // We're already executing this block; we'll have to return a proxy to the
  1003. // type which we'll define later.
  1004. CPPTypeProxy *proxy = new CPPTypeProxy;
  1005. _proxies.push_back(proxy);
  1006. assert(proxy != nullptr);
  1007. return proxy;
  1008. }
  1009. _subst_decl_recursive_protect = true;
  1010. CPPStructType *rep = new CPPStructType(*this);
  1011. if (_ident != nullptr) {
  1012. rep->_ident =
  1013. _ident->substitute_decl(subst, current_scope, global_scope);
  1014. }
  1015. if (_scope != nullptr) {
  1016. rep->_scope =
  1017. _scope->substitute_decl(subst, current_scope, global_scope);
  1018. if (rep->_scope != _scope) {
  1019. rep->_scope->set_struct_type(rep);
  1020. // If we just instantiated a template scope, write the template
  1021. // parameters into our identifier.
  1022. CPPScope *pscope = rep->_scope->get_parent_scope();
  1023. if (pscope != nullptr &&
  1024. pscope->_name.has_templ()) {
  1025. // If the struct name didn't have an explicit template reference
  1026. // before, now it does.
  1027. if (_ident != nullptr && !_ident->_names.empty() && !_ident->_names.back().has_templ()) {
  1028. if (rep->is_template()) {
  1029. rep->_template_scope = nullptr;
  1030. CPPNameComponent nc(get_simple_name());
  1031. nc.set_templ(pscope->_name.get_templ());
  1032. rep->_ident = new CPPIdentifier(nc, _file);
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. bool unchanged =
  1039. (rep->_ident == _ident && rep->_scope == _scope);
  1040. for (int i = 0; i < (int)_derivation.size(); ++i) {
  1041. rep->_derivation[i]._base =
  1042. _derivation[i]._base->substitute_decl(subst, current_scope, global_scope)->as_type();
  1043. if (rep->_derivation[i]._base != _derivation[i]._base) {
  1044. unchanged = false;
  1045. }
  1046. }
  1047. if (unchanged) {
  1048. delete rep;
  1049. rep = this;
  1050. }
  1051. subst.insert(SubstDecl::value_type(this, rep));
  1052. _subst_decl_recursive_protect = false;
  1053. // Now fill in all the proxies we created for our recursive references.
  1054. Proxies::iterator pi;
  1055. for (pi = _proxies.begin(); pi != _proxies.end(); ++pi) {
  1056. (*pi)->_actual_type = rep;
  1057. }
  1058. assert(rep != nullptr);
  1059. rep = CPPType::new_type(rep)->as_struct_type();
  1060. assert(rep != nullptr);
  1061. if (rep != this) {
  1062. _instantiations.insert(rep);
  1063. }
  1064. return rep;
  1065. }
  1066. /**
  1067. *
  1068. */
  1069. void CPPStructType::
  1070. output(std::ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  1071. if (!complete && _ident != nullptr) {
  1072. // If we have a name, use it.
  1073. if (cppparser_output_class_keyword) {
  1074. out << _type << " ";
  1075. }
  1076. out << _ident->get_local_name(scope);
  1077. if (is_template()) {
  1078. CPPTemplateScope *tscope = get_template_scope();
  1079. tscope->_parameters.output(out, scope);
  1080. }
  1081. } else {
  1082. if (is_template()) {
  1083. get_template_scope()->_parameters.write_formal(out, scope);
  1084. indent(out, indent_level);
  1085. }
  1086. if (_ident != nullptr) {
  1087. out << _type << " " << _ident->get_local_name(scope);
  1088. } else {
  1089. out << _type;
  1090. }
  1091. if (_final) {
  1092. out << " final";
  1093. }
  1094. // Show any derivation we may have
  1095. if (!_derivation.empty()) {
  1096. Derivation::const_iterator di = _derivation.begin();
  1097. out << " : " << *di;
  1098. ++di;
  1099. while (di != _derivation.end()) {
  1100. out << ", " << *di;
  1101. ++di;
  1102. }
  1103. }
  1104. out << " {\n";
  1105. _scope->write(out, indent_level + 2, _scope);
  1106. indent(out, indent_level) << "}";
  1107. }
  1108. }
  1109. /**
  1110. *
  1111. */
  1112. CPPDeclaration::SubType CPPStructType::
  1113. get_subtype() const {
  1114. return ST_struct;
  1115. }
  1116. /**
  1117. *
  1118. */
  1119. CPPStructType *CPPStructType::
  1120. as_struct_type() {
  1121. return this;
  1122. }
  1123. /**
  1124. * Fills funcs up with a list of all the virtual function declarations (pure-
  1125. * virtual or otherwise) defined at or above this class. This is used to
  1126. * determine which functions in a given class are actually virtual, since a
  1127. * function is virtual whose parent class holds a virtual function by the same
  1128. * name, whether or not it is actually declared virtual in the derived class.
  1129. */
  1130. void CPPStructType::
  1131. get_virtual_funcs(VFunctions &funcs) const {
  1132. // First, get all the virtual funcs from our parents.
  1133. Derivation::const_iterator di;
  1134. for (di = _derivation.begin(); di != _derivation.end(); ++di) {
  1135. VFunctions vf;
  1136. CPPStructType *base = (*di)._base->as_struct_type();
  1137. if (base != nullptr) {
  1138. base->get_virtual_funcs(vf);
  1139. funcs.splice(funcs.end(), vf);
  1140. }
  1141. }
  1142. // Now look for matching functions in this class that we can now infer are
  1143. // virtual.
  1144. VFunctions::iterator vfi, vfnext;
  1145. vfi = funcs.begin();
  1146. while (vfi != funcs.end()) {
  1147. vfnext = vfi;
  1148. ++vfnext;
  1149. CPPInstance *inst = (*vfi);
  1150. assert(inst->_type != nullptr);
  1151. CPPFunctionType *base_ftype = inst->_type->as_function_type();
  1152. assert(base_ftype != nullptr);
  1153. if (inst->_storage_class & CPPInstance::SC_deleted) {
  1154. // Ignore deleted functions.
  1155. } else if ((base_ftype->_flags & CPPFunctionType::F_destructor) != 0) {
  1156. // Match destructor-for-destructor; don't try to match destructors up by
  1157. // name.
  1158. CPPInstance *destructor = get_destructor();
  1159. if (destructor != nullptr) {
  1160. // It's a match! This destructor is virtual.
  1161. funcs.erase(vfi);
  1162. destructor->_storage_class |=
  1163. (CPPInstance::SC_virtual | CPPInstance::SC_inherited_virtual);
  1164. }
  1165. } else {
  1166. // Non-destructors we can try to match up by name.
  1167. std::string fname = inst->get_local_name();
  1168. CPPScope::Functions::const_iterator fi;
  1169. fi = _scope->_functions.find(fname);
  1170. if (fi != _scope->_functions.end()) {
  1171. CPPFunctionGroup *fgroup = (*fi).second;
  1172. // Look for a matching function amid this group.
  1173. bool match_found = false;
  1174. CPPFunctionGroup::Instances::const_iterator ii;
  1175. for (ii = fgroup->_instances.begin();
  1176. ii != fgroup->_instances.end() && !match_found;
  1177. ++ii) {
  1178. CPPInstance *new_inst = (*ii);
  1179. assert(new_inst->_type != nullptr);
  1180. CPPFunctionType *new_ftype = new_inst->_type->as_function_type();
  1181. assert(new_ftype != nullptr);
  1182. if (new_ftype->match_virtual_override(*base_ftype)) {
  1183. // It's a match! We now know it's virtual. Erase this function
  1184. // from the list, so we can add it back in below.
  1185. funcs.erase(vfi);
  1186. match_found = true;
  1187. // In fact, it's not only definitely virtual, but it's *inherited*
  1188. // virtual, which means only that the interface is defined in some
  1189. // parent class. Sometimes this is useful to know.
  1190. new_inst->_storage_class |=
  1191. (CPPInstance::SC_virtual | CPPInstance::SC_inherited_virtual);
  1192. }
  1193. }
  1194. }
  1195. }
  1196. vfi = vfnext;
  1197. }
  1198. // Finally, look for more virtual function definitions.
  1199. CPPScope::Functions::const_iterator fi;
  1200. for (fi = _scope->_functions.begin();
  1201. fi != _scope->_functions.end();
  1202. ++fi) {
  1203. CPPFunctionGroup *fgroup = (*fi).second;
  1204. CPPFunctionGroup::Instances::const_iterator ii;
  1205. for (ii = fgroup->_instances.begin();
  1206. ii != fgroup->_instances.end();
  1207. ++ii) {
  1208. CPPInstance *inst = (*ii);
  1209. if ((inst->_storage_class & CPPInstance::SC_virtual) != 0 &&
  1210. (inst->_storage_class & CPPInstance::SC_deleted) == 0) {
  1211. // Here's a virtual function.
  1212. funcs.push_back(inst);
  1213. }
  1214. }
  1215. }
  1216. }
  1217. /**
  1218. * Fills funcs up with a list of all the pure virtual function declarations
  1219. * defined at or above this class that have not been given definitions.
  1220. */
  1221. void CPPStructType::
  1222. get_pure_virtual_funcs(VFunctions &funcs) const {
  1223. // First, get all the virtual functions.
  1224. VFunctions vfuncs;
  1225. get_virtual_funcs(vfuncs);
  1226. // Now traverse the list, getting out those functions that are pure virtual.
  1227. VFunctions::iterator vfi;
  1228. for (vfi = vfuncs.begin(); vfi != vfuncs.end(); ++vfi) {
  1229. CPPInstance *inst = (*vfi);
  1230. if ((inst->_storage_class & CPPInstance::SC_pure_virtual) != 0) {
  1231. funcs.push_back(inst);
  1232. }
  1233. }
  1234. }
  1235. /**
  1236. * Called by CPPDeclaration to determine whether this type is equivalent to
  1237. * another type of the same type.
  1238. */
  1239. bool CPPStructType::
  1240. is_equal(const CPPDeclaration *other) const {
  1241. return CPPDeclaration::is_equal(other);
  1242. /*
  1243. const CPPStructType *ot = ((CPPDeclaration *)other)->as_struct_type();
  1244. assert(ot != NULL);
  1245. return this == ot ||
  1246. (get_fully_scoped_name() == ot->get_fully_scoped_name());
  1247. */
  1248. }
  1249. /**
  1250. * Called by CPPDeclaration to determine whether this type should be ordered
  1251. * before another type of the same type, in an arbitrary but fixed ordering.
  1252. */
  1253. bool CPPStructType::
  1254. is_less(const CPPDeclaration *other) const {
  1255. return CPPDeclaration::is_less(other);
  1256. /*
  1257. const CPPStructType *ot = ((CPPDeclaration *)other)->as_struct_type();
  1258. assert(ot != NULL);
  1259. if (this == ot) {
  1260. return false;
  1261. }
  1262. return
  1263. (get_fully_scoped_name() < ot->get_fully_scoped_name());
  1264. */
  1265. }