@@ -10,6 +10,7 @@ import {RUNTIME_DEFINITION_FILE} from "@static-script/runtime";
1010import { LANGUAGE_DEFINITION_FILE } from "../../constants" ;
1111import { CMangler } from "./c.mangler" ;
1212import { ManglerInterface } from "./mangler.interface" ;
13+ import { SignatureDeclaration } from "typescript" ;
1314
1415export function passReturnStatement ( parent : ts . ReturnStatement , ctx : Context , builder : llvm . IRBuilder ) {
1516 if ( ! parent . expression ) {
@@ -375,6 +376,29 @@ function buildFromPostfixUnaryExpression(
375376 }
376377}
377378
379+
380+ function mangleNameFromDecleration (
381+ declaration : ts . SignatureDeclaration ,
382+ ctx : Context ,
383+ mangler : ManglerInterface
384+ ) {
385+ if ( declaration . kind === ts . SyntaxKind . MethodDeclaration ) {
386+ const left = ctx . typeChecker . getTypeAtLocation ( declaration . parent ! ) as ts . ObjectType ;
387+
388+ return mangler . getMethodName (
389+ < string > left . symbol . escapedName ,
390+ < string > ( < ts . Identifier > declaration . name ) . escapedText ,
391+ declaration . parameters
392+ ) ;
393+ }
394+
395+ return mangler . getFunctionName (
396+ < string > ( < ts . Identifier > declaration . name ) . escapedText ,
397+ declaration . parameters
398+ ) ;
399+ }
400+
401+
378402function buildCalleFromCallExpression (
379403 expr : ts . CallExpression ,
380404 ctx : Context ,
@@ -386,16 +410,16 @@ function buildCalleFromCallExpression(
386410 return ctx . signature . get ( calleSignature ) ;
387411 }
388412
389- const symbolDeclaration = < ts . SignatureDeclaration > calleSignature . declaration ;
390- if ( symbolDeclaration . name ) {
391- const sourceFile = symbolDeclaration . getSourceFile ( ) ;
413+ const declaration = < ts . SignatureDeclaration > calleSignature . declaration ;
414+ if ( declaration . name ) {
415+ const sourceFile = declaration . getSourceFile ( ) ;
392416
393417 if ( sourceFile . fileName === RUNTIME_DEFINITION_FILE ) {
394418 const llvmFunction = declareFunctionFromDefinition (
395- < ts . FunctionDeclaration > symbolDeclaration ,
419+ < ts . FunctionDeclaration > declaration ,
396420 ctx ,
397421 builder ,
398- CPPMangler
422+ mangleNameFromDecleration ( declaration , ctx , CPPMangler )
399423 ) ;
400424
401425 ctx . signature . set ( calleSignature , llvmFunction ) ;
@@ -405,10 +429,10 @@ function buildCalleFromCallExpression(
405429
406430 if ( sourceFile . fileName === LANGUAGE_DEFINITION_FILE ) {
407431 const llvmFunction = declareFunctionFromDefinition (
408- < ts . FunctionDeclaration > symbolDeclaration ,
432+ < ts . FunctionDeclaration > declaration ,
409433 ctx ,
410434 builder ,
411- CMangler
435+ mangleNameFromDecleration ( declaration , ctx , CMangler )
412436 ) ;
413437
414438
@@ -449,7 +473,7 @@ function declareFunctionFromDefinition(
449473 stmt : ts . FunctionDeclaration ,
450474 ctx : Context ,
451475 builder : llvm . IRBuilder ,
452- mangler : ManglerInterface
476+ name : string
453477) : llvm . Function {
454478 let fnType = llvm . FunctionType . get (
455479 stmt . type ? NativeTypeResolver . getType ( ctx . typeChecker . getTypeFromTypeNode ( stmt . type ) , ctx ) . getType ( ) : llvm . Type . getVoidTy ( ctx . llvmContext ) ,
@@ -469,7 +493,7 @@ function declareFunctionFromDefinition(
469493 return llvm . Function . create (
470494 fnType ,
471495 llvm . LinkageTypes . ExternalLinkage ,
472- mangler . getFunctionName ( < string > stmt . name . escapedText , stmt . parameters ) ,
496+ name ,
473497 ctx . llvmModule
474498 ) ;
475499}
0 commit comments