11import {
2+ ContractIdx ,
23 BasicBlock ,
34 BasicBlockIdx ,
45 BasicBlockKind ,
56 CFG ,
67 CFGIdx ,
78 CompilationUnit ,
89 Contract ,
9- ContractIdx ,
1010 ContractName ,
1111 Edge ,
1212 FunctionKind ,
@@ -113,14 +113,15 @@ export class TactIRBuilder {
113113 private registerFunctions ( ) : void {
114114 this . functionIndexes = this . ast . functions . reduce ( ( acc , fun ) => {
115115 if ( fun . kind == "function_def" ) {
116+ const funName = fun . name . text as FunctionName ;
116117 const idx = this . registerCFGIdx (
117- fun . name . text ,
118+ funName ,
118119 fun . id ,
119120 "function" ,
120121 fun . loc . origin ,
121122 fun . loc ,
122123 ) ;
123- acc . set ( fun . name . text , idx ) ;
124+ acc . set ( funName , idx ) ;
124125 }
125126 return acc ;
126127 } , new Map < FunctionName , CFGIdx > ( ) ) ;
@@ -133,12 +134,13 @@ export class TactIRBuilder {
133134 private createFunctions ( ) : Map < CFGIdx , CFG > {
134135 return this . ast . functions . reduce ( ( acc , fun ) => {
135136 if ( fun . kind == "function_def" ) {
136- const idx = this . functionIndexes . get ( fun . name . text ) ! ;
137+ const funName = fun . name . text as FunctionName ;
138+ const idx = this . functionIndexes . get ( funName ) ! ;
137139 acc . set (
138140 idx ,
139141 this . createCFGFromStatements (
140142 idx ,
141- fun . name . text ,
143+ funName ,
142144 fun . id ,
143145 "function" ,
144146 fun . loc . origin ,
@@ -157,13 +159,21 @@ export class TactIRBuilder {
157159 private getMethodInfo (
158160 decl : AstContractDeclaration ,
159161 contractId : number ,
160- ) : [ string | undefined , FunctionKind | undefined , AstStatement [ ] | null ] {
162+ ) : [
163+ FunctionName | undefined ,
164+ FunctionKind | undefined ,
165+ AstStatement [ ] | null ,
166+ ] {
161167 return decl . kind === "function_def"
162- ? [ decl . name . text , "method" , decl . statements ]
168+ ? [ decl . name . text as FunctionName , "method" , decl . statements ]
163169 : decl . kind === "contract_init"
164- ? [ `init_${ contractId } ` , "method" , decl . statements ]
170+ ? [ `init_${ contractId } ` as FunctionName , "method" , decl . statements ]
165171 : decl . kind === "receiver"
166- ? [ generateReceiveName ( decl ) , "receive" , decl . statements ]
172+ ? [
173+ generateReceiveName ( decl ) as FunctionName ,
174+ "receive" ,
175+ decl . statements ,
176+ ]
167177 : [ undefined , undefined , null ] ;
168178 }
169179
@@ -173,7 +183,7 @@ export class TactIRBuilder {
173183 private registerContracts ( ) : void {
174184 this . methodIndexes = this . ast . types . reduce ( ( acc , entry ) => {
175185 if ( entry . kind == "contract" ) {
176- const contractName = entry . name . text ;
186+ const contractName = entry . name . text as ContractName ;
177187 const methodsMap = entry . declarations . reduce ( ( methodAcc , decl ) => {
178188 const [ name , kind , _ ] = this . getMethodInfo ( decl , entry . id ) ;
179189 // NOTE: We don't create CFG entries for asm functions.
@@ -201,7 +211,7 @@ export class TactIRBuilder {
201211 private createContracts ( ) : Map < ContractIdx , Contract > {
202212 return this . ast . types . reduce ( ( acc , entry ) => {
203213 if ( entry . kind == "contract" ) {
204- const contractName = entry . name . text ;
214+ const contractName = entry . name . text as ContractName ;
205215 const methodsMap = this . methodIndexes . get ( contractName ) ! ;
206216 const methodCFGs = entry . declarations . reduce ( ( methodAcc , decl ) => {
207217 const [ name , kind , stmts ] = this . getMethodInfo ( decl , entry . id ) ;
@@ -281,11 +291,15 @@ export class TactIRBuilder {
281291 parentCalls : Set < CFGIdx > = new Set ( ) ,
282292 ) : Set < CFGIdx > {
283293 switch ( expr . kind ) {
284- case "method_call" : // method
294+ case "method_call" :
285295 if ( expr . self . kind === "id" && isSelfId ( expr . self ) ) {
286- const contractMethods = this . methodIndexes . get ( expr . self . text ) ;
296+ const contractMethods = this . methodIndexes . get (
297+ expr . self . text as ContractName ,
298+ ) ;
287299 if ( contractMethods ) {
288- const methodIdx = contractMethods . get ( expr . method . text ) ;
300+ const methodIdx = contractMethods . get (
301+ expr . method . text as FunctionName ,
302+ ) ;
289303 if ( methodIdx !== undefined ) {
290304 parentCalls . add ( methodIdx ) ;
291305 } else {
@@ -310,8 +324,10 @@ export class TactIRBuilder {
310324 expr . args . forEach ( ( arg ) => this . collectFunctionCalls ( arg , parentCalls ) ) ;
311325 this . collectFunctionCalls ( expr . self , parentCalls ) ;
312326 break ;
313- case "static_call" : // free function
314- const funcIdx = this . functionIndexes . get ( expr . function . text ) ;
327+ case "static_call" :
328+ const funcIdx = this . functionIndexes . get (
329+ expr . function . text as FunctionName ,
330+ ) ;
315331 if ( funcIdx !== undefined ) {
316332 parentCalls . add ( funcIdx ) ;
317333 }
0 commit comments