cppExpression.cxx 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255
  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 cppExpression.cxx
  10. * @author drose
  11. * @date 1999-10-25
  12. */
  13. #include "cppExpression.h"
  14. #include "cppToken.h"
  15. #include "cppIdentifier.h"
  16. #include "cppType.h"
  17. #include "cppSimpleType.h"
  18. #include "cppPointerType.h"
  19. #include "cppEnumType.h"
  20. #include "cppConstType.h"
  21. #include "cppArrayType.h"
  22. #include "cppPreprocessor.h"
  23. #include "cppInstance.h"
  24. #include "cppFunctionGroup.h"
  25. #include "cppFunctionType.h"
  26. #include "cppClosureType.h"
  27. #include "cppStructType.h"
  28. #include "cppBison.h"
  29. #include "pdtoa.h"
  30. #include <assert.h>
  31. /**
  32. *
  33. */
  34. CPPExpression::Result::
  35. Result() {
  36. _type = RT_error;
  37. }
  38. /**
  39. *
  40. */
  41. CPPExpression::Result::
  42. Result(int value) {
  43. _type = RT_integer;
  44. _u._integer = value;
  45. }
  46. /**
  47. *
  48. */
  49. CPPExpression::Result::
  50. Result(double value) {
  51. _type = RT_real;
  52. _u._real = value;
  53. }
  54. /**
  55. *
  56. */
  57. CPPExpression::Result::
  58. Result(void *value) {
  59. _type = RT_pointer;
  60. _u._pointer = value;
  61. }
  62. /**
  63. *
  64. */
  65. int CPPExpression::Result::
  66. as_integer() const {
  67. switch (_type) {
  68. case RT_integer:
  69. return _u._integer;
  70. case RT_real:
  71. return (int)_u._real;
  72. case RT_pointer:
  73. // We don't mind if this loses precision.
  74. return (int)reinterpret_cast<long>(_u._pointer);
  75. default:
  76. cerr << "Invalid type\n";
  77. assert(false);
  78. return 0;
  79. }
  80. }
  81. /**
  82. *
  83. */
  84. double CPPExpression::Result::
  85. as_real() const {
  86. switch (_type) {
  87. case RT_integer:
  88. return (double)_u._integer;
  89. case RT_real:
  90. return _u._real;
  91. case RT_pointer:
  92. // We don't mind if this loses precision.
  93. return (double)reinterpret_cast<long>(_u._pointer);
  94. default:
  95. cerr << "Invalid type\n";
  96. assert(false);
  97. return 0.0;
  98. }
  99. }
  100. /**
  101. *
  102. */
  103. void *CPPExpression::Result::
  104. as_pointer() const {
  105. switch (_type) {
  106. case RT_integer:
  107. return reinterpret_cast<void*>((long)_u._integer);
  108. case RT_real:
  109. return reinterpret_cast<void*>((long)_u._real);
  110. case RT_pointer:
  111. return _u._pointer;
  112. default:
  113. cerr << "Invalid type\n";
  114. assert(false);
  115. return (void *)NULL;
  116. }
  117. }
  118. /**
  119. *
  120. */
  121. bool CPPExpression::Result::
  122. as_boolean() const {
  123. switch (_type) {
  124. case RT_integer:
  125. return (_u._integer != 0);
  126. case RT_real:
  127. return (_u._real != 0.0);
  128. case RT_pointer:
  129. return (_u._pointer != NULL);
  130. default:
  131. cerr << "Invalid type\n";
  132. assert(false);
  133. return false;
  134. }
  135. }
  136. /**
  137. *
  138. */
  139. void CPPExpression::Result::
  140. output(ostream &out) const {
  141. switch (_type) {
  142. case RT_integer:
  143. out << _u._integer;
  144. break;
  145. case RT_real:
  146. out << _u._real;
  147. break;
  148. case RT_pointer:
  149. out << _u._pointer;
  150. break;
  151. case RT_error:
  152. out << "(error)";
  153. break;
  154. default:
  155. out << "(**invalid type**)\n";
  156. }
  157. }
  158. /**
  159. *
  160. */
  161. CPPExpression::
  162. CPPExpression(bool value) :
  163. CPPDeclaration(CPPFile())
  164. {
  165. _type = T_boolean;
  166. _u._boolean = value;
  167. }
  168. /**
  169. *
  170. */
  171. CPPExpression::
  172. CPPExpression(unsigned long long value) :
  173. CPPDeclaration(CPPFile())
  174. {
  175. _type = T_integer;
  176. _u._integer = value;
  177. }
  178. /**
  179. *
  180. */
  181. CPPExpression::
  182. CPPExpression(int value) :
  183. CPPDeclaration(CPPFile())
  184. {
  185. _type = T_integer;
  186. _u._integer = value;
  187. }
  188. /**
  189. *
  190. */
  191. CPPExpression::
  192. CPPExpression(long double value) :
  193. CPPDeclaration(CPPFile())
  194. {
  195. _type = T_real;
  196. _u._real = value;
  197. }
  198. /**
  199. *
  200. */
  201. CPPExpression::
  202. CPPExpression(const string &value) :
  203. CPPDeclaration(CPPFile())
  204. {
  205. _type = T_string;
  206. _str = value;
  207. }
  208. /**
  209. *
  210. */
  211. CPPExpression::
  212. CPPExpression(CPPIdentifier *ident, CPPScope *current_scope,
  213. CPPScope *global_scope, CPPPreprocessor *error_sink) :
  214. CPPDeclaration(CPPFile())
  215. {
  216. CPPDeclaration *decl =
  217. ident->find_symbol(current_scope, global_scope);
  218. if (decl != NULL) {
  219. CPPInstance *inst = decl->as_instance();
  220. if (inst != NULL) {
  221. _type = T_variable;
  222. _u._variable = inst;
  223. return;
  224. }
  225. // Actually, we can't scope function groups.
  226. /*CPPFunctionGroup *fgroup = decl->as_function_group();
  227. if (fgroup != NULL) {
  228. _type = T_function;
  229. _u._fgroup = fgroup;
  230. return;
  231. }*/
  232. }
  233. _type = T_unknown_ident;
  234. _u._ident = ident;
  235. // _u._ident->_native_scope = current_scope;
  236. }
  237. /**
  238. *
  239. */
  240. CPPExpression::
  241. CPPExpression(int unary_operator, CPPExpression *op1) :
  242. CPPDeclaration(CPPFile())
  243. {
  244. _type = T_unary_operation;
  245. _u._op._operator = unary_operator;
  246. _u._op._op1 = op1;
  247. _u._op._op2 = NULL;
  248. _u._op._op3 = NULL;
  249. }
  250. /**
  251. *
  252. */
  253. CPPExpression::
  254. CPPExpression(int binary_operator, CPPExpression *op1, CPPExpression *op2) :
  255. CPPDeclaration(CPPFile())
  256. {
  257. _type = T_binary_operation;
  258. _u._op._operator = binary_operator;
  259. _u._op._op1 = op1;
  260. _u._op._op2 = op2;
  261. _u._op._op3 = NULL;
  262. }
  263. /**
  264. *
  265. */
  266. CPPExpression::
  267. CPPExpression(int trinary_operator, CPPExpression *op1, CPPExpression *op2,
  268. CPPExpression *op3) :
  269. CPPDeclaration(CPPFile())
  270. {
  271. _type = T_trinary_operation;
  272. _u._op._operator = trinary_operator;
  273. _u._op._op1 = op1;
  274. _u._op._op2 = op2;
  275. _u._op._op3 = op3;
  276. }
  277. /**
  278. * Creates an expression that represents a typecast operation.
  279. */
  280. CPPExpression CPPExpression::
  281. typecast_op(CPPType *type, CPPExpression *op1, Type cast_type) {
  282. assert(cast_type >= T_typecast && cast_type <= T_reinterpret_cast);
  283. CPPExpression expr(0);
  284. expr._type = cast_type;
  285. expr._u._typecast._to = type;
  286. expr._u._typecast._op1 = op1;
  287. return expr;
  288. }
  289. /**
  290. * Creates an expression that represents a constructor call.
  291. */
  292. CPPExpression CPPExpression::
  293. construct_op(CPPType *type, CPPExpression *op1) {
  294. CPPExpression expr(0);
  295. if (op1 == NULL) {
  296. // A default constructor call--no parameters.
  297. expr._type = T_default_construct;
  298. expr._u._typecast._to = type;
  299. expr._u._typecast._op1 = NULL;
  300. } else {
  301. // A normal constructor call, with parameters.
  302. expr._type = T_construct;
  303. expr._u._typecast._to = type;
  304. expr._u._typecast._op1 = op1;
  305. }
  306. return expr;
  307. }
  308. /**
  309. * Creates an expression that represents a use of the new operator.
  310. */
  311. CPPExpression CPPExpression::
  312. new_op(CPPType *type, CPPExpression *op1) {
  313. CPPExpression expr(0);
  314. if (op1 == NULL) {
  315. // A default new operation--no parameters.
  316. expr._type = T_default_new;
  317. expr._u._typecast._to = type;
  318. expr._u._typecast._op1 = NULL;
  319. } else {
  320. // A normal new operation, with parameters.
  321. expr._type = T_new;
  322. expr._u._typecast._to = type;
  323. expr._u._typecast._op1 = op1;
  324. }
  325. return expr;
  326. }
  327. /**
  328. * Creates an expression that represents a use of the typeid operator.
  329. */
  330. CPPExpression CPPExpression::
  331. typeid_op(CPPType *type, CPPType *std_type_info) {
  332. CPPExpression expr(0);
  333. expr._type = T_typeid_type;
  334. expr._u._typeid._type = type;
  335. expr._u._typeid._std_type_info = std_type_info;
  336. return expr;
  337. }
  338. /**
  339. * Creates an expression that represents a use of the typeid operator.
  340. */
  341. CPPExpression CPPExpression::
  342. typeid_op(CPPExpression *op1, CPPType *std_type_info) {
  343. CPPExpression expr(0);
  344. expr._type = T_typeid_expr;
  345. expr._u._typeid._expr = op1;
  346. expr._u._typeid._std_type_info = std_type_info;
  347. return expr;
  348. }
  349. /**
  350. * Creates an expression that returns a particular type trait.
  351. */
  352. CPPExpression CPPExpression::
  353. type_trait(int trait, CPPType *type, CPPType *arg) {
  354. CPPExpression expr(0);
  355. expr._type = T_type_trait;
  356. expr._u._type_trait._trait = trait;
  357. expr._u._type_trait._type = type;
  358. expr._u._type_trait._arg = arg;
  359. return expr;
  360. }
  361. /**
  362. *
  363. */
  364. CPPExpression CPPExpression::
  365. sizeof_func(CPPType *type) {
  366. CPPExpression expr(0);
  367. expr._type = T_sizeof;
  368. expr._u._typecast._to = type;
  369. expr._u._typecast._op1 = NULL;
  370. return expr;
  371. }
  372. /**
  373. *
  374. */
  375. CPPExpression CPPExpression::
  376. sizeof_ellipsis_func(CPPIdentifier *ident) {
  377. CPPExpression expr(0);
  378. expr._type = T_sizeof_ellipsis;
  379. expr._u._ident = ident;
  380. return expr;
  381. }
  382. /**
  383. *
  384. */
  385. CPPExpression CPPExpression::
  386. alignof_func(CPPType *type) {
  387. CPPExpression expr(0);
  388. expr._type = T_alignof;
  389. expr._u._typecast._to = type;
  390. expr._u._typecast._op1 = NULL;
  391. return expr;
  392. }
  393. /**
  394. *
  395. */
  396. CPPExpression CPPExpression::
  397. lambda(CPPClosureType *type) {
  398. CPPExpression expr(0);
  399. expr._type = T_lambda;
  400. expr._u._closure_type = type;
  401. return expr;
  402. }
  403. /**
  404. *
  405. */
  406. CPPExpression CPPExpression::
  407. literal(unsigned long long value, CPPInstance *lit_op) {
  408. CPPExpression expr(0);
  409. expr._type = T_literal;
  410. expr._u._literal._value = new CPPExpression(value);
  411. expr._u._literal._operator = lit_op;
  412. return expr;
  413. }
  414. /**
  415. *
  416. */
  417. CPPExpression CPPExpression::
  418. literal(long double value, CPPInstance *lit_op) {
  419. CPPExpression expr(0);
  420. expr._type = T_literal;
  421. expr._u._literal._value = new CPPExpression(value);
  422. expr._u._literal._operator = lit_op;
  423. return expr;
  424. }
  425. /**
  426. *
  427. */
  428. CPPExpression CPPExpression::
  429. literal(CPPExpression *value, CPPInstance *lit_op) {
  430. CPPExpression expr(0);
  431. expr._type = T_literal;
  432. expr._u._literal._value = value;
  433. expr._u._literal._operator = lit_op;
  434. return expr;
  435. }
  436. /**
  437. *
  438. */
  439. CPPExpression CPPExpression::
  440. raw_literal(const string &raw, CPPInstance *lit_op) {
  441. CPPExpression expr(0);
  442. expr._type = T_raw_literal;
  443. expr._str = raw;
  444. expr._u._literal._value = (CPPExpression *)NULL;
  445. expr._u._literal._operator = lit_op;
  446. return expr;
  447. }
  448. /**
  449. *
  450. */
  451. const CPPExpression &CPPExpression::
  452. get_nullptr() {
  453. static CPPExpression expr(0);
  454. expr._type = T_nullptr;
  455. return expr;
  456. }
  457. /**
  458. *
  459. */
  460. const CPPExpression &CPPExpression::
  461. get_default() {
  462. static CPPExpression expr(0);
  463. expr._type = T_default;
  464. return expr;
  465. }
  466. /**
  467. *
  468. */
  469. const CPPExpression &CPPExpression::
  470. get_delete() {
  471. static CPPExpression expr(0);
  472. expr._type = T_delete;
  473. return expr;
  474. }
  475. /**
  476. *
  477. */
  478. CPPExpression::Result CPPExpression::
  479. evaluate() const {
  480. Result r1, r2;
  481. switch (_type) {
  482. case T_nullptr:
  483. return Result((void *)0);
  484. case T_boolean:
  485. return Result((int)_u._boolean);
  486. case T_integer:
  487. return Result((int)_u._integer);
  488. case T_real:
  489. return Result((double)_u._real);
  490. case T_string:
  491. case T_wstring:
  492. case T_u8string:
  493. case T_u16string:
  494. case T_u32string:
  495. return Result();
  496. case T_variable:
  497. if (_u._variable->_type != NULL &&
  498. _u._variable->_initializer != NULL) {
  499. // A constexpr variable, which is treated as const.
  500. if (_u._variable->_storage_class & CPPInstance::SC_constexpr) {
  501. return _u._variable->_initializer->evaluate();
  502. }
  503. // A const variable. Fetch its assigned value.
  504. CPPConstType *const_type = _u._variable->_type->as_const_type();
  505. if (const_type != NULL) {
  506. return _u._variable->_initializer->evaluate();
  507. }
  508. }
  509. return Result();
  510. case T_function:
  511. return Result();
  512. case T_unknown_ident:
  513. return Result();
  514. case T_typecast:
  515. case T_static_cast:
  516. case T_dynamic_cast:
  517. case T_const_cast:
  518. case T_reinterpret_cast:
  519. assert(_u._typecast._op1 != NULL);
  520. r1 = _u._typecast._op1->evaluate();
  521. if (r1._type != RT_error) {
  522. CPPSimpleType *stype = _u._typecast._to->as_simple_type();
  523. if (stype != NULL) {
  524. if (stype->_type == CPPSimpleType::T_bool) {
  525. return Result(r1.as_boolean());
  526. } else if (stype->_type == CPPSimpleType::T_int) {
  527. return Result(r1.as_integer());
  528. } else if (stype->_type == CPPSimpleType::T_float ||
  529. stype->_type == CPPSimpleType::T_double) {
  530. return Result(r1.as_real());
  531. }
  532. }
  533. if (_u._typecast._to->as_pointer_type()) {
  534. return Result(r1.as_pointer());
  535. }
  536. }
  537. return Result();
  538. case T_construct:
  539. case T_default_construct:
  540. case T_new:
  541. case T_default_new:
  542. case T_sizeof:
  543. case T_sizeof_ellipsis:
  544. return Result();
  545. case T_alignof:
  546. if (_u._typecast._to != NULL) {
  547. // Check if the type is defined with an alignas. TODO: this should
  548. // probably be moved to a virtual getter on CPPType.
  549. CPPExtensionType *etype = _u._typecast._to->as_extension_type();
  550. if (etype != NULL && etype->_alignment != NULL) {
  551. return etype->_alignment->evaluate();
  552. }
  553. }
  554. return Result();
  555. case T_binary_operation:
  556. assert(_u._op._op2 != NULL);
  557. r2 = _u._op._op2->evaluate();
  558. // The operators && and || are special cases: these are shirt-circuiting
  559. // operators. Thus, if we are using either of these it might be
  560. // acceptable for the second operand to be invalid, since we might never
  561. // evaluate it.
  562. // In all other cases, both operands must be valid in order for the
  563. // operation to be valid.
  564. if (r2._type == RT_error &&
  565. (_u._op._operator != OROR && _u._op._operator != ANDAND)) {
  566. return r2;
  567. }
  568. // Fall through
  569. case T_trinary_operation:
  570. // The trinary operator is also a short-circuiting operator: we don't test
  571. // the second or third operands until we need them. The only critical one
  572. // is the first operand.
  573. // Fall through
  574. case T_unary_operation:
  575. assert(_u._op._op1 != NULL);
  576. r1 = _u._op._op1->evaluate();
  577. if (r1._type == RT_error) {
  578. // Here's one more special case: if the first operand is invalid, it
  579. // really means we don't know how to evaluate it. However, if the
  580. // operator is ||, then it might not matter as long as we can evaluate
  581. // the second one *and* that comes out to be true.
  582. if (_u._op._operator == OROR && r2._type == RT_integer &&
  583. r2.as_boolean()) {
  584. return r2;
  585. }
  586. // Ditto for the operator being && and the second one coming out false.
  587. if (_u._op._operator == ANDAND && r2._type == RT_integer &&
  588. !r2.as_boolean()) {
  589. return r2;
  590. }
  591. // Also for the operator being [] and the operand being a string.
  592. if (_u._op._operator == '[' && r2._type == RT_integer &&
  593. (_u._op._op1->_type == T_string ||
  594. _u._op._op1->_type == T_u8string)) {
  595. int index = (int)r2.as_integer();
  596. if ((size_t)index == _u._op._op1->_str.size()) {
  597. return Result(0);
  598. } else if (index >= 0 && (size_t)index < _u._op._op1->_str.size()) {
  599. return Result(_u._op._op1->_str[(size_t)index]);
  600. } else {
  601. cerr << "array index " << index << " out of bounds of string literal "
  602. << *_u._op._op1 << "\n";
  603. }
  604. }
  605. return r1;
  606. }
  607. switch (_u._op._operator) {
  608. case UNARY_NOT:
  609. return Result(!r1.as_boolean());
  610. case UNARY_NEGATE:
  611. return Result(~r1.as_integer());
  612. case UNARY_MINUS:
  613. return (r1._type == RT_real) ? Result(-r1.as_real()) : Result(-r1.as_integer());
  614. case UNARY_PLUS:
  615. return r1;
  616. case UNARY_STAR:
  617. case UNARY_REF:
  618. return Result();
  619. case '*':
  620. if (r1._type == RT_real || r2._type == RT_real) {
  621. return Result(r1.as_real() * r2.as_real());
  622. } else {
  623. return Result(r1.as_integer() * r2.as_integer());
  624. }
  625. case '/':
  626. if (r1._type == RT_real || r2._type == RT_real) {
  627. return Result(r1.as_real() / r2.as_real());
  628. } else {
  629. return Result(r1.as_integer() / r2.as_integer());
  630. }
  631. case '%':
  632. return Result(r1.as_integer() % r2.as_integer());
  633. case '+':
  634. if (r1._type == RT_real || r2._type == RT_real) {
  635. return Result(r1.as_real() + r2.as_real());
  636. } else {
  637. return Result(r1.as_integer() + r2.as_integer());
  638. }
  639. case '-':
  640. if (r1._type == RT_real || r2._type == RT_real) {
  641. return Result(r1.as_real() - r2.as_real());
  642. } else {
  643. return Result(r1.as_integer() - r2.as_integer());
  644. }
  645. case '|':
  646. return Result(r1.as_integer() | r2.as_integer());
  647. case '&':
  648. return Result(r1.as_integer() & r2.as_integer());
  649. case OROR:
  650. if (r1.as_boolean()) {
  651. return r1;
  652. } else {
  653. return r2;
  654. }
  655. case ANDAND:
  656. if (r1.as_boolean()) {
  657. return r2;
  658. } else {
  659. return r1;
  660. }
  661. case EQCOMPARE:
  662. if (r1._type == RT_real || r2._type == RT_real) {
  663. return Result(r1.as_real() == r2.as_real());
  664. } else {
  665. return Result(r1.as_integer() == r2.as_integer());
  666. }
  667. case NECOMPARE:
  668. if (r1._type == RT_real || r2._type == RT_real) {
  669. return Result(r1.as_real() != r2.as_real());
  670. } else {
  671. return Result(r1.as_integer() != r2.as_integer());
  672. }
  673. case LECOMPARE:
  674. if (r1._type == RT_real || r2._type == RT_real) {
  675. return Result(r1.as_real() <= r2.as_real());
  676. } else {
  677. return Result(r1.as_integer() <= r2.as_integer());
  678. }
  679. case GECOMPARE:
  680. if (r1._type == RT_real || r2._type == RT_real) {
  681. return Result(r1.as_real() >= r2.as_real());
  682. } else {
  683. return Result(r1.as_integer() >= r2.as_integer());
  684. }
  685. case '<':
  686. if (r1._type == RT_real || r2._type == RT_real) {
  687. return Result(r1.as_real() < r2.as_real());
  688. } else {
  689. return Result(r1.as_integer() < r2.as_integer());
  690. }
  691. case '>':
  692. if (r1._type == RT_real || r2._type == RT_real) {
  693. return Result(r1.as_real() > r2.as_real());
  694. } else {
  695. return Result(r1.as_integer() > r2.as_integer());
  696. }
  697. case LSHIFT:
  698. return Result(r1.as_integer() << r2.as_integer());
  699. case RSHIFT:
  700. return Result(r1.as_integer() >> r2.as_integer());
  701. case '?':
  702. return r1.as_integer() ?
  703. _u._op._op2->evaluate() : _u._op._op3->evaluate();
  704. case '.':
  705. case POINTSAT:
  706. return Result();
  707. case '[': // Array element reference
  708. return Result();
  709. case 'f': // Function evaluation
  710. return Result();
  711. case ',':
  712. return r2;
  713. default:
  714. cerr << "**unexpected operator**\n";
  715. abort();
  716. }
  717. case T_literal:
  718. case T_raw_literal:
  719. return Result();
  720. case T_typeid_type:
  721. case T_typeid_expr:
  722. return Result();
  723. case T_type_trait:
  724. switch (_u._type_trait._trait) {
  725. case KW_HAS_VIRTUAL_DESTRUCTOR:
  726. {
  727. CPPStructType *struct_type = _u._type_trait._type->as_struct_type();
  728. return Result(struct_type != NULL && struct_type->has_virtual_destructor());
  729. }
  730. case KW_IS_ABSTRACT:
  731. {
  732. CPPStructType *struct_type = _u._type_trait._type->as_struct_type();
  733. return Result(struct_type != NULL && struct_type->is_abstract());
  734. }
  735. case KW_IS_BASE_OF:
  736. {
  737. CPPStructType *struct_type1 = _u._type_trait._type->as_struct_type();
  738. CPPStructType *struct_type2 = _u._type_trait._arg->as_struct_type();
  739. return Result(struct_type1 != NULL && struct_type2 != NULL && struct_type1->is_base_of(struct_type2));
  740. }
  741. case KW_IS_CLASS:
  742. {
  743. CPPExtensionType *ext_type = _u._type_trait._type->as_extension_type();
  744. return Result(ext_type != NULL && (
  745. ext_type->_type == CPPExtensionType::T_class ||
  746. ext_type->_type == CPPExtensionType::T_struct));
  747. }
  748. case KW_IS_CONSTRUCTIBLE:
  749. if (_u._type_trait._arg == NULL) {
  750. return Result(_u._type_trait._type->is_default_constructible());
  751. } else {
  752. return Result(_u._type_trait._type->is_constructible(_u._type_trait._arg));
  753. }
  754. case KW_IS_CONVERTIBLE_TO:
  755. assert(_u._type_trait._arg != NULL);
  756. return Result(_u._type_trait._type->is_convertible_to(_u._type_trait._arg));
  757. case KW_IS_DESTRUCTIBLE:
  758. return Result(_u._type_trait._type->is_destructible());
  759. case KW_IS_EMPTY:
  760. {
  761. CPPStructType *struct_type = _u._type_trait._type->as_struct_type();
  762. return Result(struct_type != NULL && struct_type->is_empty());
  763. }
  764. case KW_IS_ENUM:
  765. return Result(_u._type_trait._type->is_enum());
  766. case KW_IS_FINAL:
  767. {
  768. CPPStructType *struct_type = _u._type_trait._type->as_struct_type();
  769. return Result(struct_type != NULL && struct_type->is_final());
  770. }
  771. case KW_IS_FUNDAMENTAL:
  772. return Result(_u._type_trait._type->is_fundamental());
  773. case KW_IS_POD:
  774. return Result(_u._type_trait._type->is_trivial() &&
  775. _u._type_trait._type->is_standard_layout());
  776. case KW_IS_POLYMORPHIC:
  777. {
  778. CPPStructType *struct_type = _u._type_trait._type->as_struct_type();
  779. return Result(struct_type != NULL && struct_type->is_polymorphic());
  780. }
  781. case KW_IS_STANDARD_LAYOUT:
  782. return Result(_u._type_trait._type->is_standard_layout());
  783. case KW_IS_TRIVIAL:
  784. return Result(_u._type_trait._type->is_trivial());
  785. case KW_IS_UNION:
  786. {
  787. CPPExtensionType *ext_type = _u._type_trait._type->as_extension_type();
  788. return Result(ext_type != NULL &&
  789. ext_type->_type == CPPExtensionType::T_union);
  790. }
  791. default:
  792. cerr << "**unexpected type trait**\n";
  793. abort();
  794. }
  795. default:
  796. cerr << "**invalid operand**\n";
  797. abort();
  798. }
  799. return Result(); // Compiler kludge; can't get here.
  800. }
  801. /**
  802. * Returns the type of the expression, if it is known, or NULL if the type
  803. * cannot be determined.
  804. */
  805. CPPType *CPPExpression::
  806. determine_type() const {
  807. CPPType *t1 = (CPPType *)NULL;
  808. CPPType *t2 = (CPPType *)NULL;
  809. static CPPType *nullptr_type =
  810. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_nullptr));
  811. static CPPType *int_type =
  812. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int));
  813. static CPPType *unsigned_long_type =
  814. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
  815. CPPSimpleType::F_unsigned |
  816. CPPSimpleType::F_long));
  817. static CPPType *bool_type =
  818. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_bool));
  819. static CPPType *float_type =
  820. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_double));
  821. static CPPType *char_type =
  822. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char));
  823. static CPPType *wchar_type =
  824. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_wchar_t));
  825. static CPPType *char16_type =
  826. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char16_t));
  827. static CPPType *char32_type =
  828. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char32_t));
  829. static CPPType *char_str_type = CPPType::new_type(
  830. new CPPPointerType(CPPType::new_type(new CPPConstType(char_type))));
  831. static CPPType *wchar_str_type = CPPType::new_type(
  832. new CPPPointerType(CPPType::new_type(new CPPConstType(wchar_type))));
  833. static CPPType *char16_str_type = CPPType::new_type(
  834. new CPPPointerType(CPPType::new_type(new CPPConstType(char16_type))));
  835. static CPPType *char32_str_type = CPPType::new_type(
  836. new CPPPointerType(CPPType::new_type(new CPPConstType(char32_type))));
  837. switch (_type) {
  838. case T_nullptr:
  839. return nullptr_type;
  840. case T_boolean:
  841. return bool_type;
  842. case T_integer:
  843. return int_type;
  844. case T_real:
  845. return float_type;
  846. case T_string:
  847. return char_str_type;
  848. case T_wstring:
  849. return wchar_str_type;
  850. case T_u8string:
  851. return char_str_type;
  852. case T_u16string:
  853. return char16_str_type;
  854. case T_u32string:
  855. return char32_str_type;
  856. case T_variable:
  857. return _u._variable->_type;
  858. case T_function:
  859. if (_u._fgroup->get_return_type() == (CPPType *)NULL) {
  860. // There are multiple functions by this name that have different return
  861. // types. We could attempt to differentiate them based on the parameter
  862. // list, but that's a lot of work. Let's just give up.
  863. return (CPPType *)NULL;
  864. }
  865. return _u._fgroup->_instances.front()->_type;
  866. case T_unknown_ident:
  867. return (CPPType *)NULL;
  868. case T_typecast:
  869. case T_static_cast:
  870. case T_dynamic_cast:
  871. case T_const_cast:
  872. case T_reinterpret_cast:
  873. case T_construct:
  874. case T_default_construct:
  875. return _u._typecast._to;
  876. case T_new:
  877. case T_default_new:
  878. return CPPType::new_type(new CPPPointerType(_u._typecast._to));
  879. case T_sizeof:
  880. case T_sizeof_ellipsis:
  881. case T_alignof:
  882. // Note: this should actually be size_t, but that is defined as a typedef
  883. // in parser-inc. We could try to resolve it, but that's hacky. Eh, it's
  884. // probably not worth the effort to get this right.
  885. return unsigned_long_type;
  886. case T_binary_operation:
  887. case T_trinary_operation:
  888. assert(_u._op._op2 != NULL);
  889. t2 = _u._op._op2->determine_type();
  890. // Fall through
  891. case T_unary_operation:
  892. assert(_u._op._op1 != NULL);
  893. t1 = _u._op._op1->determine_type();
  894. switch (_u._op._operator) {
  895. case UNARY_NOT:
  896. return bool_type;
  897. case UNARY_NEGATE:
  898. return int_type;
  899. case UNARY_MINUS:
  900. case UNARY_PLUS:
  901. if (t1 != NULL) {
  902. switch (t1->get_subtype()) {
  903. case CPPDeclaration::ST_array:
  904. // Decay into pointer.
  905. return CPPType::new_type(new CPPPointerType(t1->as_array_type()->_element_type));
  906. case CPPDeclaration::ST_enum:
  907. // Convert into integral type.
  908. return t1->as_enum_type()->get_underlying_type();
  909. case CPPDeclaration::ST_simple:
  910. {
  911. CPPSimpleType *simple_type = t1->as_simple_type();
  912. if ((simple_type->_flags & CPPSimpleType::F_short) != 0 ||
  913. simple_type->_type == CPPSimpleType::T_bool ||
  914. simple_type->_type == CPPSimpleType::T_wchar_t ||
  915. simple_type->_type == CPPSimpleType::T_char16_t) {
  916. // Integer promotion.
  917. return int_type;
  918. }
  919. }
  920. // Fall through.
  921. default:
  922. return t1;
  923. }
  924. }
  925. return NULL;
  926. case UNARY_STAR:
  927. case '[': // Array element reference
  928. if (t1 != NULL) {
  929. if (t1->as_pointer_type()) {
  930. return t1->as_pointer_type()->_pointing_at;
  931. }
  932. if (t1->as_array_type()) {
  933. return t1->as_array_type()->_element_type;
  934. }
  935. }
  936. return NULL;
  937. case UNARY_REF:
  938. return t1;
  939. case '*':
  940. case '/':
  941. case '+':
  942. case '-':
  943. if (t1 == NULL) {
  944. return t2;
  945. } else if (t2 == NULL) {
  946. return t1;
  947. } else if (t1->as_pointer_type()) {
  948. if (t2->as_pointer_type()) {
  949. return int_type;
  950. }
  951. return t1;
  952. }
  953. return elevate_type(t1, t2);
  954. case '%':
  955. case '|':
  956. case '&':
  957. case LSHIFT:
  958. case RSHIFT:
  959. return int_type;
  960. case OROR:
  961. case ANDAND:
  962. case EQCOMPARE:
  963. case NECOMPARE:
  964. case LECOMPARE:
  965. case GECOMPARE:
  966. case '<':
  967. case '>':
  968. return bool_type;
  969. case '?':
  970. return t2;
  971. case '.':
  972. case POINTSAT:
  973. return NULL;
  974. case 'f': // Function evaluation
  975. if (t1 != NULL) {
  976. CPPFunctionType *ftype = t1->as_function_type();
  977. if (ftype != (CPPFunctionType *)NULL) {
  978. return ftype->_return_type;
  979. }
  980. }
  981. return NULL;
  982. case ',':
  983. return t2;
  984. default:
  985. cerr << "**unexpected operator**\n";
  986. abort();
  987. }
  988. case T_literal:
  989. case T_raw_literal:
  990. if (_u._literal._operator != NULL) {
  991. CPPType *type = _u._literal._operator->_type;
  992. CPPFunctionType *ftype = type->as_function_type();
  993. if (ftype != (CPPFunctionType *)NULL) {
  994. return ftype->_return_type;
  995. }
  996. }
  997. return NULL;
  998. case T_typeid_type:
  999. case T_typeid_expr:
  1000. return _u._typeid._std_type_info;
  1001. case T_type_trait:
  1002. return bool_type;
  1003. case T_lambda:
  1004. return _u._closure_type;
  1005. default:
  1006. cerr << "**invalid operand**\n";
  1007. abort();
  1008. }
  1009. return NULL; // Compiler kludge; can't get here.
  1010. }
  1011. /**
  1012. * Returns true if this declaration is an actual, factual declaration, or
  1013. * false if some part of the declaration depends on a template parameter which
  1014. * has not yet been instantiated.
  1015. */
  1016. bool CPPExpression::
  1017. is_fully_specified() const {
  1018. if (!CPPDeclaration::is_fully_specified()) {
  1019. return false;
  1020. }
  1021. switch (_type) {
  1022. case T_nullptr:
  1023. case T_boolean:
  1024. case T_integer:
  1025. case T_real:
  1026. case T_string:
  1027. case T_wstring:
  1028. case T_u8string:
  1029. case T_u16string:
  1030. case T_u32string:
  1031. return false;
  1032. case T_variable:
  1033. return _u._variable->is_fully_specified();
  1034. case T_function:
  1035. return _u._fgroup->is_fully_specified();
  1036. case T_unknown_ident:
  1037. return _u._ident->is_fully_specified();
  1038. case T_typecast:
  1039. case T_static_cast:
  1040. case T_dynamic_cast:
  1041. case T_const_cast:
  1042. case T_reinterpret_cast:
  1043. case T_construct:
  1044. case T_new:
  1045. return (_u._typecast._to->is_fully_specified() &&
  1046. _u._typecast._op1->is_fully_specified());
  1047. case T_default_construct:
  1048. case T_default_new:
  1049. case T_sizeof:
  1050. case T_alignof:
  1051. return _u._typecast._to->is_fully_specified();
  1052. case T_sizeof_ellipsis:
  1053. return _u._ident->is_fully_specified();
  1054. case T_trinary_operation:
  1055. if (!_u._op._op3->is_fully_specified()) {
  1056. return false;
  1057. }
  1058. // Fall through
  1059. case T_binary_operation:
  1060. if (!_u._op._op2->is_fully_specified()) {
  1061. return false;
  1062. }
  1063. // Fall through
  1064. case T_unary_operation:
  1065. return _u._op._op1->is_fully_specified();
  1066. case T_literal:
  1067. return _u._literal._value->is_fully_specified() &&
  1068. _u._literal._operator->is_fully_specified();
  1069. case T_raw_literal:
  1070. return _u._literal._value->is_fully_specified();
  1071. case T_typeid_type:
  1072. return _u._typeid._type->is_fully_specified();
  1073. case T_typeid_expr:
  1074. return _u._typeid._expr->is_fully_specified();
  1075. case T_type_trait:
  1076. return _u._type_trait._type->is_fully_specified();
  1077. case T_lambda:
  1078. return _u._closure_type->is_fully_specified();
  1079. default:
  1080. return true;
  1081. }
  1082. }
  1083. /**
  1084. *
  1085. */
  1086. CPPDeclaration *CPPExpression::
  1087. substitute_decl(CPPDeclaration::SubstDecl &subst,
  1088. CPPScope *current_scope, CPPScope *global_scope) {
  1089. CPPDeclaration *top =
  1090. CPPDeclaration::substitute_decl(subst, current_scope, global_scope);
  1091. if (top != this) {
  1092. return top;
  1093. }
  1094. CPPExpression *rep = new CPPExpression(*this);
  1095. bool any_changed = false;
  1096. CPPDeclaration *decl;
  1097. switch (_type) {
  1098. case T_variable:
  1099. decl = _u._variable->substitute_decl(subst, current_scope, global_scope);
  1100. if (decl != rep->_u._variable) {
  1101. if (decl->as_instance()) {
  1102. // Replacing the variable reference with another variable reference.
  1103. rep->_u._variable = decl->as_instance();
  1104. any_changed = true;
  1105. } else if (decl->as_expression()) {
  1106. // Replacing the variable reference with an expression.
  1107. delete rep;
  1108. rep = decl->as_expression();
  1109. any_changed = true;
  1110. }
  1111. }
  1112. break;
  1113. case T_unknown_ident:
  1114. rep->_u._ident = _u._ident->substitute_decl(subst, current_scope, global_scope);
  1115. any_changed = any_changed || (rep->_u._ident != _u._ident);
  1116. // See if we can define it now.
  1117. decl = rep->_u._ident->find_symbol(current_scope, global_scope, subst);
  1118. if (decl != NULL) {
  1119. CPPInstance *inst = decl->as_instance();
  1120. if (inst != NULL) {
  1121. rep->_type = T_variable;
  1122. rep->_u._variable = inst;
  1123. any_changed = true;
  1124. decl = inst->substitute_decl(subst, current_scope, global_scope);
  1125. if (decl != inst) {
  1126. if (decl->as_instance()) {
  1127. // Replacing the variable reference with another variable
  1128. // reference.
  1129. rep->_u._variable = decl->as_instance();
  1130. } else if (decl->as_expression()) {
  1131. // Replacing the variable reference with an expression.
  1132. delete rep;
  1133. rep = decl->as_expression();
  1134. }
  1135. }
  1136. break;
  1137. }
  1138. CPPFunctionGroup *fgroup = decl->as_function_group();
  1139. if (fgroup != NULL) {
  1140. rep->_type = T_function;
  1141. rep->_u._fgroup = fgroup;
  1142. any_changed = true;
  1143. }
  1144. }
  1145. break;
  1146. case T_typecast:
  1147. case T_static_cast:
  1148. case T_dynamic_cast:
  1149. case T_const_cast:
  1150. case T_reinterpret_cast:
  1151. case T_construct:
  1152. case T_new:
  1153. rep->_u._typecast._op1 =
  1154. _u._typecast._op1->substitute_decl(subst, current_scope, global_scope)
  1155. ->as_expression();
  1156. any_changed = any_changed || (rep->_u._typecast._op1 != _u._typecast._op1);
  1157. // fall through
  1158. case T_default_construct:
  1159. case T_default_new:
  1160. case T_sizeof:
  1161. case T_alignof:
  1162. rep->_u._typecast._to =
  1163. _u._typecast._to->substitute_decl(subst, current_scope, global_scope)
  1164. ->as_type();
  1165. any_changed = any_changed || (rep->_u._typecast._to != _u._typecast._to);
  1166. break;
  1167. case T_trinary_operation:
  1168. rep->_u._op._op3 =
  1169. _u._op._op3->substitute_decl(subst, current_scope, global_scope)
  1170. ->as_expression();
  1171. any_changed = any_changed || (rep->_u._op._op3 != _u._op._op3);
  1172. // fall through
  1173. case T_binary_operation:
  1174. rep->_u._op._op2 =
  1175. _u._op._op2->substitute_decl(subst, current_scope, global_scope)
  1176. ->as_expression();
  1177. any_changed = any_changed || (rep->_u._op._op2 != _u._op._op2);
  1178. // fall through
  1179. case T_unary_operation:
  1180. rep->_u._op._op1 =
  1181. _u._op._op1->substitute_decl(subst, current_scope, global_scope)
  1182. ->as_expression();
  1183. any_changed = any_changed || (rep->_u._op._op1 != _u._op._op1);
  1184. break;
  1185. case T_typeid_type:
  1186. rep->_u._typeid._type =
  1187. _u._typeid._type->substitute_decl(subst, current_scope, global_scope)
  1188. ->as_type();
  1189. any_changed = any_changed || (rep->_u._typeid._type != _u._typeid._type);
  1190. break;
  1191. case T_typeid_expr:
  1192. rep->_u._typeid._expr =
  1193. _u._typeid._expr->substitute_decl(subst, current_scope, global_scope)
  1194. ->as_expression();
  1195. any_changed = any_changed || (rep->_u._typeid._expr != _u._typeid._expr);
  1196. break;
  1197. case T_type_trait:
  1198. rep->_u._type_trait._type =
  1199. _u._type_trait._type->substitute_decl(subst, current_scope, global_scope)
  1200. ->as_type();
  1201. any_changed = any_changed || (rep->_u._type_trait._type != _u._type_trait._type);
  1202. break;
  1203. default:
  1204. break;
  1205. }
  1206. if (!any_changed) {
  1207. delete rep;
  1208. rep = this;
  1209. }
  1210. subst.insert(SubstDecl::value_type(this, rep));
  1211. return rep;
  1212. }
  1213. /**
  1214. * Returns true if any type within the expression list is a CPPTBDType and
  1215. * thus isn't fully determined right now.
  1216. */
  1217. bool CPPExpression::
  1218. is_tbd() const {
  1219. switch (_type) {
  1220. case T_variable:
  1221. if (_u._variable->_type != NULL &&
  1222. _u._variable->_initializer != NULL) {
  1223. if (_u._variable->_storage_class & CPPInstance::SC_constexpr) {
  1224. return false;
  1225. }
  1226. CPPConstType *const_type = _u._variable->_type->as_const_type();
  1227. if (const_type != NULL) {
  1228. return false;
  1229. }
  1230. }
  1231. return true;
  1232. case T_unknown_ident:
  1233. return true;
  1234. case T_typecast:
  1235. case T_static_cast:
  1236. case T_dynamic_cast:
  1237. case T_const_cast:
  1238. case T_reinterpret_cast:
  1239. case T_construct:
  1240. case T_new:
  1241. case T_default_construct:
  1242. case T_default_new:
  1243. case T_sizeof:
  1244. case T_alignof:
  1245. return _u._typecast._to->is_tbd();
  1246. case T_trinary_operation:
  1247. if (_u._op._op3->is_tbd()) {
  1248. return true;
  1249. }
  1250. // fall through
  1251. case T_binary_operation:
  1252. if (_u._op._op2->is_tbd()) {
  1253. return true;
  1254. }
  1255. // fall through
  1256. case T_unary_operation:
  1257. if (_u._op._op1->is_tbd()) {
  1258. return true;
  1259. }
  1260. return false;
  1261. case T_typeid_type:
  1262. return _u._typeid._type->is_tbd();
  1263. case T_typeid_expr:
  1264. return _u._typeid._expr->is_tbd();
  1265. case T_type_trait:
  1266. return _u._type_trait._type->is_tbd();
  1267. case T_lambda:
  1268. return _u._closure_type->is_tbd();
  1269. default:
  1270. return false;
  1271. }
  1272. }
  1273. /**
  1274. *
  1275. */
  1276. void CPPExpression::
  1277. output(ostream &out, int indent_level, CPPScope *scope, bool) const {
  1278. switch (_type) {
  1279. case T_nullptr:
  1280. out << "nullptr";
  1281. break;
  1282. case T_boolean:
  1283. out << (_u._boolean ? "true" : "false");
  1284. break;
  1285. case T_integer:
  1286. out << _u._integer;
  1287. break;
  1288. case T_real:
  1289. {
  1290. // We use our own dtoa implementation here because it guarantees to
  1291. // never format the number as an integer.
  1292. char buffer[32];
  1293. pdtoa(_u._real, buffer);
  1294. out << buffer;
  1295. }
  1296. break;
  1297. case T_string:
  1298. case T_wstring:
  1299. case T_u8string:
  1300. case T_u16string:
  1301. case T_u32string:
  1302. {
  1303. switch (_type) {
  1304. case T_wstring:
  1305. out << 'L';
  1306. break;
  1307. case T_u8string:
  1308. out << "u8";
  1309. break;
  1310. case T_u16string:
  1311. out << "u";
  1312. break;
  1313. case T_u32string:
  1314. out << "U";
  1315. break;
  1316. default:
  1317. break;
  1318. }
  1319. // We don't really care about preserving the encoding for now.
  1320. out << '"';
  1321. string::const_iterator si;
  1322. for (si = _str.begin(); si != _str.end(); ++si) {
  1323. switch (*si) {
  1324. case '\n':
  1325. out << "\\n";
  1326. break;
  1327. case '\t':
  1328. out << "\\t";
  1329. break;
  1330. case '\r':
  1331. out << "\\r";
  1332. break;
  1333. case '\a':
  1334. out << "\\a";
  1335. break;
  1336. case '"':
  1337. out << "\\\"";
  1338. break;
  1339. case '\\':
  1340. out << "\\\\";
  1341. break;
  1342. default:
  1343. if (isprint(*si)) {
  1344. out << *si;
  1345. } else {
  1346. out << '\\' << oct << setw(3) << setfill('0') << (int)(*si)
  1347. << dec << setw(0);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. out << '"';
  1353. break;
  1354. case T_variable:
  1355. // We can just refer to the variable by name, except if it's a private
  1356. // constant, in which case we have to compute the value, since we may have
  1357. // to use it in generated code.
  1358. if (_u._variable->_type != NULL &&
  1359. _u._variable->_initializer != NULL &&
  1360. _u._variable->_vis > V_public) {
  1361. // A constexpr or const variable. Fetch its assigned value.
  1362. CPPConstType *const_type = _u._variable->_type->as_const_type();
  1363. if ((_u._variable->_storage_class & CPPInstance::SC_constexpr) != 0 ||
  1364. const_type != NULL) {
  1365. _u._variable->_initializer->output(out, indent_level, scope, false);
  1366. break;
  1367. }
  1368. }
  1369. _u._variable->_ident->output(out, scope);
  1370. break;
  1371. case T_function:
  1372. out << _u._fgroup->_name;
  1373. break;
  1374. case T_unknown_ident:
  1375. _u._ident->output(out, scope);
  1376. break;
  1377. case T_typecast:
  1378. out << "(";
  1379. _u._typecast._to->output(out, indent_level, scope, false);
  1380. out << ")(";
  1381. _u._typecast._op1->output(out, indent_level, scope, false);
  1382. out << ")";
  1383. break;
  1384. case T_static_cast:
  1385. out << "static_cast<";
  1386. _u._typecast._to->output(out, indent_level, scope, false);
  1387. out << ">(";
  1388. _u._typecast._op1->output(out, indent_level, scope, false);
  1389. out << ")";
  1390. break;
  1391. case T_dynamic_cast:
  1392. out << "dynamic_cast<";
  1393. _u._typecast._to->output(out, indent_level, scope, false);
  1394. out << ">(";
  1395. _u._typecast._op1->output(out, indent_level, scope, false);
  1396. out << ")";
  1397. break;
  1398. case T_const_cast:
  1399. out << "const_cast<";
  1400. _u._typecast._to->output(out, indent_level, scope, false);
  1401. out << ">(";
  1402. _u._typecast._op1->output(out, indent_level, scope, false);
  1403. out << ")";
  1404. break;
  1405. case T_reinterpret_cast:
  1406. out << "reinterpret_cast<";
  1407. _u._typecast._to->output(out, indent_level, scope, false);
  1408. out << ">(";
  1409. _u._typecast._op1->output(out, indent_level, scope, false);
  1410. out << ")";
  1411. break;
  1412. case T_construct:
  1413. _u._typecast._to->output(out, indent_level, scope, false);
  1414. out << "(";
  1415. _u._typecast._op1->output(out, indent_level, scope, false);
  1416. out << ")";
  1417. break;
  1418. case T_default_construct:
  1419. _u._typecast._to->output(out, indent_level, scope, false);
  1420. out << "()";
  1421. break;
  1422. case T_new:
  1423. out << "(new ";
  1424. _u._typecast._to->output(out, indent_level, scope, false);
  1425. out << "(";
  1426. _u._typecast._op1->output(out, indent_level, scope, false);
  1427. out << "))";
  1428. break;
  1429. case T_default_new:
  1430. out << "(new ";
  1431. _u._typecast._to->output(out, indent_level, scope, false);
  1432. out << "())";
  1433. break;
  1434. case T_sizeof:
  1435. out << "sizeof(";
  1436. _u._typecast._to->output(out, indent_level, scope, false);
  1437. out << ")";
  1438. break;
  1439. case T_sizeof_ellipsis:
  1440. out << "sizeof...(";
  1441. _u._ident->output(out, scope);
  1442. out << ")";
  1443. break;
  1444. case T_alignof:
  1445. out << "alignof(";
  1446. _u._typecast._to->output(out, indent_level, scope, false);
  1447. out << ")";
  1448. break;
  1449. case T_unary_operation:
  1450. switch (_u._op._operator) {
  1451. case UNARY_NOT:
  1452. out << "(! ";
  1453. _u._op._op1->output(out, indent_level, scope, false);
  1454. out << ")";
  1455. break;
  1456. case UNARY_NEGATE:
  1457. out << "(~ ";
  1458. _u._op._op1->output(out, indent_level, scope, false);
  1459. out << ")";
  1460. break;
  1461. case UNARY_MINUS:
  1462. out << '-';
  1463. _u._op._op1->output(out, indent_level, scope, false);
  1464. break;
  1465. case UNARY_PLUS:
  1466. out << '+';
  1467. _u._op._op1->output(out, indent_level, scope, false);
  1468. break;
  1469. case UNARY_STAR:
  1470. out << "(* ";
  1471. _u._op._op1->output(out, indent_level, scope, false);
  1472. out << ")";
  1473. break;
  1474. case UNARY_REF:
  1475. out << "(& ";
  1476. _u._op._op1->output(out, indent_level, scope, false);
  1477. out << ")";
  1478. break;
  1479. case 'f': // Function evaluation, no parameters.
  1480. _u._op._op1->output(out, indent_level, scope, false);
  1481. out << "()";
  1482. break;
  1483. default:
  1484. out << "(" << (char)_u._op._operator << " ";
  1485. _u._op._op1->output(out, indent_level, scope, false);
  1486. out << ")";
  1487. break;
  1488. }
  1489. break;
  1490. case T_binary_operation:
  1491. switch (_u._op._operator) {
  1492. case OROR:
  1493. out << "(";
  1494. _u._op._op1->output(out, indent_level, scope, false);
  1495. out << " || ";
  1496. _u._op._op2->output(out, indent_level, scope, false);
  1497. out << ")";
  1498. break;
  1499. case ANDAND:
  1500. out << "(";
  1501. _u._op._op1->output(out, indent_level, scope, false);
  1502. out << " && ";
  1503. _u._op._op2->output(out, indent_level, scope, false);
  1504. out << ")";
  1505. break;
  1506. case EQCOMPARE:
  1507. out << "(";
  1508. _u._op._op1->output(out, indent_level, scope, false);
  1509. out << " == ";
  1510. _u._op._op2->output(out, indent_level, scope, false);
  1511. out << ")";
  1512. break;
  1513. case NECOMPARE:
  1514. out << "(";
  1515. _u._op._op1->output(out, indent_level, scope, false);
  1516. out << " != ";
  1517. _u._op._op2->output(out, indent_level, scope, false);
  1518. out << ")";
  1519. break;
  1520. case LECOMPARE:
  1521. out << "(";
  1522. _u._op._op1->output(out, indent_level, scope, false);
  1523. out << " <= ";
  1524. _u._op._op2->output(out, indent_level, scope, false);
  1525. out << ")";
  1526. break;
  1527. case GECOMPARE:
  1528. out << "(";
  1529. _u._op._op1->output(out, indent_level, scope, false);
  1530. out << " >= ";
  1531. _u._op._op2->output(out, indent_level, scope, false);
  1532. out << ")";
  1533. break;
  1534. case LSHIFT:
  1535. out << "(";
  1536. _u._op._op1->output(out, indent_level, scope, false);
  1537. out << " << ";
  1538. _u._op._op2->output(out, indent_level, scope, false);
  1539. out << ")";
  1540. break;
  1541. case RSHIFT:
  1542. out << "(";
  1543. _u._op._op1->output(out, indent_level, scope, false);
  1544. out << " >> ";
  1545. _u._op._op2->output(out, indent_level, scope, false);
  1546. out << ")";
  1547. break;
  1548. case '.':
  1549. _u._op._op1->output(out, indent_level, scope, false);
  1550. out << ".";
  1551. _u._op._op2->output(out, indent_level, scope, false);
  1552. break;
  1553. case POINTSAT:
  1554. _u._op._op1->output(out, indent_level, scope, false);
  1555. out << "->";
  1556. _u._op._op2->output(out, indent_level, scope, false);
  1557. break;
  1558. case '[': // Array element reference
  1559. out << "(";
  1560. _u._op._op1->output(out, indent_level, scope, false);
  1561. out << "[";
  1562. _u._op._op2->output(out, indent_level, scope, false);
  1563. out << "])";
  1564. break;
  1565. case 'f': // Function evaluation
  1566. out << "(";
  1567. _u._op._op1->output(out, indent_level, scope, false);
  1568. out << "(";
  1569. _u._op._op2->output(out, indent_level, scope, false);
  1570. out << "))";
  1571. break;
  1572. case ',': // Comma, no parens are used
  1573. _u._op._op1->output(out, indent_level, scope, false);
  1574. out << ", ";
  1575. _u._op._op2->output(out, indent_level, scope, false);
  1576. break;
  1577. default:
  1578. out << "(";
  1579. _u._op._op1->output(out, indent_level, scope, false);
  1580. out << " " << (char)_u._op._operator << " ";
  1581. _u._op._op2->output(out, indent_level, scope, false);
  1582. out << ")";
  1583. }
  1584. break;
  1585. case T_trinary_operation:
  1586. out << "(";
  1587. _u._op._op1->output(out, indent_level, scope, false);
  1588. out << " ? ";
  1589. _u._op._op2->output(out, indent_level, scope, false);
  1590. out << " : ";
  1591. _u._op._op3->output(out, indent_level, scope, false);
  1592. out << ")";
  1593. break;
  1594. case T_literal:
  1595. _u._literal._value->output(out, indent_level, scope, false);
  1596. if (_u._literal._operator != NULL) {
  1597. string name = _u._literal._operator->get_simple_name();
  1598. assert(name.substr(0, 12) == "operator \"\" ");
  1599. out << name.substr(12);
  1600. }
  1601. break;
  1602. case T_raw_literal:
  1603. out << _str;
  1604. if (_u._literal._operator != NULL) {
  1605. string name = _u._literal._operator->get_simple_name();
  1606. assert(name.substr(0, 12) == "operator \"\" ");
  1607. out << name.substr(12);
  1608. }
  1609. break;
  1610. case T_typeid_type:
  1611. out << "typeid(";
  1612. _u._typeid._type->output(out, indent_level, scope, false);
  1613. out << ")";
  1614. break;
  1615. case T_typeid_expr:
  1616. out << "typeid(";
  1617. _u._typeid._expr->output(out, indent_level, scope, false);
  1618. out << ")";
  1619. break;
  1620. case T_default:
  1621. out << "default";
  1622. break;
  1623. case T_delete:
  1624. out << "delete";
  1625. break;
  1626. case T_type_trait:
  1627. switch (_u._type_trait._trait) {
  1628. case KW_HAS_VIRTUAL_DESTRUCTOR:
  1629. out << "__has_virtual_destructor";
  1630. break;
  1631. case KW_IS_ABSTRACT:
  1632. out << "__is_abstract";
  1633. break;
  1634. case KW_IS_BASE_OF:
  1635. out << "__is_base_of";
  1636. break;
  1637. case KW_IS_CLASS:
  1638. out << "__is_class";
  1639. break;
  1640. case KW_IS_CONSTRUCTIBLE:
  1641. out << "__is_constructible";
  1642. break;
  1643. case KW_IS_CONVERTIBLE_TO:
  1644. out << "__is_convertible_to";
  1645. break;
  1646. case KW_IS_DESTRUCTIBLE:
  1647. out << "__is_destructible";
  1648. break;
  1649. case KW_IS_EMPTY:
  1650. out << "__is_empty";
  1651. break;
  1652. case KW_IS_ENUM:
  1653. out << "__is_enum";
  1654. break;
  1655. case KW_IS_FINAL:
  1656. out << "__is_final";
  1657. break;
  1658. case KW_IS_FUNDAMENTAL:
  1659. out << "__is_fundamental";
  1660. break;
  1661. case KW_IS_POD:
  1662. out << "__is_pod";
  1663. break;
  1664. case KW_IS_POLYMORPHIC:
  1665. out << "__is_polymorphic";
  1666. break;
  1667. case KW_IS_STANDARD_LAYOUT:
  1668. out << "__is_standard_layout";
  1669. break;
  1670. case KW_IS_TRIVIAL:
  1671. out << "__is_trivial";
  1672. break;
  1673. case KW_IS_UNION:
  1674. out << "__is_union";
  1675. break;
  1676. default:
  1677. out << (evaluate().as_boolean() ? "true" : "false");
  1678. return;
  1679. }
  1680. out << '(';
  1681. _u._type_trait._type->output(out, indent_level, scope, false);
  1682. out << ')';
  1683. break;
  1684. case T_lambda:
  1685. _u._closure_type->output(out, indent_level, scope, false);
  1686. break;
  1687. default:
  1688. out << "(** invalid operand type " << (int)_type << " **)";
  1689. }
  1690. }
  1691. /**
  1692. *
  1693. */
  1694. CPPDeclaration::SubType CPPExpression::
  1695. get_subtype() const {
  1696. return ST_expression;
  1697. }
  1698. /**
  1699. *
  1700. */
  1701. CPPExpression *CPPExpression::
  1702. as_expression() {
  1703. return this;
  1704. }
  1705. /**
  1706. * Returns the most general of the two given types.
  1707. */
  1708. CPPType *CPPExpression::
  1709. elevate_type(CPPType *t1, CPPType *t2) {
  1710. CPPSimpleType *st1 = t1->as_simple_type();
  1711. CPPSimpleType *st2 = t2->as_simple_type();
  1712. if (st1 == NULL || st2 == NULL) {
  1713. // Nothing we can do about this. Who knows?
  1714. return NULL;
  1715. }
  1716. if (st1->_type == st2->_type) {
  1717. // They have the same type, so return the one with the largest flag bits.
  1718. if (st1->_flags & CPPSimpleType::F_longlong) {
  1719. return st1;
  1720. } else if (st2->_flags & CPPSimpleType::F_longlong) {
  1721. return st2;
  1722. } else if (st1->_flags & CPPSimpleType::F_long) {
  1723. return st1;
  1724. } else if (st2->_flags & CPPSimpleType::F_long) {
  1725. return st2;
  1726. } else if (st1->_flags & CPPSimpleType::F_short) {
  1727. return st2;
  1728. } else if (st2->_flags & CPPSimpleType::F_short) {
  1729. return st1;
  1730. }
  1731. return st1;
  1732. }
  1733. // They have different types.
  1734. if (st1->_type == CPPSimpleType::T_float ||
  1735. st1->_type == CPPSimpleType::T_double) {
  1736. return st1;
  1737. } else if (st2->_type == CPPSimpleType::T_float ||
  1738. st2->_type == CPPSimpleType::T_double) {
  1739. return st2;
  1740. } else if (st1->_type == CPPSimpleType::T_int) {
  1741. return st1;
  1742. } else if (st2->_type == CPPSimpleType::T_int) {
  1743. return st2;
  1744. } else if (st1->_type == CPPSimpleType::T_bool) {
  1745. return st1;
  1746. } else if (st2->_type == CPPSimpleType::T_bool) {
  1747. return st2;
  1748. }
  1749. return st1;
  1750. }
  1751. /**
  1752. * Called by CPPDeclaration to determine whether this expr is equivalent to
  1753. * another expr.
  1754. */
  1755. bool CPPExpression::
  1756. is_equal(const CPPDeclaration *other) const {
  1757. const CPPExpression *ot = ((CPPDeclaration *)other)->as_expression();
  1758. assert(ot != NULL);
  1759. if (_type != ot->_type) {
  1760. return false;
  1761. }
  1762. switch (_type) {
  1763. case T_nullptr:
  1764. return true;
  1765. case T_boolean:
  1766. return _u._boolean == ot->_u._boolean;
  1767. case T_integer:
  1768. return _u._integer == ot->_u._integer;
  1769. case T_real:
  1770. return _u._real == ot->_u._real;
  1771. case T_string:
  1772. case T_wstring:
  1773. case T_u8string:
  1774. case T_u16string:
  1775. case T_u32string:
  1776. return _str == ot->_str;
  1777. case T_variable:
  1778. return _u._variable == ot->_u._variable;
  1779. case T_function:
  1780. return _u._fgroup == ot->_u._fgroup;
  1781. case T_unknown_ident:
  1782. case T_sizeof_ellipsis:
  1783. return *_u._ident == *ot->_u._ident;
  1784. case T_typecast:
  1785. case T_static_cast:
  1786. case T_dynamic_cast:
  1787. case T_const_cast:
  1788. case T_reinterpret_cast:
  1789. case T_construct:
  1790. case T_new:
  1791. return _u._typecast._to == ot->_u._typecast._to &&
  1792. *_u._typecast._op1 == *ot->_u._typecast._op1;
  1793. case T_default_construct:
  1794. case T_default_new:
  1795. case T_sizeof:
  1796. case T_alignof:
  1797. return _u._typecast._to == ot->_u._typecast._to;
  1798. case T_unary_operation:
  1799. return *_u._op._op1 == *ot->_u._op._op1;
  1800. case T_binary_operation:
  1801. return *_u._op._op1 == *ot->_u._op._op1 &&
  1802. *_u._op._op2 == *ot->_u._op._op2;
  1803. case T_trinary_operation:
  1804. return *_u._op._op1 == *ot->_u._op._op1 &&
  1805. *_u._op._op2 == *ot->_u._op._op2;
  1806. case T_literal:
  1807. return *_u._literal._value == *ot->_u._literal._value &&
  1808. _u._literal._operator == ot->_u._literal._operator;
  1809. case T_raw_literal:
  1810. return _str == ot->_str &&
  1811. _u._literal._operator == ot->_u._literal._operator;
  1812. case T_typeid_type:
  1813. return _u._typeid._type == ot->_u._typeid._type;
  1814. case T_typeid_expr:
  1815. return _u._typeid._expr == ot->_u._typeid._expr;
  1816. case T_type_trait:
  1817. return _u._type_trait._trait == ot->_u._type_trait._trait &&
  1818. _u._type_trait._type == ot->_u._type_trait._type;
  1819. case T_lambda:
  1820. return _u._closure_type == ot->_u._closure_type;
  1821. default:
  1822. cerr << "(** invalid operand type " << (int)_type << " **)";
  1823. }
  1824. return true;
  1825. }
  1826. /**
  1827. * Called by CPPDeclaration to determine whether this expr should be ordered
  1828. * before another expr of the same type, in an arbitrary but fixed ordering.
  1829. */
  1830. bool CPPExpression::
  1831. is_less(const CPPDeclaration *other) const {
  1832. const CPPExpression *ot = ((CPPDeclaration *)other)->as_expression();
  1833. assert(ot != NULL);
  1834. if (_type != ot->_type) {
  1835. return (int)_type < (int)ot->_type;
  1836. }
  1837. switch (_type) {
  1838. case T_nullptr:
  1839. return false;
  1840. case T_boolean:
  1841. return _u._boolean < ot->_u._boolean;
  1842. case T_integer:
  1843. return _u._integer < ot->_u._integer;
  1844. case T_real:
  1845. return _u._real < ot->_u._real;
  1846. case T_string:
  1847. case T_wstring:
  1848. case T_u8string:
  1849. case T_u16string:
  1850. case T_u32string:
  1851. return _str < ot->_str;
  1852. case T_variable:
  1853. return _u._variable < ot->_u._variable;
  1854. case T_function:
  1855. return *_u._fgroup < *ot->_u._fgroup;
  1856. case T_unknown_ident:
  1857. case T_sizeof_ellipsis:
  1858. return *_u._ident < *ot->_u._ident;
  1859. case T_typecast:
  1860. case T_static_cast:
  1861. case T_dynamic_cast:
  1862. case T_const_cast:
  1863. case T_reinterpret_cast:
  1864. case T_construct:
  1865. case T_new:
  1866. if (_u._typecast._to != ot->_u._typecast._to) {
  1867. return _u._typecast._to < ot->_u._typecast._to;
  1868. }
  1869. return *_u._typecast._op1 < *ot->_u._typecast._op1;
  1870. case T_default_construct:
  1871. case T_default_new:
  1872. case T_sizeof:
  1873. case T_alignof:
  1874. return _u._typecast._to < ot->_u._typecast._to;
  1875. case T_trinary_operation:
  1876. if (*_u._op._op3 != *ot->_u._op._op3) {
  1877. return *_u._op._op3 < *ot->_u._op._op3;
  1878. }
  1879. // Fall through
  1880. case T_binary_operation:
  1881. if (*_u._op._op2 != *ot->_u._op._op2) {
  1882. return *_u._op._op2 < *ot->_u._op._op2;
  1883. }
  1884. // Fall through
  1885. case T_unary_operation:
  1886. return *_u._op._op1 < *ot->_u._op._op1;
  1887. case T_literal:
  1888. if (_u._literal._operator != ot->_u._literal._operator) {
  1889. return _u._literal._operator < ot->_u._literal._operator;
  1890. }
  1891. return *_u._literal._value < *ot->_u._literal._value;
  1892. case T_raw_literal:
  1893. if (_u._literal._operator != ot->_u._literal._operator) {
  1894. return _u._literal._operator < ot->_u._literal._operator;
  1895. }
  1896. return _str < ot->_str;
  1897. case T_typeid_type:
  1898. return _u._typeid._type < ot->_u._typeid._type;
  1899. case T_typeid_expr:
  1900. return *_u._typeid._expr < *ot->_u._typeid._expr;
  1901. case T_type_trait:
  1902. if (_u._type_trait._trait != ot->_u._type_trait._trait) {
  1903. return _u._type_trait._trait < ot->_u._type_trait._trait;
  1904. }
  1905. return *_u._type_trait._type < *ot->_u._type_trait._type;
  1906. case T_lambda:
  1907. return _u._closure_type < ot->_u._closure_type;
  1908. default:
  1909. cerr << "(** invalid operand type " << (int)_type << " **)";
  1910. }
  1911. return false;
  1912. }