BfModule.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210
  1. #pragma once
  2. #pragma warning(push)
  3. #pragma warning(disable:4141)
  4. #pragma warning(disable:4146)
  5. #pragma warning(disable:4291)
  6. #pragma warning(disable:4244)
  7. #pragma warning(disable:4267)
  8. #pragma warning(disable:4624)
  9. #pragma warning(disable:4800)
  10. #pragma warning(disable:4996)
  11. #include "BeefySysLib/Common.h"
  12. #include "BeefySysLib/util/CritSect.h"
  13. #include "BeefySysLib/util/PerfTimer.h"
  14. #include "BeefySysLib/util/Hash.h"
  15. #include "BeefySysLib/util/HashSet.h"
  16. #include "BeefySysLib/util/SizedArray.h"
  17. #include "BeefySysLib/Span.h"
  18. #include "BfSourceClassifier.h"
  19. #include "BfAst.h"
  20. #include "BfSystem.h"
  21. #include "BfIRBuilder.h"
  22. #include "BfResolvedTypeUtils.h"
  23. #include "BfUtil.h"
  24. #include <unordered_set>
  25. #include <functional>
  26. #pragma warning(pop)
  27. NS_BF_BEGIN
  28. class BfType;
  29. class BfResolvedType;
  30. class BfExprEvaluator;
  31. class CeEmitContext;
  32. class CeDbgState;
  33. enum BfCeTypeEmitSourceKind : int8;
  34. enum BfPopulateType
  35. {
  36. BfPopulateType_TypeDef,
  37. BfPopulateType_Identity,
  38. BfPopulateType_IdentityNoRemapAlias,
  39. BfPopulateType_Declaration,
  40. BfPopulateType_BaseType,
  41. BfPopulateType_CustomAttributes,
  42. BfPopulateType_Interfaces_Direct,
  43. BfPopulateType_AllowStaticMethods,
  44. BfPopulateType_Interfaces_All,
  45. BfPopulateType_Data_Soft,
  46. BfPopulateType_Data,
  47. BfPopulateType_DataAndMethods,
  48. BfPopulateType_Full = BfPopulateType_DataAndMethods,
  49. BfPopulateType_Full_Force
  50. };
  51. enum BfEvalExprFlags : int64
  52. {
  53. BfEvalExprFlags_None = 0,
  54. BfEvalExprFlags_ExplicitCast = 1,
  55. BfEvalExprFlags_NoCast = 2,
  56. BfEvalExprFlags_NoValueAddr = 4,
  57. BfEvalExprFlags_PropogateNullConditional = 8,
  58. BfEvalExprFlags_IgnoreNullConditional = 0x10,
  59. BfEvalExprFlags_AllowSplat = 0x20,
  60. BfEvalExprFlags_AllowEnumId = 0x40,
  61. BfEvalExprFlags_AllowIntUnknown = 0x80,
  62. BfEvalExprFlags_CreateConditionalScope = 0x100,
  63. BfEvalExprFlags_PendingPropSet = 0x200,
  64. BfEvalExprFlags_AllowParamsExpr = 0x400,
  65. BfEvalExprFlags_AllowRefExpr = 0x800,
  66. BfEvalExprFlags_AllowOutExpr = 0x1000,
  67. BfEvalExprFlags_FieldInitializer = 0x2000,
  68. BfEvalExprFlags_VariableDeclaration = 0x4000,
  69. BfEvalExprFlags_NoAutoComplete = 0x8000,
  70. BfEvalExprFlags_AllowNonConst = 0x10000,
  71. BfEvalExprFlags_StringInterpolateFormat = 0x20000,
  72. BfEvalExprFlags_NoLookupError = 0x40000,
  73. BfEvalExprFlags_Comptime = 0x80000,
  74. BfEvalExprFlags_DisallowComptime = 0x100000,
  75. BfEvalExprFlags_InCascade = 0x200000,
  76. BfEvalExprFlags_InferReturnType = 0x400000,
  77. BfEvalExprFlags_WasMethodRef = 0x800000,
  78. BfEvalExprFlags_DeclType = 0x1000000,
  79. BfEvalExprFlags_AllowBase = 0x2000000,
  80. BfEvalExprFlags_NoCeRebuildFlags = 0x4000000,
  81. BfEvalExprFlags_FromConversionOp = 0x8000000,
  82. BfEvalExprFlags_FromConversionOp_Explicit = 0x10000000,
  83. BfEvalExprFlags_AllowGenericConstValue = 0x20000000,
  84. BfEvalExprFlags_IsExpressionBody = 0x40000000,
  85. BfEvalExprFlags_AppendFieldInitializer = 0x80000000,
  86. BfEvalExprFlags_NameOf = 0x100000000LL,
  87. BfEvalExprFlags_NameOfSuccess = 0x200000000LL,
  88. BfEvalExprFlags_InParamsExpr = 0x400000000LL,
  89. BfEvalExprFlags_InheritFlags = BfEvalExprFlags_NoAutoComplete | BfEvalExprFlags_Comptime | BfEvalExprFlags_DeclType
  90. };
  91. enum BfCastFlags
  92. {
  93. BfCastFlags_None = 0,
  94. BfCastFlags_Explicit = 1,
  95. BfCastFlags_Unchecked = 2,
  96. BfCastFlags_Internal = 4,
  97. BfCastFlags_SilentFail = 8,
  98. BfCastFlags_NoBox = 0x10,
  99. BfCastFlags_NoBoxDtor = 0x20,
  100. BfCastFlags_NoInterfaceImpl = 0x40,
  101. BfCastFlags_NoConversionOperator = 0x80,
  102. BfCastFlags_FromCompiler = 0x100, // Not user specified
  103. BfCastFlags_Force = 0x200,
  104. BfCastFlags_PreferAddr = 0x400,
  105. BfCastFlags_WarnOnBox = 0x800,
  106. BfCastFlags_IsCastCheck = 0x1000,
  107. BfCastFlags_IsConstraintCheck = 0x2000,
  108. BfCastFlags_WantsConst = 0x4000,
  109. BfCastFlags_FromComptimeReturn = 0x8000
  110. };
  111. enum BfCastResultFlags : int8
  112. {
  113. BfCastResultFlags_None = 0,
  114. BfCastResultFlags_IsAddr = 1,
  115. BfCastResultFlags_IsTemp = 2
  116. };
  117. enum BfAllocFlags : int8
  118. {
  119. BfAllocFlags_None = 0,
  120. BfAllocFlags_HasAppendWantMark = 1,
  121. BfAllocFlags_RawArray = 2,
  122. BfAllocFlags_ZeroMemory = 4,
  123. BfAllocFlags_NoDtorCall = 8,
  124. BfAllocFlags_NoDefaultToMalloc = 0x10,
  125. };
  126. enum BfProtectionCheckFlags : int8
  127. {
  128. BfProtectionCheckFlag_None = 0,
  129. BfProtectionCheckFlag_CheckedProtected = 1,
  130. BfProtectionCheckFlag_CheckedPrivate = 2,
  131. BfProtectionCheckFlag_AllowProtected = 4,
  132. BfProtectionCheckFlag_AllowPrivate = 8,
  133. BfProtectionCheckFlag_InstanceLookup = 0x10
  134. };
  135. enum BfEmbeddedStatementFlags : int8
  136. {
  137. BfEmbeddedStatementFlags_None = 0,
  138. BfEmbeddedStatementFlags_IsConditional = 1,
  139. BfEmbeddedStatementFlags_IsDeferredBlock = 2,
  140. BfEmbeddedStatementFlags_Unscoped = 4,
  141. BfEmbeddedStatementFlags_CheckStack = 8
  142. };
  143. enum BfLocalVarAssignKind : int8
  144. {
  145. BfLocalVarAssignKind_None = 0,
  146. BfLocalVarAssignKind_Conditional = 1,
  147. BfLocalVarAssignKind_Unconditional = 2
  148. };
  149. struct BfCreateTypeDataContext
  150. {
  151. Dictionary<int, int> mUsedStringIdMap;
  152. HashSet<BfTypeInstance*> mReflectTypeSet;
  153. };
  154. class BfLocalVariable
  155. {
  156. public:
  157. int64 mUnassignedFieldFlags;
  158. BfType* mResolvedType;
  159. BfIdentifierNode* mNameNode;
  160. String mName;
  161. BfIRValue mAddr;
  162. BfIRValue mConstValue;
  163. BfIRValue mValue;
  164. BfIRMDNode mDbgVarInst;
  165. BfIRValue mDbgDeclareInst;
  166. BfIRBlock mDeclBlock;
  167. int mLocalVarIdx; // Index in mLocals
  168. int mLocalVarId; // Unique Id for identification (does not get reused, unlike mLocalVarIdx)
  169. int mCompositeCount;
  170. int mWrittenToId;
  171. int mReadFromId;
  172. int mParamIdx;
  173. uint8 mNamePrefixCount;
  174. bool mIsThis;
  175. bool mHasLocalStructBacking;
  176. bool mIsStruct;
  177. bool mIsImplicitParam;
  178. bool mParamFailed;
  179. BfLocalVarAssignKind mAssignedKind;
  180. bool mHadExitBeforeAssign;
  181. bool mIsReadOnly;
  182. bool mIsStatic;
  183. bool mIsSplat;
  184. bool mIsLowered;
  185. bool mAllowAddr;
  186. bool mIsShadow;
  187. bool mUsedImplicitly; // Passed implicitly to a local method, capture by ref if we can
  188. bool mNotCaptured;
  189. bool mIsConst;
  190. bool mIsBumpAlloc;
  191. BfLocalVariable* mShadowedLocal;
  192. public:
  193. BfLocalVariable()
  194. {
  195. mUnassignedFieldFlags = 0;
  196. mResolvedType = NULL;
  197. mNameNode = NULL;
  198. mLocalVarIdx = -1;
  199. mLocalVarId = -1;
  200. mCompositeCount = -1;
  201. mParamIdx = -2;
  202. mNamePrefixCount = 0;
  203. mIsThis = false;
  204. mHasLocalStructBacking = false;
  205. mIsStruct = false;
  206. mIsImplicitParam = false;
  207. mParamFailed = false;
  208. mAssignedKind = BfLocalVarAssignKind_None;
  209. mHadExitBeforeAssign = false;
  210. mWrittenToId = -1;
  211. mReadFromId = -1;
  212. mIsReadOnly = false;
  213. mIsStatic = false;
  214. mIsSplat = false;
  215. mIsLowered = false;
  216. mAllowAddr = false;
  217. mIsShadow = false;
  218. mUsedImplicitly = false;
  219. mNotCaptured = false;
  220. mIsConst = false;
  221. mIsBumpAlloc = false;
  222. mShadowedLocal = NULL;
  223. }
  224. bool IsParam()
  225. {
  226. return mParamIdx != -2;
  227. }
  228. void Init();
  229. };
  230. class BfMethodState;
  231. class BfMixinState;
  232. class BfClosureState;
  233. class BfLocalMethod
  234. {
  235. public:
  236. BfSystem* mSystem;
  237. BfModule* mModule;
  238. BfSource* mSource;
  239. BfMethodDeclaration* mMethodDeclaration;
  240. String mExpectedFullName;
  241. String mMethodName;
  242. BfMethodDef* mMethodDef;
  243. BfLocalMethod* mOuterLocalMethod;
  244. BfMethodInstanceGroup* mMethodInstanceGroup;
  245. BfMethodInstance* mLambdaInvokeMethodInstance;
  246. BfLambdaBindExpression* mLambdaBindExpr;
  247. BfMethodState* mDeclMethodState;
  248. BfIRMDNode mDeclDIScope;
  249. BfMixinState* mDeclMixinState;
  250. OwnedVector<BfDirectTypeReference> mDirectTypeRefs;
  251. bool mDeclOnly;
  252. bool mDidBodyErrorPass;
  253. BfLocalMethod* mNextWithSameName;
  254. public:
  255. BfLocalMethod()
  256. {
  257. mModule = NULL;
  258. mSystem = NULL;
  259. mSource = NULL;
  260. mMethodDeclaration = NULL;
  261. mMethodDef = NULL;
  262. mOuterLocalMethod = NULL;
  263. mMethodInstanceGroup = NULL;
  264. mLambdaInvokeMethodInstance = NULL;
  265. mLambdaBindExpr = NULL;
  266. mDeclMethodState = NULL;
  267. mDeclMixinState = NULL;
  268. mDeclOnly = false;
  269. mDidBodyErrorPass = false;
  270. mNextWithSameName = NULL;
  271. }
  272. ~BfLocalMethod();
  273. void Dispose();
  274. };
  275. class BfDeferredCapture
  276. {
  277. public:
  278. String mName;
  279. BfTypedValue mValue;
  280. };
  281. class BfDeferredCallEntry
  282. {
  283. public:
  284. BfDeferredCallEntry* mNext;
  285. BfAstNode* mSrcNode;
  286. BfTypedValue mTarget;
  287. BfModuleMethodInstance mModuleMethodInstance;
  288. BfIRValue mDeferredAlloca;
  289. SizedArray<BfIRValue, 2> mOrigScopeArgs;
  290. SizedArray<BfIRValue, 2> mScopeArgs;
  291. Array<BfDeferredCapture> mCaptures;
  292. BfBlock* mDeferredBlock;
  293. BfAstNode* mEmitRefNode;
  294. int64 mBlockId;
  295. int mHandlerCount;
  296. bool mBypassVirtual;
  297. bool mDoNullCheck;
  298. bool mCastThis;
  299. bool mArgsNeedLoad;
  300. bool mIgnored;
  301. bool mIsAllocaFunc;
  302. SLIList<BfDeferredCallEntry*> mDynList;
  303. BfIRValue mDynCallTail;
  304. public:
  305. BfDeferredCallEntry()
  306. {
  307. mBypassVirtual = false;
  308. mDoNullCheck = false;
  309. mNext = NULL;
  310. mSrcNode = NULL;
  311. mDeferredBlock = NULL;
  312. mEmitRefNode = NULL;
  313. mBlockId = -1;
  314. mHandlerCount = 0;
  315. mArgsNeedLoad = false;
  316. mCastThis = false;
  317. mIgnored = false;
  318. }
  319. ~BfDeferredCallEntry()
  320. {
  321. mDynList.DeleteAll();
  322. }
  323. bool IsDynList()
  324. {
  325. return (bool)mDynCallTail;
  326. }
  327. };
  328. struct BfDeferredHandler
  329. {
  330. BfIRBlock mHandlerBlock;
  331. BfIRBlock mDoneBlock;
  332. };
  333. class BfScopeData;
  334. struct BfAssignedLocal
  335. {
  336. BfLocalVariable* mLocalVar;
  337. int mLocalVarField;
  338. BfLocalVarAssignKind mAssignKind;
  339. bool operator==(const BfAssignedLocal& second) const
  340. {
  341. return (mLocalVar == second.mLocalVar) && (mLocalVarField == second.mLocalVarField) && (mAssignKind == second.mAssignKind);
  342. }
  343. };
  344. // We use this structure in the case where we have multiple execution paths, then we merge the assigned variables together
  345. // So when we have "if (check) { a = 1; } else {a = 2; }" we can know that a IS definitely assigned afterwards
  346. class BfDeferredLocalAssignData
  347. {
  348. public:
  349. BfScopeData* mScopeData;
  350. int mVarIdBarrier;
  351. SizedArray<BfAssignedLocal, 4> mAssignedLocals;
  352. bool mIsChained;
  353. BfDeferredLocalAssignData* mChainedAssignData;
  354. bool mHadFallthrough;
  355. bool mHadReturn;
  356. bool mHadBreak;
  357. bool mIsUnconditional;
  358. bool mIsIfCondition;
  359. bool mIfMayBeSkipped;
  360. bool mLeftBlock;
  361. bool mLeftBlockUncond;
  362. public:
  363. BfDeferredLocalAssignData(BfScopeData* scopeData = NULL)
  364. {
  365. mScopeData = scopeData;
  366. mVarIdBarrier = -1;
  367. mHadFallthrough = false;
  368. mHadReturn = false;
  369. mHadBreak = false;
  370. mChainedAssignData = NULL;
  371. mIsChained = false;
  372. mIsUnconditional = false;
  373. mIsIfCondition = false;
  374. mIfMayBeSkipped = false;
  375. mLeftBlock = false;
  376. mLeftBlockUncond = false;
  377. }
  378. bool Contains(const BfAssignedLocal& val)
  379. {
  380. for (int i = 0; i < (int)mAssignedLocals.mSize; i++)
  381. {
  382. auto& check = mAssignedLocals[i];
  383. if ((check.mLocalVar == val.mLocalVar) && (check.mLocalVarField == val.mLocalVarField) && (check.mAssignKind >= val.mAssignKind))
  384. return true;
  385. }
  386. return false;
  387. }
  388. void ExtendFrom(BfDeferredLocalAssignData* outerLocalAssignData, bool doChain = false);
  389. void BreakExtendChain();
  390. void SetIntersection(const BfDeferredLocalAssignData& otherLocalAssignData);
  391. void Validate() const;
  392. void SetUnion(const BfDeferredLocalAssignData& otherLocalAssignData);
  393. };
  394. enum BfScopeKind
  395. {
  396. BfScopeKind_Normal,
  397. BfScopeKind_StatementTarget,
  398. BfScopeKind_StatementTarget_Conditional,
  399. };
  400. class BfDeferredCallProcessorInstance
  401. {
  402. public:
  403. BfDeferredCallEntry* mDeferredCallEntry;
  404. BfIRBlock mProcessorBlock;
  405. BfIRBlock mContinueBlock;
  406. };
  407. // "Looped" means this scope will execute zero to many times, "Conditional" means zero or one.
  408. // Looped and Conditional are mutually exclusive. "Dyn" means Looped OR Conditional.
  409. class BfScopeData
  410. {
  411. public:
  412. BfScopeData* mPrevScope;
  413. BfScopeKind mScopeKind;
  414. BfIRMDNode mDIScope;
  415. BfIRMDNode mDIInlinedAt;
  416. String mLabel;
  417. BfIdentifierNode* mLabelNode;
  418. int mLocalVarStart;
  419. int mScopeDepth;
  420. int mMixinDepth;
  421. int mScopeLocalId;
  422. bool mIsScopeHead; // For first scope data or for inlined start
  423. bool mIsLoop;
  424. bool mIsConditional; // Rarely set - usually we rely on OuterIsConditional or InnerIsConditional
  425. bool mOuterIsConditional;
  426. bool mInnerIsConditional;
  427. bool mHadOuterDynStack;
  428. bool mAllowTargeting;
  429. bool mHadScopeValueRetain;
  430. bool mIsDeferredBlock;
  431. bool mAllowVariableDeclarations;
  432. bool mInInitBlock;
  433. bool mSupressNextUnreachable;
  434. bool mInConstIgnore;
  435. bool mIsSharedTempBlock;
  436. bool mDone;
  437. BfMixinState* mMixinState;
  438. BfBlock* mAstBlock;
  439. BfAstNode* mCloseNode;
  440. BfExprEvaluator* mExprEvaluator;
  441. SLIList<BfDeferredCallEntry*> mDeferredCallEntries;
  442. Array<BfDeferredCallProcessorInstance> mDeferredCallProcessorInstances;
  443. BfIRValue mBlock;
  444. BfIRValue mValueScopeStart;
  445. BfIRValue mSavedStack;
  446. Array<BfIRValue> mSavedStackUses;
  447. Array<BfDeferredHandler> mDeferredHandlers; // These get cleared when us our a parent gets new entries added into mDeferredCallEntries
  448. Array<BfIRBlock> mAtEndBlocks; // Move these to the end after we close scope
  449. Array<BfIRValue> mDeferredLifetimeEnds;
  450. BfDeferredLocalAssignData* mExitLocalAssignData;
  451. BfIRMDNode mAltDIFile;
  452. BfIRMDNode mAltDIScope;
  453. public:
  454. BfScopeData()
  455. {
  456. mScopeKind = BfScopeKind_Normal;
  457. mPrevScope = NULL;
  458. mLocalVarStart = 0;
  459. mLabelNode = NULL;
  460. mMixinState = NULL;
  461. mAstBlock = NULL;
  462. mCloseNode = NULL;
  463. mExprEvaluator = NULL;
  464. mIsScopeHead = false;
  465. mIsLoop = false;
  466. mIsConditional = false;
  467. mOuterIsConditional = false;
  468. mInnerIsConditional = false;
  469. mHadOuterDynStack = false;
  470. mHadScopeValueRetain = false;
  471. mIsDeferredBlock = false;
  472. mSupressNextUnreachable = false;
  473. mAllowTargeting = true;
  474. mAllowVariableDeclarations = true;
  475. mInInitBlock = false;
  476. mInConstIgnore = false;
  477. mIsSharedTempBlock = false;
  478. mDone = false;
  479. mMixinDepth = 0;
  480. mScopeDepth = 0;
  481. mScopeLocalId = -1;
  482. mExitLocalAssignData = NULL;
  483. }
  484. ~BfScopeData()
  485. {
  486. mDeferredCallEntries.DeleteAll();
  487. delete mExitLocalAssignData;
  488. }
  489. BfScopeData* GetHead()
  490. {
  491. auto checkScope = this;
  492. while (!checkScope->mIsScopeHead)
  493. checkScope = checkScope->mPrevScope;
  494. return checkScope;
  495. }
  496. BfScopeData* GetTargetable()
  497. {
  498. if (!mAllowTargeting)
  499. return mPrevScope->GetTargetable();
  500. return this;
  501. }
  502. bool IsLooped(BfScopeData* scopeData)
  503. {
  504. auto checkScope = this;
  505. while (checkScope != NULL)
  506. {
  507. if (checkScope->mIsLoop)
  508. return true;
  509. if (checkScope == scopeData)
  510. break;
  511. checkScope = checkScope->mPrevScope;
  512. }
  513. return false;
  514. }
  515. bool IsDyn(BfScopeData* scopeData)
  516. {
  517. auto checkScope = this;
  518. // Scoping to a loop is dynamic - it doesn't have to cross the loop boundary.
  519. // Scoping to a loop _body_ is not necessarily dynamic, however.
  520. while (checkScope != NULL)
  521. {
  522. if (checkScope->mIsConditional)
  523. return true;
  524. if ((checkScope->mIsLoop) || (checkScope->mInnerIsConditional))
  525. return true;
  526. if (checkScope == scopeData)
  527. break;
  528. if (checkScope->mOuterIsConditional)
  529. return true;
  530. checkScope = checkScope->mPrevScope;
  531. }
  532. return false;
  533. }
  534. bool CrossesMixin(BfScopeData* scopeData)
  535. {
  536. // Check for a transition for having an inlinedAt to not having one
  537. if (!mDIInlinedAt)
  538. return false;
  539. auto checkScope = this;
  540. while (checkScope != scopeData)
  541. {
  542. checkScope = checkScope->mPrevScope;
  543. if (!checkScope->mDIInlinedAt)
  544. return true;
  545. }
  546. return false;
  547. }
  548. void ClearHandlers(BfScopeData* scopeData)
  549. {
  550. auto checkScope = this;
  551. while (true)
  552. {
  553. checkScope->mDeferredHandlers.Clear();
  554. if (checkScope == scopeData)
  555. break;
  556. checkScope = checkScope->mPrevScope;
  557. }
  558. }
  559. int GetDepth()
  560. {
  561. int depth = 0;
  562. auto checkScopeData = this;
  563. while (true)
  564. {
  565. checkScopeData = checkScopeData->mPrevScope;
  566. if (checkScopeData == NULL)
  567. break;
  568. depth++;
  569. }
  570. return depth;
  571. }
  572. bool ExtendLifetime(BfIRValue irValue)
  573. {
  574. if (mDeferredLifetimeEnds.Remove(irValue))
  575. {
  576. if (mPrevScope != NULL)
  577. mPrevScope->mDeferredLifetimeEnds.Add(irValue);
  578. return true;
  579. }
  580. return false;
  581. }
  582. };
  583. struct BfCaptureInfo
  584. {
  585. public:
  586. struct Entry
  587. {
  588. BfCaptureType mCaptureType;
  589. bool mUsed;
  590. BfAstNode* mRefNode;
  591. BfAstNode* mNameNode;
  592. Entry()
  593. {
  594. mCaptureType = BfCaptureType_Copy;
  595. mUsed = false;
  596. mRefNode = NULL;
  597. mNameNode = NULL;
  598. }
  599. };
  600. public:
  601. Array<Entry> mCaptures;
  602. };
  603. class BfAllocTarget
  604. {
  605. public:
  606. BfScopeData* mScopeData;
  607. BfAstNode* mRefNode;
  608. BfTypedValue mCustomAllocator;
  609. BfScopedInvocationTarget* mScopedInvocationTarget;
  610. int mAlignOverride;
  611. BfCaptureInfo* mCaptureInfo;
  612. bool mIsFriend;
  613. public:
  614. BfAllocTarget()
  615. {
  616. mScopeData = NULL;
  617. mRefNode = NULL;
  618. mCustomAllocator = NULL;
  619. mScopedInvocationTarget = NULL;
  620. mAlignOverride = -1;
  621. mIsFriend = false;
  622. mCaptureInfo = NULL;
  623. }
  624. BfAllocTarget(BfScopeData* scopeData)
  625. {
  626. mScopeData = scopeData;
  627. mRefNode = NULL;
  628. mCustomAllocator = NULL;
  629. mScopedInvocationTarget = NULL;
  630. mAlignOverride = -1;
  631. }
  632. BfAllocTarget(const BfTypedValue& customAllocator, BfAstNode* refNode)
  633. {
  634. mScopeData = NULL;
  635. mCustomAllocator = customAllocator;
  636. mRefNode = NULL;
  637. mScopedInvocationTarget = NULL;
  638. mAlignOverride = -1;
  639. }
  640. };
  641. class BfBreakData
  642. {
  643. public:
  644. BfBreakData* mPrevBreakData;
  645. BfScopeData* mScope;
  646. BfIRBlock mIRContinueBlock;
  647. BfIRBlock mIRBreakBlock;
  648. BfIRBlock mIRFallthroughBlock;
  649. BfIRValue mInnerValueScopeStart;
  650. bool mHadBreak;
  651. public:
  652. BfBreakData()
  653. {
  654. mPrevBreakData = NULL;
  655. mScope = NULL;
  656. mHadBreak = false;
  657. }
  658. };
  659. class BfMixinRecord
  660. {
  661. public:
  662. BfAstNode * mSource;
  663. };
  664. class BfDeferredLocalMethod
  665. {
  666. public:
  667. BfLocalMethod* mLocalMethod;
  668. BfMethodInstance* mMethodInstance;
  669. Array<BfLocalMethod*> mLocalMethods; // Local methods that were in scope at the time
  670. Array<BfLocalVariable> mConstLocals;
  671. Array<BfMixinRecord> mMixinStateRecords;
  672. };
  673. enum BfReturnTypeInferState
  674. {
  675. BfReturnTypeInferState_None,
  676. BfReturnTypeInferState_Inferring,
  677. BfReturnTypeInferState_Fail,
  678. };
  679. class BfClosureState
  680. {
  681. public:
  682. bool mCapturing;
  683. bool mCaptureVisitingBody;
  684. int mCaptureStartAccessId;
  685. // When we need to look into another local method to determine captures, but we don't want to process local variable declarations or cause infinite recursion
  686. bool mBlindCapturing;
  687. bool mDeclaringMethodIsMutating;
  688. bool mCapturedDelegateSelf;
  689. BfReturnTypeInferState mReturnTypeInferState;
  690. BfLocalMethod* mLocalMethod;
  691. BfClosureInstanceInfo* mClosureInstanceInfo;
  692. BfMethodDef* mClosureMethodDef;
  693. BfType* mReturnType;
  694. BfTypeInstance* mDelegateType;
  695. BfTypeInstance* mClosureType;
  696. BfDeferredLocalMethod* mActiveDeferredLocalMethod;
  697. Array<BfLocalVariable> mConstLocals; // Locals not inserted into the captured 'this'
  698. HashSet<BfFieldInstance*> mReferencedOuterClosureMembers;
  699. HashSet<BfMethodInstance*> mLocalMethodRefSet;
  700. Array<BfMethodInstance*> mLocalMethodRefs;
  701. Array<BfMethodInstance*> mDeferredProcessLocalMethods;
  702. public:
  703. BfClosureState()
  704. {
  705. mClosureMethodDef = NULL;
  706. mLocalMethod = NULL;
  707. mClosureInstanceInfo = NULL;
  708. mCapturing = false;
  709. mCaptureVisitingBody = false;
  710. mCaptureStartAccessId = -1;
  711. mBlindCapturing = false;
  712. mDeclaringMethodIsMutating = false;
  713. mCapturedDelegateSelf = false;
  714. mReturnTypeInferState = BfReturnTypeInferState_None;
  715. mActiveDeferredLocalMethod = NULL;
  716. mReturnType = NULL;
  717. mDelegateType = NULL;
  718. mClosureType = NULL;
  719. }
  720. };
  721. class BfIteratorClassState
  722. {
  723. public:
  724. BfTypeInstance* mIteratorClass;
  725. bool mCapturing;
  726. public:
  727. BfIteratorClassState()
  728. {
  729. mCapturing = false;
  730. }
  731. };
  732. class BfPendingNullConditional
  733. {
  734. public:
  735. BfIRBlock mPrevBB;
  736. BfIRBlock mCheckBB;
  737. BfIRBlock mDoneBB;
  738. SizedArray<BfIRBlock, 4> mNotNullBBs;
  739. };
  740. class BfAttributeState
  741. {
  742. public:
  743. enum Flags
  744. {
  745. Flag_None,
  746. Flag_StopOnError = 1,
  747. Flag_HadError = 2
  748. };
  749. public:
  750. Flags mFlags;
  751. BfAstNode* mSrc;
  752. BfAttributeTargets mTarget;
  753. BfCustomAttributes* mCustomAttributes;
  754. bool mUsed;
  755. BfAttributeState()
  756. {
  757. mSrc = NULL;
  758. mFlags = Flag_None;
  759. mTarget = BfAttributeTargets_None;
  760. mCustomAttributes = NULL;
  761. mUsed = false;
  762. }
  763. ~BfAttributeState()
  764. {
  765. if (mCustomAttributes != NULL)
  766. delete mCustomAttributes;
  767. }
  768. };
  769. class BfMixinState
  770. {
  771. public:
  772. BfMixinState* mPrevMixinState;
  773. BfAstNode* mSource;
  774. BfScopeData* mCallerScope;
  775. BfScopeData* mTargetScope; // Equals caller scope unless user explicitly calls specifies scope override
  776. BfFilePosition mInjectFilePosition;
  777. BfMethodInstance* mMixinMethodInstance;
  778. BfAstNode* mResultExpr;
  779. SizedArray<BfType*, 8> mArgTypes;
  780. SizedArray<BfIRValue, 8> mArgConsts;
  781. int mLocalsStartIdx;
  782. bool mUsedInvocationScope;
  783. bool mHasDeferredUsage;
  784. bool mCheckedCircularRef;
  785. bool mDoCircularVarResult;
  786. bool mUseMixinGenerics;
  787. BfTypedValue mTarget;
  788. int mLastTargetAccessId;
  789. public:
  790. BfMixinState()
  791. {
  792. mPrevMixinState = NULL;
  793. mSource = NULL;
  794. mCallerScope = NULL;
  795. mTarget = NULL;
  796. mMixinMethodInstance = NULL;
  797. mResultExpr = NULL;
  798. mLocalsStartIdx = 0;
  799. mUsedInvocationScope = false;
  800. mHasDeferredUsage = false;
  801. mCheckedCircularRef = false;
  802. mDoCircularVarResult = false;
  803. mUseMixinGenerics = false;
  804. mLastTargetAccessId = -1;
  805. }
  806. BfMixinState* GetRoot()
  807. {
  808. auto curMixin = this;
  809. while (curMixin->mPrevMixinState != NULL)
  810. curMixin = curMixin->mPrevMixinState;
  811. return curMixin;
  812. }
  813. };
  814. class BfDeferredCallEmitState
  815. {
  816. public:
  817. BfAstNode* mCloseNode;
  818. public:
  819. BfDeferredCallEmitState()
  820. {
  821. mCloseNode = NULL;
  822. }
  823. };
  824. class BfTypeLookupError
  825. {
  826. public:
  827. enum BfErrorKind
  828. {
  829. BfErrorKind_None,
  830. BfErrorKind_Ambiguous,
  831. BfErrorKind_Inaccessible
  832. };
  833. public:
  834. BfErrorKind mErrorKind;
  835. BfAstNode* mRefNode;
  836. BfTypeDef* mAmbiguousTypeDef;
  837. public:
  838. BfTypeLookupError()
  839. {
  840. mErrorKind = BfErrorKind_None;
  841. mRefNode = NULL;
  842. mAmbiguousTypeDef = NULL;
  843. }
  844. };
  845. /*struct BfSplatDecompHash
  846. {
  847. size_t operator()(const std::pair<BfIRValue, int>& val) const
  848. {
  849. return (val.first.mId << 4) + val.second;
  850. }
  851. };
  852. struct BfSplatDecompEquals
  853. {
  854. bool operator()(const std::pair<BfIRValue, int>& lhs, const std::pair<BfIRValue, int>& rhs) const
  855. {
  856. return (lhs.first.mFlags == rhs.first.mFlags) && (lhs.first.mId == rhs.first.mId) && (lhs.second == rhs.second);
  857. }
  858. };*/
  859. struct BfMethodRefHash
  860. {
  861. size_t operator()(const BfMethodRef& val) const
  862. {
  863. if (val.mTypeInstance == NULL)
  864. return 0;
  865. return val.mTypeInstance->mTypeId ^ (val.mMethodNum << 10);
  866. }
  867. };
  868. class BfConstResolveState
  869. {
  870. public:
  871. BfMethodInstance* mMethodInstance;
  872. BfConstResolveState* mPrevConstResolveState;
  873. bool mInCalcAppend;
  874. bool mFailed;
  875. BfConstResolveState()
  876. {
  877. mMethodInstance = NULL;
  878. mPrevConstResolveState = NULL;
  879. mInCalcAppend = false;
  880. mFailed = false;
  881. }
  882. };
  883. struct BfLocalVarEntry
  884. {
  885. BfLocalVariable* mLocalVar;
  886. BfLocalVarEntry(BfLocalVariable* localVar)
  887. {
  888. mLocalVar = localVar;
  889. }
  890. bool operator==(const BfLocalVarEntry& other) const
  891. {
  892. return mLocalVar->mName == other.mLocalVar->mName;
  893. }
  894. bool operator==(const StringImpl& name) const
  895. {
  896. return mLocalVar->mName == name;
  897. }
  898. };
  899. class BfLambdaCaptureInfo
  900. {
  901. public:
  902. String mName;
  903. };
  904. class BfLambdaInstance
  905. {
  906. public:
  907. BfTypeInstance* mDelegateTypeInstance;
  908. BfTypeInstance* mUseTypeInstance;
  909. BfClosureType* mClosureTypeInstance;
  910. BfMixinState* mDeclMixinState;
  911. BfTypeInstance* mOuterClosure;
  912. BfIRValue mClosureFunc;
  913. BfIRValue mDtorFunc;
  914. bool mCopyOuterCaptures;
  915. bool mDeclaringMethodIsMutating;
  916. bool mIsStatic;
  917. Array<BfLambdaCaptureInfo> mCaptures;
  918. BfMethodInstance* mMethodInstance;
  919. BfMethodInstance* mDtorMethodInstance;
  920. Array<BfLocalVariable> mConstLocals;
  921. OwnedVector<BfParameterDeclaration> mParamDecls;
  922. public:
  923. BfLambdaInstance()
  924. {
  925. mDelegateTypeInstance = NULL;
  926. mUseTypeInstance = NULL;
  927. mClosureTypeInstance = NULL;
  928. mDeclMixinState = NULL;
  929. mOuterClosure = NULL;
  930. mCopyOuterCaptures = false;
  931. mDeclaringMethodIsMutating = false;
  932. mIsStatic = false;
  933. mMethodInstance = NULL;
  934. mDtorMethodInstance = NULL;
  935. }
  936. ~BfLambdaInstance()
  937. {
  938. auto methodDef = mMethodInstance->mMethodDef;
  939. delete mMethodInstance;
  940. delete methodDef;
  941. if (mDtorMethodInstance != NULL)
  942. {
  943. auto methodDef = mDtorMethodInstance->mMethodDef;
  944. delete mDtorMethodInstance;
  945. delete methodDef;
  946. }
  947. }
  948. };
  949. class BfParentNodeEntry
  950. {
  951. public:
  952. BfAstNode* mNode;
  953. BfParentNodeEntry* mPrev;
  954. };
  955. class BfMethodState
  956. {
  957. public:
  958. enum TempKind
  959. {
  960. TempKind_None,
  961. TempKind_Static,
  962. TempKind_NonStatic
  963. };
  964. public:
  965. BumpAllocator mBumpAlloc;
  966. BfMethodState* mPrevMethodState; // Only non-null for things like local methods
  967. BfConstResolveState* mConstResolveState;
  968. BfMethodInstance* mMethodInstance;
  969. BfHotDataReferenceBuilder* mHotDataReferenceBuilder;
  970. BfTypeInstance* mPrivateTypeInstance;
  971. BfIRFunction mIRFunction;
  972. BfIRBlock mIRHeadBlock;
  973. BfIRBlock mIRInitBlock;
  974. BfIRBlock mIREntryBlock;
  975. Array<BfLocalVariable*, AllocatorBump> mLocals;
  976. HashSet<BfLocalVarEntry, AllocatorBump> mLocalVarSet;
  977. Array<BfLocalMethod*> mLocalMethods;
  978. Dictionary<String, BfLocalMethod*> mLocalMethodMap;
  979. Dictionary<String, BfLocalMethod*> mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method
  980. Array<BfDeferredLocalMethod*> mDeferredLocalMethods;
  981. OwnedVector<BfMixinState> mMixinStates;
  982. Dictionary<BfAstNodeList, BfLambdaInstance*> mLambdaCache;
  983. Array<BfLambdaInstance*> mDeferredLambdaInstances;
  984. Array<BfIRValue> mSplatDecompAddrs;
  985. BfDeferredLocalAssignData* mDeferredLocalAssignData;
  986. BfProjectSet mVisibleProjectSet;
  987. int mDeferredLoopListCount;
  988. int mDeferredLoopListEntryCount;
  989. HashSet<int> mSkipObjectAccessChecks; // Indexed by BfIRValue value id
  990. Dictionary<int64, BfType*>* mGenericTypeBindings;
  991. BfIRMDNode mDIFile;
  992. bool mInHeadScope; // Is in starting scope of code on entry, controls mStackAllocUncondCount
  993. BfTypedValue mRetVal;
  994. BfIRValue mRetValAddr;
  995. int mCurAppendAlign;
  996. BfIRValue mDynStackRevIdx; // Increments when we restore the stack, which can invalidate dynSize for dynamic looped allocs
  997. BfIRBlock mIRExitBlock;
  998. BfBreakData* mBreakData;
  999. int mBlockNestLevel; // 0 = top level
  1000. bool mIgnoreObjectAccessCheck;
  1001. bool mDisableChecks;
  1002. BfMixinState* mMixinState;
  1003. BfClosureState* mClosureState;
  1004. BfDeferredCallEmitState* mDeferredCallEmitState;
  1005. BfIteratorClassState* mIteratorClassState;
  1006. BfPendingNullConditional* mPendingNullConditional;
  1007. BfTypeOptions* mMethodTypeOptions; // for [Options] attribute
  1008. BfIRMDNode mDIRetVal;
  1009. BfScopeData mHeadScope;
  1010. BfScopeData* mCurScope;
  1011. BfScopeData* mTailScope; // Usually equals mCurScope
  1012. BfScopeData* mOverrideScope;
  1013. BfAstNode* mEmitRefNode;
  1014. TempKind mTempKind; // Used for var inference, etc
  1015. bool mInDeferredBlock;
  1016. bool mHadReturn;
  1017. bool mHadContinue;
  1018. bool mMayNeedThisAccessCheck;
  1019. bool mLeftBlockUncond; // Definitely left block. mHadReturn also sets mLeftBlock
  1020. bool mLeftBlockCond; // May have left block.
  1021. bool mInPostReturn; // Unreachable code
  1022. bool mCrossingMixin; // ie: emitting dtors in response to a return in a mixin
  1023. bool mNoBind;
  1024. bool mInConditionalBlock; // IE: RHS of ((A) && (B)), indicates an allocation in 'B' won't be dominated by a dtor, for example
  1025. bool mAllowUinitReads;
  1026. bool mDisableReturns;
  1027. bool mCancelledDeferredCall;
  1028. bool mNoObjectAccessChecks;
  1029. int mCurLocalVarId; // Can also refer to a label
  1030. int mCurAccessId; // For checking to see if a block reads from or writes to a local
  1031. public:
  1032. BfMethodState()
  1033. {
  1034. mLocals.mAlloc = &mBumpAlloc;
  1035. mLocalVarSet.mAlloc = &mBumpAlloc;
  1036. mMethodInstance = NULL;
  1037. mPrevMethodState = NULL;
  1038. mConstResolveState = NULL;
  1039. mHotDataReferenceBuilder = NULL;
  1040. mPrivateTypeInstance = NULL;
  1041. mHeadScope.mIsScopeHead = true;
  1042. mCurScope = &mHeadScope;
  1043. mTailScope = &mHeadScope;
  1044. mEmitRefNode = NULL;
  1045. mOverrideScope = NULL;
  1046. mHadReturn = false;
  1047. mLeftBlockUncond = false;
  1048. mLeftBlockCond = false;
  1049. mHadContinue = false;
  1050. mMayNeedThisAccessCheck = false;
  1051. mTempKind = TempKind_None;
  1052. mInHeadScope = true;
  1053. mBreakData = NULL;
  1054. mBlockNestLevel = 0;
  1055. mInPostReturn = false;
  1056. mCrossingMixin = false;
  1057. mNoBind = false;
  1058. mIgnoreObjectAccessCheck = false;
  1059. mDisableChecks = false;
  1060. mInConditionalBlock = false;
  1061. mAllowUinitReads = false;
  1062. mDisableReturns = false;
  1063. mCancelledDeferredCall = false;
  1064. mNoObjectAccessChecks = false;
  1065. mInDeferredBlock = false;
  1066. mDeferredLocalAssignData = NULL;
  1067. mCurLocalVarId = 0;
  1068. mCurAccessId = 1;
  1069. mCurAppendAlign = 0;
  1070. mDeferredLoopListCount = 0;
  1071. mDeferredLoopListEntryCount = 0;
  1072. mClosureState = NULL;
  1073. mDeferredCallEmitState = NULL;
  1074. mIteratorClassState = NULL;
  1075. mGenericTypeBindings = NULL;
  1076. mMixinState = NULL;
  1077. mPendingNullConditional = NULL;
  1078. mMethodTypeOptions = NULL;
  1079. }
  1080. ~BfMethodState();
  1081. void AddScope(BfScopeData* newScopeData)
  1082. {
  1083. BF_ASSERT(newScopeData != mCurScope);
  1084. mInHeadScope = false;
  1085. newScopeData->mDIScope = mCurScope->mDIScope;
  1086. newScopeData->mDIInlinedAt = mCurScope->mDIInlinedAt;
  1087. newScopeData->mLocalVarStart = mCurScope->mLocalVarStart;
  1088. newScopeData->mExprEvaluator = mCurScope->mExprEvaluator;
  1089. newScopeData->mAltDIFile = mCurScope->mAltDIFile;
  1090. newScopeData->mPrevScope = mCurScope;
  1091. newScopeData->mMixinDepth = mCurScope->mMixinDepth;
  1092. newScopeData->mScopeDepth = mCurScope->mScopeDepth + 1;
  1093. newScopeData->mInConstIgnore = mCurScope->mInConstIgnore;
  1094. mCurScope = newScopeData;
  1095. mTailScope = mCurScope;
  1096. }
  1097. void SetHadReturn(bool hadReturn)
  1098. {
  1099. mHadReturn = hadReturn;
  1100. if (mDeferredLocalAssignData != NULL)
  1101. mDeferredLocalAssignData->mHadReturn = hadReturn;
  1102. }
  1103. BfMethodState* GetRootMethodState()
  1104. {
  1105. auto checkMethodState = this;
  1106. while (checkMethodState->mPrevMethodState != NULL)
  1107. checkMethodState = checkMethodState->mPrevMethodState;
  1108. return checkMethodState;
  1109. }
  1110. BfMethodState* GetNonCaptureState()
  1111. {
  1112. //TODO: Why did this require mLocalMethod to not be null? That means lambda captures we're not crossed over
  1113. auto checkMethodState = this;
  1114. while ((checkMethodState->mPrevMethodState != NULL) && (checkMethodState->mClosureState != NULL) &&
  1115. (checkMethodState->mClosureState->mCapturing) /*&& (checkMethodState->mClosureState->mLocalMethod != NULL)*/)
  1116. checkMethodState = checkMethodState->mPrevMethodState;
  1117. return checkMethodState;
  1118. }
  1119. BfMethodState* GetMethodStateForLocal(BfLocalVariable* localVar);
  1120. bool InMainMixinScope()
  1121. {
  1122. if (mMixinState == NULL)
  1123. return false;
  1124. return mMixinState->mCallerScope == mCurScope->mPrevScope;
  1125. }
  1126. BfMixinState* GetRootMixinState()
  1127. {
  1128. BfMixinState* mixinState = mMixinState;
  1129. while ((mixinState != NULL) && (mixinState->mPrevMixinState != NULL))
  1130. {
  1131. mixinState = mixinState->mPrevMixinState;
  1132. }
  1133. return mixinState;
  1134. }
  1135. BfAstNode* GetRootMixinSource()
  1136. {
  1137. BfMixinState* mixinState = NULL;
  1138. auto checkMethodState = this;
  1139. while (checkMethodState != NULL)
  1140. {
  1141. if (checkMethodState->mMixinState != NULL)
  1142. mixinState = checkMethodState->mMixinState;
  1143. if (checkMethodState->mClosureState != NULL)
  1144. {
  1145. auto activeLocalMethod = checkMethodState->mClosureState->mActiveDeferredLocalMethod;
  1146. if (activeLocalMethod != NULL)
  1147. {
  1148. if (!activeLocalMethod->mMixinStateRecords.IsEmpty())
  1149. return activeLocalMethod->mMixinStateRecords.back().mSource;
  1150. }
  1151. }
  1152. checkMethodState = checkMethodState->mPrevMethodState;
  1153. }
  1154. if (mixinState != NULL)
  1155. return mixinState->GetRoot()->mSource;
  1156. return NULL;
  1157. }
  1158. bool HasMixin()
  1159. {
  1160. auto checkMethodState = this;
  1161. while (checkMethodState != NULL)
  1162. {
  1163. if (checkMethodState->mMixinState != NULL)
  1164. return true;
  1165. checkMethodState = checkMethodState->mPrevMethodState;
  1166. }
  1167. return false;
  1168. }
  1169. bool HasNonStaticMixin()
  1170. {
  1171. auto checkMethodState = this;
  1172. while (checkMethodState != NULL)
  1173. {
  1174. if ((checkMethodState->mMixinState != NULL) && (!checkMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mIsStatic))
  1175. return true;
  1176. checkMethodState = checkMethodState->mPrevMethodState;
  1177. }
  1178. return false;
  1179. }
  1180. void LocalDefined(BfLocalVariable* localVar, int fieldIdx = -1, BfLocalVarAssignKind assignKind = BfLocalVarAssignKind_None, bool isFromDeferredAssignData = false);
  1181. void ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData& deferredLocalAssignData);
  1182. void Reset();
  1183. int GetLocalStartIdx()
  1184. {
  1185. if (mMixinState != NULL)
  1186. return mMixinState->mLocalsStartIdx;
  1187. return 0;
  1188. }
  1189. bool IsTemporary()
  1190. {
  1191. return mTempKind != TempKind_None;
  1192. }
  1193. };
  1194. class BfDeferredMethodCallData;
  1195. enum BfValueFlags
  1196. {
  1197. BfValueFlags_None = 0,
  1198. BfValueFlags_Boxed = 1,
  1199. };
  1200. enum BfBuiltInFuncType
  1201. {
  1202. BfBuiltInFuncType_PrintF,
  1203. BfBuiltInFuncType_Malloc,
  1204. BfBuiltInFuncType_Free,
  1205. BfBuiltInFuncType_LoadSharedLibraries,
  1206. BfBuiltInFuncType_Count
  1207. };
  1208. // These are the options that can be applied to individual methods that cause AltModules
  1209. // to be build, since they are exclusive to an LLVMModule; LLVM optimization-related
  1210. // options always apply to entire LLVM modules
  1211. struct BfModuleOptions
  1212. {
  1213. public:
  1214. BfSIMDSetting mSIMDSetting;
  1215. int mEmitDebugInfo;
  1216. BfOptLevel mOptLevel;
  1217. bool operator==(const BfModuleOptions& other)
  1218. {
  1219. return (mSIMDSetting == other.mSIMDSetting) &&
  1220. (mEmitDebugInfo == other.mEmitDebugInfo) &&
  1221. (mOptLevel == other.mOptLevel);
  1222. }
  1223. bool operator!=(const BfModuleOptions& other)
  1224. {
  1225. return !(*this == other);
  1226. }
  1227. BfModuleOptions()
  1228. {
  1229. mSIMDSetting = BfSIMDSetting_None;
  1230. mEmitDebugInfo = false;
  1231. mOptLevel = BfOptLevel_NotSet;
  1232. }
  1233. };
  1234. struct BfGenericParamSource
  1235. {
  1236. public:
  1237. BfTypeInstance* mTypeInstance;
  1238. BfMethodInstance* mMethodInstance;
  1239. bool mCheckAccessibility;
  1240. public:
  1241. BfGenericParamSource()
  1242. {
  1243. mTypeInstance = NULL;
  1244. mMethodInstance = NULL;
  1245. mCheckAccessibility = true;
  1246. }
  1247. BfGenericParamSource(BfTypeInstance* typeInstance)
  1248. {
  1249. mTypeInstance = typeInstance;
  1250. mMethodInstance = NULL;
  1251. mCheckAccessibility = true;
  1252. }
  1253. BfGenericParamSource(BfMethodInstance* methodInstance)
  1254. {
  1255. mTypeInstance = NULL;
  1256. mMethodInstance = methodInstance;
  1257. mCheckAccessibility = true;
  1258. }
  1259. BfTypeInstance* GetTypeInstance() const
  1260. {
  1261. if (mTypeInstance != NULL)
  1262. return mTypeInstance;
  1263. if (mMethodInstance != NULL)
  1264. return mMethodInstance->GetOwner();
  1265. return NULL;
  1266. }
  1267. };
  1268. class BfAmbiguityContext
  1269. {
  1270. public:
  1271. class Entry
  1272. {
  1273. public:
  1274. BfTypeInterfaceEntry* mInterfaceEntry;
  1275. int mMethodIdx;
  1276. Array<BfMethodInstance*> mCandidates;
  1277. };
  1278. public:
  1279. BfModule* mModule;
  1280. BfTypeInstance* mTypeInstance;
  1281. bool mIsProjectSpecific;
  1282. bool mIsReslotting;
  1283. Dictionary<int, Entry> mEntries;
  1284. public:
  1285. BfAmbiguityContext()
  1286. {
  1287. mModule = NULL;
  1288. mTypeInstance = NULL;
  1289. mIsProjectSpecific = false;
  1290. mIsReslotting = false;
  1291. }
  1292. void Add(int id, BfTypeInterfaceEntry* ifaceEntry, int methodIdx, BfMethodInstance* candidateA, BfMethodInstance* candidateB);
  1293. void Remove(int id);
  1294. void Finish();
  1295. };
  1296. enum BfDefaultValueKind
  1297. {
  1298. BfDefaultValueKind_Const,
  1299. BfDefaultValueKind_Value,
  1300. BfDefaultValueKind_Addr,
  1301. BfDefaultValueKind_Undef
  1302. };
  1303. class BfModuleFileName
  1304. {
  1305. public:
  1306. Array<BfProject*> mProjects;
  1307. String mFileName;
  1308. bool mModuleWritten;
  1309. bool mWroteToLib;
  1310. bool operator==(const BfModuleFileName& second) const
  1311. {
  1312. return (mProjects == second.mProjects) && (mFileName == second.mFileName);
  1313. }
  1314. };
  1315. class BfGlobalLookup
  1316. {
  1317. public:
  1318. enum Kind
  1319. {
  1320. Kind_All,
  1321. Kind_Field,
  1322. Kind_Method
  1323. };
  1324. public:
  1325. Kind mKind;
  1326. String mName;
  1327. };
  1328. enum BfSrcPosFlags
  1329. {
  1330. BfSrcPosFlag_None = 0,
  1331. BfSrcPosFlag_Expression = 1,
  1332. BfSrcPosFlag_NoSetDebugLoc = 2,
  1333. BfSrcPosFlag_Force = 4
  1334. };
  1335. enum BfDeferredBlockFlags
  1336. {
  1337. BfDeferredBlockFlag_None = 0,
  1338. BfDeferredBlockFlag_BypassVirtual = 1,
  1339. BfDeferredBlockFlag_DoNullChecks = 2,
  1340. BfDeferredBlockFlag_SkipObjectAccessCheck = 4,
  1341. BfDeferredBlockFlag_MoveNewBlocksToEnd = 8,
  1342. BfDeferredBlockFlag_IsAllocaFunc = 0x10
  1343. };
  1344. enum BfGetCustomAttributesFlags
  1345. {
  1346. BfGetCustomAttributesFlags_None = 0,
  1347. BfGetCustomAttributesFlags_AllowNonConstArgs = 1,
  1348. BfGetCustomAttributesFlags_KeepConstsInModule = 2
  1349. };
  1350. class BfVDataExtEntry
  1351. {
  1352. public:
  1353. BfTypeInstance* mDeclTypeInst;
  1354. BfTypeInstance* mImplTypeInst;
  1355. bool operator==(const BfVDataExtEntry& rhs)
  1356. {
  1357. return ((mDeclTypeInst == rhs.mDeclTypeInst) && (mImplTypeInst == rhs.mImplTypeInst));
  1358. }
  1359. };
  1360. #define BFMODULE_FATAL(module, msg) (module)->FatalError((msg), __FILE__, __LINE__)
  1361. struct BfCEParseContext
  1362. {
  1363. int mFailIdx;
  1364. int mWarnIdx;
  1365. };
  1366. class BfModule : public BfStructuralVisitor
  1367. {
  1368. public:
  1369. enum RebuildKind
  1370. {
  1371. RebuildKind_None,
  1372. RebuildKind_SkipOnDemandTypes,
  1373. RebuildKind_All
  1374. };
  1375. public:
  1376. Val128 mDataHash;
  1377. #ifdef _DEBUG
  1378. StringT<128> mModuleName;
  1379. #else
  1380. String mModuleName;
  1381. #endif
  1382. Array<BfModuleFileName> mOutFileNames;
  1383. // SpecializedModules contain method specializations with types that come from other projects
  1384. Dictionary<Array<BfProject*>, BfModule*> mSpecializedMethodModules;
  1385. BfModule* mParentModule;
  1386. BfModule* mNextAltModule; // Linked
  1387. BfModuleOptions* mModuleOptions; // Only in altModules
  1388. BfSystem* mSystem;
  1389. BfCompiler* mCompiler;
  1390. BfContext* mContext;
  1391. BfProject* mProject;
  1392. BfIRType mStringLiteralType;
  1393. BfTypeInstance* mCurTypeInstance;
  1394. Dictionary<BfParserData*, BfFileInstance*> mFileInstanceMap;
  1395. Dictionary<String, BfFileInstance*> mNamedFileInstanceMap;
  1396. Array<BfTypeInstance*> mOwnedTypeInstances;
  1397. Dictionary<int, BfIRValue> mStringObjectPool;
  1398. Dictionary<int, BfIRValue> mStringCharPtrPool;
  1399. Array<int> mStringPoolRefs;
  1400. HashSet<int> mUnreifiedStringPoolRefs;
  1401. HashSet<int> mSignatureIdRefs;
  1402. Array<BfIRBuilder*> mPrevIRBuilders; // Before extensions
  1403. BfIRBuilder* mBfIRBuilder;
  1404. BfMethodState* mCurMethodState;
  1405. BfAttributeState* mAttributeState;
  1406. BfFilePosition mCurFilePosition;
  1407. BfMethodInstance* mCurMethodInstance;
  1408. BfParentNodeEntry* mParentNodeEntry;
  1409. BfIRFunction mBuiltInFuncs[BfBuiltInFuncType_Count];
  1410. Array<BfDllImportEntry> mDllImportEntries;
  1411. Array<int> mImportFileNames;
  1412. Dictionary<BfMethodRef, BfIRValue> mFuncReferences;
  1413. Dictionary<BfFieldRef, BfIRValue> mStaticFieldRefs;
  1414. Dictionary<BfTypeInstance*, BfIRValue> mInterfaceSlotRefs;
  1415. Dictionary<BfTypeInstance*, BfIRValue> mClassVDataRefs;
  1416. Dictionary<BfVDataExtEntry, BfIRValue> mClassVDataExtRefs;
  1417. Dictionary<BfType*, BfIRValue> mTypeDataRefs;
  1418. Dictionary<BfType*, BfIRValue> mDbgRawAllocDataRefs;
  1419. Dictionary<BfMethodInstance*, BfDeferredMethodCallData*> mDeferredMethodCallData;
  1420. HashSet<int64> mDeferredMethodIds;
  1421. HashSet<BfModule*> mModuleRefs;
  1422. BfIRMDNode mDICompileUnit;
  1423. int mRevision;
  1424. int mRebuildIdx;
  1425. int mLastUsedRevision;
  1426. int mExtensionCount;
  1427. int mIncompleteMethodCount;
  1428. int mOnDemandMethodCount;
  1429. int mLastModuleWrittenRevision;
  1430. int mCurLocalMethodId;
  1431. int16 mUsedSlotCount; // -1 = not used, 0 = awaiting
  1432. bool mAddedToCount;
  1433. bool mHasForceLinkMarker;
  1434. bool mIsReified;
  1435. bool mGeneratesCode;
  1436. bool mReifyQueued;
  1437. bool mWantsIRIgnoreWrites;
  1438. bool mHasGenericMethods;
  1439. bool mIsSpecialModule; // vdata, unspecialized, external
  1440. bool mIsComptimeModule;
  1441. bool mIsScratchModule;
  1442. bool mIsSpecializedMethodModuleRoot;
  1443. bool mIsModuleMutable; // Set to false after writing module to disk, can be set back to true after doing extension module
  1444. bool mWroteToLib;
  1445. bool mHadBuildError;
  1446. bool mHadBuildWarning;
  1447. bool mIgnoreErrors;
  1448. bool mHadIgnoredError;
  1449. bool mIgnoreWarnings;
  1450. bool mSetIllegalSrcPosition;
  1451. bool mReportErrors; // Still puts system in error state when set to false
  1452. bool mIsInsideAutoComplete;
  1453. bool mIsHotModule;
  1454. bool mIsDeleting;
  1455. bool mSkipInnerLookup;
  1456. bool mAwaitingInitFinish;
  1457. bool mAwaitingFinish;
  1458. bool mHasFullDebugInfo;
  1459. bool mNoResolveGenericParams;
  1460. bool mHadHotObjectWrites;
  1461. public:
  1462. void FatalError(const StringImpl& error, const char* file = NULL, int line = -1, int column = -1);
  1463. void FatalError(const StringImpl& error, BfAstNode* refNode);
  1464. void FatalError(const StringImpl& error, BfFailHandleKind failHandleKind);
  1465. void InternalError(const StringImpl& error, BfAstNode* refNode = NULL, const char* file = NULL, int line = -1);
  1466. void NotImpl(BfAstNode* astNode);
  1467. void AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None);
  1468. bool CheckProtection(BfProtection protection, BfTypeDef* checkType, bool allowProtected, bool allowPrivate);
  1469. void GetAccessAllowed(BfTypeInstance* checkType, bool& allowProtected, bool& allowPrivate);
  1470. bool CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* memberOwner, BfProject* memberProject, BfProtection memberProtection, BfTypeInstance* lookupStartType);
  1471. void SetElementType(BfAstNode* astNode, BfSourceElementType elementType);
  1472. void SetHighestElementType(BfAstNode* astNode, BfSourceElementType elementType);
  1473. bool PreFail();
  1474. void SetFail();
  1475. void VerifyOnDemandMethods();
  1476. bool IsSkippingExtraResolveChecks();
  1477. bool AddErrorContext(StringImpl& errorString, BfAstNode* refNode, BfWhileSpecializingFlags& isWhileSpecializing, bool isWarning);
  1478. CeDbgState* GetCeDbgState();
  1479. BfError* Fail(const StringImpl& error, BfAstNode* refNode = NULL, bool isPersistent = false, bool deferError = false);
  1480. BfError* FailInternal(const StringImpl& error, BfAstNode* refNode = NULL);
  1481. BfError* FailAfter(const StringImpl& error, BfAstNode* refNode);
  1482. BfError* Warn(int warningNum, const StringImpl& warning, BfAstNode* refNode = NULL, bool isPersistent = false, bool showInSpecialized = false);
  1483. void CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfFieldInstance* fieldInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc);
  1484. void CheckRangeError(BfType* type, BfAstNode* refNode);
  1485. bool CheckCircularDataError(bool failTypes = true, bool forceFail = false);
  1486. BfFileInstance* GetFileFromNode(BfAstNode* astNode);
  1487. //void UpdateSrcPos(BfAstNode* astNode, bool setDebugLoc = true, int debugLocOffset = 0, bool force = false);
  1488. void UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0);
  1489. void UseDefaultSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0);
  1490. void UpdateExprSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None);
  1491. void SetIllegalSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None);
  1492. void SetIllegalExprSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None);
  1493. void GetConstClassValueParam(BfIRValue classVData, SizedArrayImpl<BfIRValue>& typeValueParams);
  1494. BfIRValue GetConstValue(int64 val);
  1495. BfIRValue GetConstValue(int64 val, BfType* type);
  1496. BfIRValue GetConstValue8(int val);
  1497. BfIRValue GetConstValue32(int32 val);
  1498. BfIRValue GetConstValue64(int64 val);
  1499. BfIRValue GetDefaultValue(BfType* type);
  1500. BfTypedValue GetFakeTypedValue(BfType* type);
  1501. BfTypedValue GetDefaultTypedValue(BfType* type, bool allowRef = false, BfDefaultValueKind defaultValueKind = BfDefaultValueKind_Const);
  1502. void FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams, bool fillInPadding = false);
  1503. BfIRValue CreateStringObjectValue(const StringImpl& str, int stringId, bool define);
  1504. BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define);
  1505. bool HasStringId(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
  1506. int GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
  1507. String* GetStringPoolString(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
  1508. BfIRValue GetStringCharPtr(int stringId, bool force = false);
  1509. BfIRValue GetStringCharPtr(BfIRValue strValue, bool force = false);
  1510. BfIRValue GetStringCharPtr(const StringImpl& str, bool force = false);
  1511. BfIRValue GetStringObjectValue(int idx, bool define, bool force);
  1512. BfIRValue GetStringObjectValue(const StringImpl& str, bool define = false, bool force = false);
  1513. BfIRValue CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external);
  1514. void DataToString(StringImpl& str, void* ptr, BfType* type);
  1515. void VariantToString(StringImpl& str, const BfVariant& variant, BfType* type = NULL);
  1516. StringT<128> TypeToString(BfType* resolvedType, Array<String>* genericMethodParamNameOverrides = NULL);
  1517. StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array<String>* genericMethodParamNameOverrides = NULL);
  1518. void DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None, Array<String>* genericMethodParamNameOverrides = NULL);
  1519. String FieldToString(BfFieldInstance* fieldInstance);
  1520. StringT<128> MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags = BfMethodNameFlag_ResolveGenericParamNames, BfTypeVector* typeGenericArgs = NULL, BfTypeVector* methodGenericArgs = NULL);
  1521. void pt(BfType* type);
  1522. void pm(BfMethodInstance* type);
  1523. BfIRType CurrentAddToConstHolder(BfIRType irType);
  1524. void CurrentAddToConstHolder(BfIRValue& irVal);
  1525. void ClearConstData();
  1526. bool HasUnactializedConstant(BfConstant* constant, BfIRConstHolder* constHolder);
  1527. bool HasGlobalVarReference(BfConstant* constant, BfIRConstHolder* constHolder);
  1528. BfTypedValue GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType);
  1529. BfIRValue ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowUnactualized = false);
  1530. void ValidateCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeTargets attrTarget, bool force = false);
  1531. void GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, BfGetCustomAttributesFlags flags = BfGetCustomAttributesFlags_None, BfCaptureInfo* captureInfo = NULL);
  1532. BfCustomAttributes* GetCustomAttributes(BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, BfGetCustomAttributesFlags flags = BfGetCustomAttributesFlags_None, BfCaptureInfo* captureInfo = NULL);
  1533. BfCustomAttributes* GetCustomAttributes(BfTypeDef* typeDef);
  1534. void FinishAttributeState(BfAttributeState* attributeState);
  1535. void ProcessTypeInstCustomAttributes(int& packing, bool& isUnion, bool& isCRepr, bool& isOrdered, int& alignOverride, BfType*& underlyingArrayType, int& underlyingArraySize);
  1536. void ProcessCustomAttributeData();
  1537. bool TryGetConstString(BfIRConstHolder* constHolder, BfIRValue irValue, StringImpl& str);
  1538. BfVariant TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& value, bool allowUndef = false);
  1539. BfTypedValue FlushNullConditional(BfTypedValue result, bool ignoreNullable = false);
  1540. void NewScopeState(bool createLexicalBlock = true, bool flushValueScope = true); // returns prev scope data
  1541. BfIRValue CreateAlloca(BfIRType irType, int align, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
  1542. BfIRValue CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
  1543. BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
  1544. BfDeferredCallEntry* AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock());
  1545. void RestoreScoreState_LocalVariables(int localVarStart);
  1546. void RestoreScopeState();
  1547. void MarkDynStack(BfScopeData* scope);
  1548. void SaveStackState(BfScopeData* scope);
  1549. BfIRValue ValueScopeStart();
  1550. void ValueScopeEnd(BfIRValue valueScopeStart);
  1551. BfProjectSet* GetVisibleProjectSet();
  1552. bool IsProjectVisible(BfProject* project);
  1553. void AddBasicBlock(BfIRBlock bb, bool activate = true);
  1554. void VisitEmbeddedStatement(BfAstNode* stmt, BfExprEvaluator* exprEvaluator = NULL, BfEmbeddedStatementFlags flags = BfEmbeddedStatementFlags_None);
  1555. void VisitCodeBlock(BfBlock* block);
  1556. void VisitCodeBlock(BfBlock* block, BfIRBlock continueBlock, BfIRBlock breakBlock, BfIRBlock fallthroughBlock, bool defaultBreak, bool* hadReturn = NULL, BfLabelNode* labelNode = NULL, bool closeScope = false, BfEmbeddedStatementFlags flags = BfEmbeddedStatementFlags_None);
  1557. void DoForLess(BfForEachStatement* forEachStmt);
  1558. // Util
  1559. void CreateReturn(BfIRValue val);
  1560. void EmitReturn(const BfTypedValue& val);
  1561. void EmitDefaultReturn();
  1562. void EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, SizedArrayImpl<BfIRValue>& llvmArgs, BfDeferredBlockFlags flags = BfDeferredBlockFlag_None);
  1563. bool AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfScopeData* scope);
  1564. BfDeferredCallEntry* AddDeferredBlock(BfBlock* block, BfScopeData* scope, Array<BfDeferredCapture>* captures = NULL);
  1565. BfDeferredCallEntry* AddDeferredCall(const BfModuleMethodInstance& moduleMethodInstance, SizedArrayImpl<BfIRValue>& llvmArgs, BfScopeData* scope, BfAstNode* srcNode = NULL, bool bypassVirtual = false, bool doNullCheck = false, bool isAllocaFunc = false);
  1566. void EmitDeferredCall(BfScopeData* scopeData, BfDeferredCallEntry& deferredCallEntry, bool moveBlocks);
  1567. void EmitDeferredCallProcessor(BfScopeData* scopeData, SLIList<BfDeferredCallEntry*>& callEntries, BfIRValue callTail);
  1568. void EmitDeferredCallProcessorInstances(BfScopeData* scopeData);
  1569. bool CanCast(BfTypedValue typedVal, BfType* toType, BfCastFlags castFlags = BfCastFlags_None);
  1570. bool AreSplatsCompatible(BfType* fromType, BfType* toType, bool* outNeedsMemberCasting);
  1571. BfType* GetClosestNumericCastType(const BfTypedValue& typedVal, BfType* wantType);
  1572. BfTypedValue BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfType* toType /*Can be System.Object or interface*/, const BfAllocTarget& allocTarget, BfCastFlags castFlags = BfCastFlags_None);
  1573. BfIRValue CastToFunction(BfAstNode* srcNode, const BfTypedValue& targetValue, BfMethodInstance* methodInstance, BfType* toType, BfCastFlags castFlags = BfCastFlags_None, BfIRValue irFunc = BfIRValue());
  1574. BfIRValue CastToValue(BfAstNode* srcNode, BfTypedValue val, BfType* toType, BfCastFlags castFlags = BfCastFlags_None, BfCastResultFlags* resultFlags = NULL);
  1575. BfTypedValue Cast(BfAstNode* srcNode, const BfTypedValue& val, BfType* toType, BfCastFlags castFlags = BfCastFlags_None);
  1576. BfPrimitiveType* GetIntCoercibleType(BfType* type);
  1577. BfTypedValue GetIntCoercible(const BfTypedValue& typedValue);
  1578. bool WantsDebugInfo();
  1579. BfTypeOptions* GetTypeOptions();
  1580. BfReflectKind GetUserReflectKind(BfTypeInstance* attrType);
  1581. BfReflectKind GetReflectKind(BfReflectKind reflectKind, BfTypeInstance* typeInstance);
  1582. void CleanupFileInstances();
  1583. void AssertErrorState();
  1584. void AssertParseErrorState();
  1585. void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize, BfAllocFlags allocFlags = BfAllocFlags_None);
  1586. bool IsAllocatorAligned();
  1587. BfIRValue AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*bool zeroMemory, bool defaultToMalloc*/);
  1588. BfIRValue GetMarkFuncPtr(BfType* type);
  1589. BfIRValue GetDbgRawAllocData(BfType* type);
  1590. BfIRValue AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue = BfIRValue(), BfIRValue arraySize = BfIRValue(), int arrayDim = 0, /*bool isRawArrayAlloc = false, bool zeroMemory = true*/BfAllocFlags allocFlags = BfAllocFlags_ZeroMemory, int alignOverride = -1);
  1591. void ValidateAllocation(BfType* type, BfAstNode* refNode);
  1592. bool IsOptimized();
  1593. void EmitAppendAlign(int align, int sizeMultiple = 0);
  1594. BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
  1595. bool IsTargetingBeefBackend();
  1596. bool WantsLifetimes();
  1597. bool HasCompiledOutput();
  1598. bool HasExecutedOutput();
  1599. void SkipObjectAccessCheck(BfTypedValue typedVal);
  1600. bool WantsObjectAccessCheck(BfType* type);
  1601. void EmitObjectAccessCheck(BfTypedValue typedVal);
  1602. bool WantsDebugHelpers();
  1603. void EmitEnsureInstructionAt();
  1604. void EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* targetType, BfIRBlock trueBlock, BfIRBlock falseBlock, bool nullSucceeds = false);
  1605. void EmitDynamicCastCheck(BfTypedValue typedVal, BfType* type, bool allowNull);
  1606. void CheckStaticAccess(BfTypeInstance* typeInstance);
  1607. BfTypedValue RemoveRef(BfTypedValue typedValue, bool makeInReadOnly = true);
  1608. BfTypedValue SanitizeAddr(BfTypedValue typedValue);
  1609. BfTypedValue ToRef(BfTypedValue typedValue, BfRefType* refType = NULL);
  1610. BfTypedValue LoadOrAggregateValue(BfTypedValue typedValue);
  1611. BfTypedValue LoadValue(BfTypedValue typedValue, BfAstNode* refNode = NULL, bool isVolatile = false);
  1612. BfTypedValue PrepareConst(BfTypedValue& typedValue);
  1613. void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
  1614. BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL);
  1615. BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false, bool forceAddressable = false);
  1616. BfTypedValue RemoveReadOnly(BfTypedValue typedValue);
  1617. BfTypedValue CopyValue(const BfTypedValue& typedValue);
  1618. BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);
  1619. BfTypedValue ExtractValue(BfTypedValue typedValue, BfFieldInstance* fieldInst, int fieldIdx);
  1620. BfIRValue ExtractValue(BfTypedValue typedValue, int dataIdx);
  1621. BfIRValue CreateIndexedValue(BfType* elementType, BfIRValue value, BfIRValue indexValue, bool isElementIndex = false);
  1622. BfIRValue CreateIndexedValue(BfType* elementType, BfIRValue value, int indexValue, bool isElementIndex = false);
  1623. bool CheckModifyValue(BfTypedValue& typedValue, BfAstNode* refNode, const char* modifyType = NULL);
  1624. BfIRValue GetInterfaceSlotNum(BfTypeInstance* ifaceType);
  1625. void HadSlotCountDependency();
  1626. BfTypedValue GetCompilerFieldValue(const StringImpl& str);
  1627. BfTypedValue GetCompilerFieldValue(const BfTypedValue typedVal);
  1628. BfTypedValue ReferenceStaticField(BfFieldInstance* fieldInstance);
  1629. BfFieldInstance* GetFieldInstance(BfTypeInstance* typeInst, int fieldIdx, const char* fieldName = NULL);
  1630. BfTypedValue GetThis(bool markUsing = true);
  1631. void MarkUsingThis();
  1632. BfLocalVariable* GetThisVariable();
  1633. bool IsInGeneric();
  1634. bool InDefinitionSection();
  1635. bool IsInSpecializedGeneric();
  1636. bool IsInSpecializedSection(); // Either a specialized generic or an injected mixin
  1637. bool IsInUnspecializedGeneric();
  1638. // BfStmtEvaluator.cpp
  1639. virtual void Visit(BfAstNode* astNode) override;
  1640. virtual void Visit(BfIdentifierNode* identifierNode) override;
  1641. virtual void Visit(BfTypeReference* typeRef) override;
  1642. virtual void Visit(BfEmptyStatement* astNode) override;
  1643. virtual void Visit(BfExpression* expressionStmt) override;
  1644. virtual void Visit(BfExpressionStatement* expressionStmt) override;
  1645. virtual void Visit(BfVariableDeclaration* varDecl) override;
  1646. virtual void Visit(BfLocalMethodDeclaration* methodDecl) override;
  1647. virtual void Visit(BfAttributedStatement* attribStmt) override;
  1648. virtual void Visit(BfThrowStatement* throwStmt) override;
  1649. virtual void Visit(BfDeleteStatement* deleteStmt) override;
  1650. virtual void Visit(BfSwitchStatement* switchStmt) override;
  1651. virtual void Visit(BfTryStatement* tryStmt) override;
  1652. virtual void Visit(BfCatchStatement* catchStmt) override;
  1653. virtual void Visit(BfFinallyStatement* finallyStmt) override;
  1654. virtual void Visit(BfCheckedStatement* checkedStmt) override;
  1655. virtual void Visit(BfUncheckedStatement* uncheckedStmt) override;
  1656. void DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool includeFalseStmt);
  1657. virtual void Visit(BfIfStatement* ifStmt) override;
  1658. virtual void Visit(BfReturnStatement* returnStmt) override;
  1659. virtual void Visit(BfYieldStatement* yieldStmt) override;
  1660. virtual void Visit(BfBreakStatement* breakStmt) override;
  1661. virtual void Visit(BfContinueStatement* continueStmt) override;
  1662. virtual void Visit(BfFallthroughStatement* fallthroughStmt) override;
  1663. virtual void Visit(BfUsingStatement* usingStmt) override;
  1664. virtual void Visit(BfDoStatement* doStmt) override;
  1665. virtual void Visit(BfRepeatStatement* doStmt) override;
  1666. virtual void Visit(BfWhileStatement* whileStmt) override;
  1667. virtual void Visit(BfForStatement* forStmt) override;
  1668. virtual void Visit(BfForEachStatement* forEachStmt) override;
  1669. virtual void Visit(BfDeferStatement* deferStmt) override;
  1670. virtual void Visit(BfBlock* block) override;
  1671. virtual void Visit(BfUnscopedBlock* block) override;
  1672. virtual void Visit(BfLabeledBlock* labeledBlock) override;
  1673. virtual void Visit(BfRootNode* rootNode) override;
  1674. virtual void Visit(BfInlineAsmStatement* asmStmt) override;
  1675. // Type helpers
  1676. BfGenericExtensionEntry* BuildGenericExtensionInfo(BfTypeInstance* genericTypeInst, BfTypeDef* partialTypeDef);
  1677. bool InitGenericParams(BfType* resolvedTypeRef);
  1678. bool FinishGenericParams(BfType* resolvedTypeRef);
  1679. bool ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* genericTypeInstance, bool ignoreErrors);
  1680. BfType* ResolveGenericMethodTypeRef(BfTypeReference* typeRef, BfMethodInstance* methodInstance, BfGenericParamInstance* genericParamInstance, BfTypeVector* methodGenericArgsOverride);
  1681. bool AreConstraintsSubset(BfGenericParamInstance* checkInner, BfGenericParamInstance* checkOuter);
  1682. bool CheckConstraintState(BfAstNode* refNode);
  1683. void ValidateGenericParams(BfGenericParamKind genericParamKind, Span<BfGenericParamInstance*> genericParams);
  1684. void SetGenericValidationError(BfTypeInstance* typeInst);
  1685. bool ShouldAllowMultipleDefinitions(BfTypeInstance* typeInst, BfTypeDef* firstDeclaringTypeDef, BfTypeDef* secondDeclaringTypeDef);
  1686. void CheckInjectNewRevision(BfTypeInstance* typeInstance);
  1687. void InitType(BfType* resolvedTypeRef, BfPopulateType populateType);
  1688. BfProtection FixProtection(BfProtection protection, BfProject* defProject);
  1689. bool CheckAccessMemberProtection(BfProtection protection, BfTypeInstance* memberType);
  1690. bool CheckDefineMemberProtection(BfProtection protection, BfType* memberType);
  1691. void CheckMemberNames(BfTypeInstance* typeInst);
  1692. void AddDependency(BfType* usedType, BfType* userType, BfDependencyMap::DependencyFlags flags, BfDepContext* depContext = NULL);
  1693. void AddDependency(BfGenericParamInstance* genericParam, BfTypeInstance* usingType);
  1694. void AddCallDependency(BfMethodInstance* methodInstance, bool devirtualized = false);
  1695. void AddFieldDependency(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfType* fieldType);
  1696. void TypeFailed(BfTypeInstance* typeInstance);
  1697. bool IsAttribute(BfTypeInstance* typeInst);
  1698. void PopulateGlobalContainersList(const BfGlobalLookup& globalLookup);
  1699. BfStaticSearch* GetStaticSearch();
  1700. BfInternalAccessSet* GetInternalAccessSet();
  1701. bool CheckInternalProtection(BfTypeDef* usingTypeDef);
  1702. void AddFailType(BfTypeInstance* typeInstance);
  1703. void DeferRebuildType(BfTypeInstance* typeInstance);
  1704. void MarkDerivedDirty(BfTypeInstance* typeInst);
  1705. void CheckAddFailType();
  1706. void PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType = BfPopulateType_Data);
  1707. BfTypeOptions* GetTypeOptions(BfTypeDef* typeDef);
  1708. bool ApplyTypeOptionMethodFilters(bool includeMethod, BfMethodDef* methodDef, BfTypeOptions* typeOptions);
  1709. int GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeInstance* typeInstance, bool checkTypeName);
  1710. void SetTypeOptions(BfTypeInstance* typeInstance);
  1711. BfModuleOptions GetModuleOptions();
  1712. BfCheckedKind GetDefaultCheckedKind();
  1713. void FinishCEParseContext(BfAstNode* refNode, BfTypeInstance* typeInstance, BfCEParseContext* ceParseContext);
  1714. BfCEParseContext CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* declaringType, const StringImpl& src, BfAstNode* refNode, BfCeTypeEmitSourceKind emitSourceKind);
  1715. void UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance, BfTypeDef* declaringType, const StringImpl& ctxString, BfAstNode* refNode, BfCeTypeEmitSourceKind emitSourceKind);
  1716. void HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* typeInst, BfFieldInstance* fieldInstance, BfCustomAttributes* customAttributes, Dictionary<BfTypeInstance*, BfIRValue>& foundAttributes, bool underlyingTypeDeferred);
  1717. void CEMixin(BfAstNode* refNode, const StringImpl& src);
  1718. void ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* typeInst, BfCEOnCompileKind onCompileKind, bool underlyingTypeDeferred);
  1719. void DoCEEmit(BfTypeInstance* typeInstance, bool& hadNewMembers, bool underlyingTypeDeferred);
  1720. void DoCEEmit(BfMethodInstance* methodInstance);
  1721. void PopulateUsingFieldData(BfTypeInstance* typeInstance);
  1722. void DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias);
  1723. void DoPopulateType_InitSearches(BfTypeInstance* typeInstance);
  1724. void DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance);
  1725. void DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType);
  1726. void DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred);
  1727. void DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateType = BfPopulateType_Data);
  1728. static BfModule* GetModuleFor(BfType* type);
  1729. void DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance);
  1730. void RebuildMethods(BfTypeInstance* typeInstance);
  1731. BfFieldInstance* GetFieldByName(BfTypeInstance* typeInstance, const StringImpl& fieldName, bool isRequired = true, BfAstNode* refNode = NULL);
  1732. void CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLocal = false);
  1733. void ResolveConstField(BfTypeInstance* typeInst, BfFieldInstance* fieldInstance, BfFieldDef* field, bool forceResolve = false);
  1734. BfTypedValue GetFieldInitializerValue(BfFieldInstance* fieldInstance, BfExpression* initializer = NULL, BfFieldDef* fieldDef = NULL, BfType* fieldType = NULL, bool doStore = false);
  1735. bool TryGetAppendedObjectInfo(BfFieldInstance* fieldInstance, int& dataSize, int& alignSize);
  1736. void AppendedObjectInit(BfFieldInstance* fieldInstance);
  1737. void MarkFieldInitialized(BfFieldInstance* fieldInstance);
  1738. bool IsThreadLocal(BfFieldInstance* fieldInstance);
  1739. BfType* ResolveVarFieldType(BfTypeInstance* typeInst, BfFieldInstance* fieldInstance, BfFieldDef* field);
  1740. void FindSubTypes(BfTypeInstance* classType, SizedArrayImpl<int>* outVals, SizedArrayImpl<BfTypeInstance*>* exChecks, bool isInterfacePass);
  1741. BfType* CheckUnspecializedGenericType(BfTypeInstance* genericTypeInst, BfPopulateType populateType);
  1742. BfTypeInstance* GetUnspecializedTypeInstance(BfTypeInstance* typeInst);
  1743. BfArrayType* CreateArrayType(BfType* resolvedType, int dimensions);
  1744. BfSizedArrayType* CreateSizedArrayType(BfType* resolvedType, int size);
  1745. BfUnknownSizedArrayType* CreateUnknownSizedArrayType(BfType* resolvedType, BfType* sizeParam);
  1746. BfPointerType* CreatePointerType(BfType* resolvedType);
  1747. BfPointerType* CreatePointerType(BfTypeReference* typeRef);
  1748. BfConstExprValueType* CreateConstExprValueType(const BfTypedValue& typedValue, bool allowCreate = true);
  1749. BfConstExprValueType* CreateConstExprValueType(const BfVariant& variant, BfType* type, bool allowCreate = true);
  1750. BfBoxedType* CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate = true);
  1751. BfTypeInstance* CreateTupleType(const BfTypeVector& fieldTypes, const Array<String>& fieldNames, bool allowVar = false);
  1752. BfTypeInstance* SantizeTupleType(BfTypeInstance* tupleType);
  1753. BfRefType* CreateRefType(BfType* resolvedTypeRef, BfRefType::RefKind refKind = BfRefType::RefKind_Ref);
  1754. BfModifiedTypeType* CreateModifiedTypeType(BfType* resolvedTypeRef, BfToken modifiedKind);
  1755. BfConcreteInterfaceType* CreateConcreteInterfaceType(BfTypeInstance* interfaceType);
  1756. BfTypeInstance* GetWrappedStructType(BfType* type, bool allowSpecialized = true);
  1757. BfTypeInstance* GetPrimitiveStructType(BfTypeCode typeCode);
  1758. BfPrimitiveType* GetPrimitiveType(BfTypeCode typeCode);
  1759. BfIRType GetIRLoweredType(BfTypeCode loweredTypeCode, BfTypeCode loweredTypeCode2);
  1760. BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false);
  1761. BfType* FixIntUnknown(BfType* type);
  1762. void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL);
  1763. void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
  1764. void FixValueActualization(BfTypedValue& typedVal, bool force = false);
  1765. bool TypeEquals(BfTypedValue& val, BfType* type);
  1766. BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
  1767. BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
  1768. void ResolveGenericParamConstraints(BfGenericParamInstance* genericParamInstance, bool isUnspecialized, Array<BfTypeReference*>* deferredResolveTypes = NULL);
  1769. String GenericParamSourceToString(const BfGenericParamSource& genericParamSource);
  1770. bool CheckGenericConstraints(const BfGenericParamSource& genericParamSource, BfType* checkArgType, BfAstNode* checkArgTypeRef, BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs = NULL, BfError** errorOut = NULL);
  1771. BfIRValue AllocLocalVariable(BfType* type, const StringImpl& name, bool doLifetimeEnd = true);
  1772. BfTypedValue CreateOutVariable(BfAstNode* refNode, BfVariableDeclaration* variableDeclaration, BfAstNode* paramNameNode, BfType* variableType, BfTypedValue initValue);
  1773. void MoveLocalToParentScope(BfLocalVariable* localVar);
  1774. void DoAddLocalVariable(BfLocalVariable* localVar);
  1775. void FixLocalVariable(BfLocalVariable* localVar);
  1776. void DoLocalVariableDebugInfo(BfLocalVariable* localVar, bool doAliasValue = false, BfIRValue declareBefore = BfIRValue(), BfIRInitType initType = BfIRInitType_NotSet);
  1777. BfLocalVariable* AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo = false, bool doAliasValue = false, BfIRValue declareBefore = BfIRValue(), BfIRInitType initType = BfIRInitType_NotSet);
  1778. bool TryLocalVariableInit(BfLocalVariable* localVar);
  1779. void LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit);
  1780. void CreateRetValLocal();
  1781. void CreateDIRetVal();
  1782. BfTypedValue CreateTuple(const Array<BfTypedValue>& values, const Array<String>& fieldNames);
  1783. void CheckTupleVariableDeclaration(BfTupleExpression* tupleExpr, BfType* initType);
  1784. void HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, BfTupleExpression* tupleExpr, BfTypedValue initTupleValue, bool isReadOnly, bool isConst, bool forceAddr, BfIRBlock* declBlock = NULL);
  1785. void HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl);
  1786. void HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArray<BfExpression*>& arguments, BfAstNode* tooFewRef, BfIRValue phiVal, BfIRBlock& matchedBlockStart,
  1787. BfIRBlock& matchedBlockEnd, BfIRBlock& falseBlockStart, BfIRBlock& falseBlockEnd, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough);
  1788. BfTypedValue TryCaseTupleMatch(BfTypedValue tupleVal, BfTupleExpression* tupleExpr, BfIRBlock* eqBlock, BfIRBlock* notEqBlock, BfIRBlock* matchBlock, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough);
  1789. BfTypedValue TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVal, BfExpression* expr, BfIRBlock* eqBlock, BfIRBlock* notEqBlock, BfIRBlock* matchBlock, int& uncondTagId, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough);
  1790. BfTypedValue HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& tagVal, BfEnumCaseBindExpression* bindExpr, BfIRBlock* eqBlock = NULL, BfIRBlock* notEqBlock = NULL, BfIRBlock* matchBlock = NULL, int* outEnumIdx = NULL);
  1791. void TryInitVar(BfAstNode* checkNode, BfLocalVariable* varDecl, BfTypedValue initValue, BfTypedValue& checkResult);
  1792. BfLocalVariable* HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfExprEvaluator* exprEvaluator = NULL);
  1793. BfLocalVariable* HandleVariableDeclaration(BfType* type, BfAstNode* nameNode, BfTypedValue val, bool updateSrcLoc = true, bool forceAddr = false);
  1794. BfLocalVariable* HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfTypedValue val, bool updateSrcLoc = true, bool forceAddr = false);
  1795. void CheckVariableDef(BfLocalVariable* variableDef);
  1796. BfScopeData* FindScope(BfAstNode* scopeName, BfMixinState* curMixinState, bool allowAcrossDeferredBlock);
  1797. BfScopeData* FindScope(BfAstNode* scopeName, bool allowAcrossDeferredBlock);
  1798. BfBreakData* FindBreakData(BfAstNode* scopeName);
  1799. void EmitLifetimeEnds(BfScopeData* scopeData);
  1800. void ClearLifetimeEnds();
  1801. bool HasDeferredScopeCalls(BfScopeData* scope);
  1802. void EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scope, BfIRBlock doneBlock = BfIRBlock());
  1803. void MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn = false);
  1804. BfGenericParamType* GetGenericParamType(BfGenericParamKind paramKind, int paramIdx);
  1805. BfType* ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, BfType* selfType, bool allowFail = false);
  1806. BfType* ResolveSelfType(BfType* type, BfType* selfType);
  1807. bool IsUnboundGeneric(BfType* type);
  1808. BfGenericParamInstance* GetGenericTypeParamInstance(int paramIdx, BfFailHandleKind failHandleKind = BfFailHandleKind_Normal);
  1809. BfGenericParamInstance* GetGenericParamInstance(BfGenericParamType* type, bool checkMixinBind = false, BfFailHandleKind failHandleKind = BfFailHandleKind_Normal);
  1810. BfType* GetGenericParamInstanceTypeConstraint(BfType* type, bool checkMixinBind = false, BfFailHandleKind failHandleKind = BfFailHandleKind_Normal);
  1811. void GetActiveTypeGenericParamInstances(SizedArray<BfGenericParamInstance*, 4>& genericParamInstance);
  1812. BfGenericParamInstance* GetMergedGenericParamData(BfType* type, BfGenericParamFlags& outFlags, BfType*& outTypeConstraint);
  1813. BfTypeInstance* GetBaseType(BfTypeInstance* typeInst);
  1814. void HandleTypeGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, int typeGenericParamIdx);
  1815. void HandleMethodGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, BfMethodDef* methodDef, int typeGenericParamIdx);
  1816. BfType* SafeResolveAliasType(BfTypeAliasType* aliasType);
  1817. bool ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTypeRef);
  1818. BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags);
  1819. void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef);
  1820. void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams);
  1821. BfTypeDef* GetActiveTypeDef(BfTypeInstance* typeInstanceOverride = NULL, bool useMixinDecl = false, bool useForeignImpl = false); // useMixinDecl is useful for type lookup, but we don't want the decl project to limit what methods the user can call
  1822. BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error, BfTypeLookupResultCtx* lookupResultCtx = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
  1823. BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
  1824. BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
  1825. BfTypeDef* FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, int numGenericParams = 0, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
  1826. BfTypedValue TryLookupGenericConstVaue(BfIdentifierNode* identifierNode, BfType* expectingType);
  1827. void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL);
  1828. void CheckIdentifierFixit(BfAstNode* node);
  1829. void TypeRefNotFound(BfTypeReference* typeRef, const char* appendName = NULL);
  1830. bool ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef);
  1831. void GetDelegateTypeRefAttributes(BfDelegateTypeRef* delegateTypeRef, BfCallingConvention& callingConvention);
  1832. BfType* ResolveTypeRef_Ref(BfTypeReference* typeRef, BfPopulateType populateType, BfResolveTypeRefFlags& resolveFlags, int numGenericArgs);
  1833. BfType* ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0, int numGenericArgs = 0);
  1834. BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0, bool resolveGenericParam = true);
  1835. BfType* ResolveTypeRef_Type(BfAstNode* astNode, const BfSizedArray<BfAstNode*>* genericArgs, BfPopulateType populateType, BfResolveTypeRefFlags& resolveFlags);
  1836. BfType* ResolveTypeRef_Ref(BfAstNode* astNode, const BfSizedArray<BfAstNode*>* genericArgs, BfPopulateType populateType, BfResolveTypeRefFlags& resolveFlags);
  1837. BfType* ResolveTypeRef_Ref(BfAstNode* astNode, BfPopulateType populateType);
  1838. BfType* ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfAstNode*>* genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
  1839. BfType* ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
  1840. BfType* ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
  1841. BfType* ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false, int numGenericArgs = 0, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
  1842. BfTypeDef* GetCombinedPartialTypeDef(BfTypeDef* type);
  1843. BfTypeInstance* GetOuterType(BfType* type);
  1844. bool IsInnerType(BfType* checkInnerType, BfType* checkOuterType);
  1845. bool IsInnerType(BfTypeDef* checkInnerType, BfTypeDef* checkOuterType);
  1846. bool TypeHasParentOrEquals(BfTypeDef* checkChildTypeDef, BfTypeDef* checkParentTypeDef);
  1847. BfTypeDef* FindCommonOuterType(BfTypeDef* type, BfTypeDef* type2);
  1848. bool TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType, bool checkAccessibility = true);
  1849. bool TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeDef* wantType);
  1850. int GetTypeDistance(BfType* fromType, BfType* toType);
  1851. bool IsTypeMoreSpecific(BfType* leftType, BfType* rightType);
  1852. bool GetBasePropertyDef(BfPropertyDef*& propDef, BfTypeInstance*& typeInst);
  1853. // Method helpers
  1854. void CheckInterfaceMethod(BfMethodInstance* methodInstance);
  1855. void CreateDelegateInvokeMethod();
  1856. BfType* GetDelegateReturnType(BfType* delegateType);
  1857. BfMethodInstance* GetDelegateInvokeMethod(BfTypeInstance* typeInstance);
  1858. String GetDelegateSignatureString(BfTypeInstance* typeInstance);
  1859. int GetSignatureId(const StringImpl& str);
  1860. int GetDelegateSignatureId(BfTypeInstance* typeInstance);
  1861. String GetLocalMethodName(const StringImpl& baseName, BfAstNode* anchorNode, BfMethodState* declMethodState, BfMixinState* declMixinState);
  1862. BfMethodDef* GetLocalMethodDef(BfLocalMethod* localMethod);
  1863. BfModuleMethodInstance GetLocalMethodInstance(BfLocalMethod* localMethod, const BfTypeVector& methodGenericArguments, BfMethodInstance* methodInstance = NULL, bool force = false);
  1864. int GetLocalInferrableGenericArgCount(BfMethodDef* methodDef);
  1865. void GetMethodCustomAttributes(BfMethodInstance* methodInstance);
  1866. void SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& mangledName, bool isTemporaryFunc, bool* outIsIntrinsic);
  1867. void CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& mangledName);
  1868. void StartMethodDeclaration(BfMethodInstance* methodInstance, BfMethodState* prevMethodState);
  1869. void DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool isTemporaryFunc, bool addToWorkList = true);
  1870. void AddMethodToWorkList(BfMethodInstance* methodInstance);
  1871. bool IsInterestedInMethod(BfTypeInstance* typeInstance, BfMethodDef* methodDef);
  1872. void CalcAppendAlign(BfMethodInstance* methodInst);
  1873. BfAllowAppendKind GetBaseAllowAppend(BfMethodInstance* curMethodInstance);
  1874. BfTypedValue TryConstCalcAppend(BfMethodInstance* methodInst, SizedArrayImpl<BfIRValue>& args, bool force = false);
  1875. BfTypedValue CallBaseCtorCalc(bool constOnly);
  1876. void EmitCtorCalcAppend();
  1877. void CreateStaticCtor();
  1878. BfIRValue CreateDllImportGlobalVar(BfMethodInstance* methodInstance, bool define = false);
  1879. void CreateDllImportMethod();
  1880. BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance);
  1881. void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined);
  1882. void EmitInitBlocks(const std::function<void(BfAstNode*)>& initBlockCallback);
  1883. void EmitCtorBody(bool& skipBody);
  1884. void EmitDtorBody();
  1885. void EmitEnumToStringBody();
  1886. void EmitTupleToStringBody();
  1887. void EmitGCMarkAppended(BfTypedValue markVal);
  1888. void EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int memberDepth, int curOffset, HashSet<int>& objectOffsets, BfModuleMethodInstance markFromGCThreadMethodInstance, bool isAppendObject = false);
  1889. void EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance markFromGCThreadMethodInstance);
  1890. void EmitGCMarkMembers();
  1891. void EmitGCFindTLSMembers();
  1892. void EmitIteratorBlock(bool& skipBody);
  1893. void EmitEquals(BfTypedValue leftValue, BfTypedValue rightValue, BfIRBlock exitBB, bool strictEquals);
  1894. void CreateFakeCallerMethod(const String& funcName);
  1895. void CallChainedMethods(BfMethodInstance* methodInstance, bool reverse = false);
  1896. void AddHotDataReferences(BfHotDataReferenceBuilder* builder);
  1897. void ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfType* thisType, bool wantsDIData, SizedArrayImpl<BfIRMDNode>* diParams);
  1898. void ProcessMethod_ProcessDeferredLocals(int startIdx = 0);
  1899. void ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup = false, bool forceIRWrites = false);
  1900. void CreateDynamicCastMethod();
  1901. void CreateDelegateEqualsMethod();
  1902. void CreateValueTypeEqualsMethod(bool strictEquals);
  1903. BfIRFunction GetIntrinsic(BfMethodInstance* methodInstance, bool reportFailure = false);
  1904. BfIRFunction GetBuiltInFunc(BfBuiltInFuncType funcType);
  1905. BfIRValue CreateFunctionFrom(BfMethodInstance* methodInstance, bool tryExisting, bool isInlined);
  1906. void EvaluateWithNewConditionalScope(BfExprEvaluator& exprEvaluator, BfExpression* expr, BfEvalExprFlags flags);
  1907. BfTypedValue CreateValueFromExpression(BfExprEvaluator& exprEvaluator, BfExpression* expr, BfType* wantTypeRef = NULL, BfEvalExprFlags flags = BfEvalExprFlags_None, BfType** outOrigType = NULL);
  1908. BfTypedValue CreateValueFromExpression(BfExpression* expr, BfType* wantTypeRef = NULL, BfEvalExprFlags flags = BfEvalExprFlags_None, BfType** outOrigType = NULL);
  1909. BfTypedValue GetOrCreateVarAddr(BfExpression* expr);
  1910. BfMethodInstance* GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL);
  1911. BfMethodInstance* GetRawMethodInstance(BfTypeInstance* typeInstance, BfMethodDef* methodDef);
  1912. BfMethodInstance* GetRawMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false, bool allowMixin = false);
  1913. BfMethodInstance* GetUnspecializedMethodInstance(BfMethodInstance* methodInstance, bool useUnspecializedType = true); // Unspecialized owner type and unspecialized method type
  1914. int GetGenericParamAndReturnCount(BfMethodInstance* methodInstance);
  1915. BfModule* GetSpecializedMethodModule(const SizedArrayImpl<BfProject*>& projectList);
  1916. BfModuleMethodInstance GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None);
  1917. BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false);
  1918. BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, const Array<BfType*>& paramTypes, bool checkBase = false);
  1919. BfModuleMethodInstance GetInternalMethod(const StringImpl& methodName, int paramCount = -1);
  1920. BfOperatorInfo* GetOperatorInfo(BfTypeInstance* typeInstance, BfOperatorDef* operatorDef);
  1921. BfType* CheckOperator(BfTypeInstance* typeInstance, BfOperatorDef* operatorDef, const BfTypedValue& lhs, const BfTypedValue& rhs);
  1922. bool IsMethodImplementedAndReified(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false);
  1923. bool HasMixin(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount, bool checkBase = false);
  1924. bool CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstance* methodB); // Doesn't compare return types nor static
  1925. bool StrictCompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstance* methodB); // Compares return types and static
  1926. bool IsCompatibleInterfaceMethod(BfMethodInstance* methodA, BfMethodInstance* methodB);
  1927. void UniqueSlotVirtualMethod(BfMethodInstance* methodInstance);
  1928. void CompareDeclTypes(BfTypeInstance* typeInst, BfTypeDef* newDeclType, BfTypeDef* prevDeclType, bool& isBetter, bool& isWorse);
  1929. bool SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityContext* ambiguityContext = NULL);
  1930. void CheckOverridenMethod(BfMethodInstance* methodInstance, BfMethodInstance* methodOverriden);
  1931. bool SlotInterfaceMethod(BfMethodInstance* methodInstance);
  1932. void SetMethodDependency(BfMethodInstance* methodInstance);
  1933. BfModuleMethodInstance ReferenceExternalMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None);
  1934. BfModule* GetOrCreateMethodModule(BfMethodInstance* methodInstance);
  1935. BfModuleMethodInstance GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None, BfTypeInstance* foreignType = NULL, BfModule* referencingModule = NULL);
  1936. BfModuleMethodInstance GetMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None);
  1937. BfMethodInstance* GetOuterMethodInstance(BfMethodInstance* methodInstance); // Only useful for local methods
  1938. void SetupMethodIdHash(BfMethodInstance* methodInstance);
  1939. bool CheckUseMethodInstance(BfMethodInstance* methodInstance, BfAstNode* refNode);
  1940. // Type Data
  1941. BfIRValue CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* outNumElements = NULL, String* outMangledName = NULL);
  1942. BfIRValue GetClassVDataPtr(BfTypeInstance* typeInstance);
  1943. BfIRValue CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTypeInstance* implTypeInst, int startVirtIdx);
  1944. BfIRValue CreateTypeDataRef(BfType* type, bool forceConstant = false);
  1945. void EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType, BfIRValue arg, SizedArrayImpl<uint8>& data, Dictionary<int, int>& usedStringIdMap);
  1946. BfIRValue CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx);
  1947. void CreateSlotOfs(BfTypeInstance* typeInstance);
  1948. BfIRValue GetTypeTypeData(BfType* type, BfCreateTypeDataContext& ctx, bool needsTypeData, bool wantsTypeDecl, bool needsTypeNames, int& typeFlags, int& typeCode);
  1949. BfIRValue CreateTypeDeclData(BfType* type, BfProject* curProject);
  1950. BfIRValue CreateTypeData(BfType* type, BfCreateTypeDataContext& ctx, bool forceReflectFields, bool needsTypeData, bool needsTypeNames, bool needsVData);
  1951. BfIRValue FixClassVData(BfIRValue value);
  1952. public:
  1953. BfModule(BfContext* context, const StringImpl& moduleName);
  1954. virtual ~BfModule();
  1955. void Init(bool isFullRebuild = true);
  1956. bool WantsFinishModule();
  1957. bool IsHotCompile();
  1958. void FinishInit();
  1959. void CalcGeneratesCode();
  1960. void ReifyModule();
  1961. void UnreifyModule();
  1962. void Cleanup();
  1963. void StartNewRevision(RebuildKind rebuildKind = RebuildKind_All, bool force = false);
  1964. void PrepareForIRWriting(BfTypeInstance* typeInst);
  1965. void SetupIRBuilder(bool dbgVerifyCodeGen);
  1966. void EnsureIRBuilder(bool dbgVerifyCodeGen = false);
  1967. void DbgFinish();
  1968. BfIRValue CreateForceLinkMarker(BfModule* module, String* outName);
  1969. void ClearModuleData(bool clearTransientData = true);
  1970. void DisownMethods();
  1971. void ClearModule();
  1972. void StartExtension(); // For new method specializations
  1973. bool Finish();
  1974. void RemoveModuleData();
  1975. void ReportMemory(MemReporter* memReporter);
  1976. };
  1977. class BfAutoParentNodeEntry
  1978. {
  1979. public:
  1980. BfModule* mModule;
  1981. BfParentNodeEntry mParentNodeEntry;
  1982. BfAutoParentNodeEntry(BfModule* module, BfAstNode* node)
  1983. {
  1984. mModule = module;
  1985. mParentNodeEntry.mNode = node;
  1986. mParentNodeEntry.mPrev = module->mParentNodeEntry;
  1987. module->mParentNodeEntry = &mParentNodeEntry;
  1988. }
  1989. ~BfAutoParentNodeEntry()
  1990. {
  1991. mModule->mParentNodeEntry = mParentNodeEntry.mPrev;
  1992. }
  1993. };
  1994. class BfVDataModule : public BfModule
  1995. {
  1996. public:
  1997. HashSet<int> mDefinedStrings;
  1998. public:
  1999. BfVDataModule(BfContext* context) : BfModule(context, StringImpl::MakeRef("vdata"))
  2000. {
  2001. }
  2002. };
  2003. NS_BF_END
  2004. namespace std
  2005. {
  2006. template<>
  2007. struct hash<Beefy::BfMethodRef>
  2008. {
  2009. size_t operator()(const Beefy::BfMethodRef& val) const
  2010. {
  2011. if (val.mTypeInstance == NULL)
  2012. return 0;
  2013. return val.mTypeInstance->mTypeId ^ (val.mMethodNum << 10);
  2014. }
  2015. };
  2016. template<>
  2017. struct hash<Beefy::BfVDataExtEntry>
  2018. {
  2019. size_t operator()(const Beefy::BfVDataExtEntry& val) const
  2020. {
  2021. return ((size_t)(val.mDeclTypeInst) * 17) ^ (size_t)(val.mDeclTypeInst);
  2022. }
  2023. };
  2024. template<>
  2025. struct hash<Beefy::BfLocalVarEntry>
  2026. {
  2027. size_t operator()(const Beefy::BfLocalVarEntry& val) const
  2028. {
  2029. return std::hash<Beefy::String>()(val.mLocalVar->mName);
  2030. }
  2031. };
  2032. }