import { ArkParameterRef } from '../base/Ref'; import { ArkReturnVoidStmt, Stmt } from '../base/Stmt'; import { GenericType, Type } from '../base/Type'; import { Value } from '../base/Value'; import { Cfg } from '../graph/Cfg'; import { ViewTree } from '../graph/ViewTree'; import { ArkBody } from './ArkBody'; import { ArkClass } from './ArkClass'; import { MethodSignature, MethodSubSignature } from './ArkSignature'; import { BodyBuilder } from './builder/BodyBuilder'; import { ArkExport, ExportType } from './ArkExport'; import { FullPosition, LineCol } from '../base/Position'; import { ArkBaseModel } from './ArkBaseModel'; import { ArkError } from '../common/ArkError'; import { Local } from '../base/Local'; import { ArkFile, Language } from './ArkFile'; import { MethodParameter } from './builder/ArkMethodBuilder'; import { CxxBodyBuilder } from '../../frontend/cppFrontend/model/builder/BodyBuilder'; export declare const arkMethodNodeKind: string[]; /** * @category core/model */ export declare class ArkMethod extends ArkBaseModel implements ArkExport { private declaringArkClass; private outerMethod?; private genericTypes?; private declareSignatures?; /** The full positions of the method declarations (for interface/abstract methods with separate declarations). */ private declareOriginFullPositions?; private implSignature?; /** The full position of the method implementation. * Undefined when the method has no implementation (e.g., interface method). */ private implOriginFullPosition?; private sourceCode?; private body?; private viewTree?; private bodyBuilder?; private CxxBodyBuilder?; constructor(); /** * Returns the program language of the file where this method defined. */ getLanguage(): Language; getExportType(): ExportType; getName(): string; /** * Returns the source text of the method extracted from the declaring ArkFile * using the method's origin position. Implements lazy loading with caching. * Returns implementation position's source if available, otherwise returns * first declaration position's source. * @returns The source text of the method, or undefined if unavailable. */ getCode(): string | undefined; /** * @deprecated Source text is now stored on ArkFile only. This method has no effect. * @param _code - The source code (ignored). */ setCode(_code: string): void; /** * @deprecated Since version 1.0.91. Use getDeclareOriginFullPositions().map(p => p.getFirstLine()) instead. * @returns null or the lines of the method's declarations with number type. */ getDeclareLines(): number[] | null; /** * @deprecated Since version 1.0.91. Use getDeclareOriginFullPositions().map(p => p.getFirstCol()) instead. * @returns null or the columns of the method's declarations with number type. */ getDeclareColumns(): number[] | null; /** * @deprecated Since version 1.0.91. Use setDeclareOriginFullPositions() instead. * @param lines - the number of lines. * @param columns - the number of columns. */ setDeclareLinesAndCols(lines: number[], columns: number[]): void; /** * @deprecated Since version 1.0.91. Use setDeclareOriginFullPositions() instead. * @param lineCols - the encoded lines and columns with LineCol type. */ setDeclareLineCols(lineCols: LineCol[]): void; /** * @deprecated Since version 1.0.91. Use getDeclareOriginFullPositions().map() instead. * @returns null or the encoded lines and columns of the method's declarations with LineCol type. */ getDeclareLineCols(): LineCol[] | null; /** * Returns the full positions of the method declarations in the source file. * @returns An array of full positions in the source code, or null if the method has no separate declarations. */ getDeclareOriginFullPositions(): FullPosition[] | null; /** * Sets the full positions of the method declarations in the source file. * @param positions - An array of full positions in the source code to set. */ setDeclareOriginFullPositions(positions: FullPosition[]): void; /** * @deprecated Since version 1.0.91. Use getImplOriginFullPosition()?.getFirstLine() instead. * @returns null or the number of the line. */ getLine(): number | null; /** * @deprecated Since version 1.0.91. Use setImplOriginFullPosition() instead. * @param line - the line number of the method implementation. */ setLine(line: number): void; /** * @deprecated Since version 1.0.91. Use getImplOriginFullPosition()?.getFirstCol() instead. * @returns null or the number of the column. */ getColumn(): number | null; /** * @deprecated Since version 1.0.91. Use setImplOriginFullPosition() instead. * @param column - the column number of the method implementation. */ setColumn(column: number): void; /** * @deprecated Since version 1.0.91. Use getImplOriginFullPosition() instead. * @returns null or the encoded line and column of the method's implementation with LineCol type. */ getLineCol(): LineCol | null; /** * @deprecated Since version 1.0.91. Use setImplOriginFullPosition() instead. * @param lineCol - the encoded line and column with LineCol type. */ setLineCol(lineCol: LineCol): void; /** * Returns the full position of the method implementation in the source file. * @returns The full position in the source code, or undefined if the method has no implementation * (e.g., interface/abstract methods with separate declarations) or was automatically * generated during IR construction. */ getImplOriginFullPosition(): FullPosition | undefined; /** * Sets the full position of the method implementation in the source file. * @param position - The full position in the source code to set. */ setImplOriginFullPosition(position: FullPosition): void; /** * Returns the declaring class of the method. * @returns The declaring class of the method. */ getDeclaringArkClass(): ArkClass; setDeclaringArkClass(declaringArkClass: ArkClass): void; getDeclaringArkFile(): ArkFile; isDefaultArkMethod(): boolean; isAnonymousMethod(): boolean; getParameters(): MethodParameter[]; getReturnType(): Type; /** * Get all declare signatures. * The results could be null if there is no seperated declaration of the method. * @returns null or the method declare signatures. */ getDeclareSignatures(): MethodSignature[] | null; /** * Get the index of the matched method declare signature among all declare signatures. * The index will be -1 if there is no matched signature found. * @param targetSignature - the target declare signature want to search. * @returns -1 or the index of the matched signature. */ getDeclareSignatureIndex(targetSignature: MethodSignature): number; /** * Get the method signature of the implementation. * The signature could be null if the method is only a declaration which body is undefined. * @returns null or the method implementation signature. */ getImplementationSignature(): MethodSignature | null; /** * Get the method signature of the implementation or the first declaration if there is no implementation. * For a method, the implementation and declaration signatures must not be undefined at the same time. * A {@link MethodSignature} includes: * - Class Signature: indicates which class this method belong to. * - Method SubSignature: indicates the detail info of this method such as method name, parameters, returnType, etc. * @returns The method signature. * @example * 1. Get the signature of method mtd. ```typescript let signature = mtd.getSignature(); // ... ... ``` */ getSignature(): MethodSignature; /** * Set signatures of all declarations. * It will reset the declaration signatures if they are already defined before. * @param signatures - one signature or a list of signatures. */ setDeclareSignatures(signatures: MethodSignature | MethodSignature[]): void; /** * Reset signature of one declaration with the specified index. * Will do nothing if the index doesn't exist. * @param signature - new signature want to set. * @param index - index of signature want to set. */ setDeclareSignatureWithIndex(signature: MethodSignature, index: number): void; /** * Set signature of implementation. * It will reset the implementation signature if it is already defined before. * @param signature - signature of implementation. */ setImplementationSignature(signature: MethodSignature): void; getSubSignature(): MethodSubSignature; getGenericTypes(): GenericType[] | undefined; isGenericsMethod(): boolean; setGenericTypes(genericTypes: GenericType[]): void; getBodyBuilder(): BodyBuilder | undefined; getCxxBodyBuilder(): CxxBodyBuilder | undefined; /** * Get {@link ArkBody} of a Method. * A {@link ArkBody} contains the CFG and actual instructions or operations to be executed for a method. * It is analogous to the body of a function or method in high-level programming languages, * which contains the statements and expressions that define what the function does. * @returns The {@link ArkBody} of a method. * @example * 1. Get cfg or stmt through ArkBody. ```typescript let cfg = this.scene.getMethod()?.getBody().getCfg(); const body = arkMethod.getBody() ``` 2. Get local variable through ArkBody. ```typescript arkClass.getDefaultArkMethod()?.getBody().getLocals.forEach(local=>{...}) let locals = arkFile().getDefaultClass().getDefaultArkMethod()?.getBody()?.getLocals(); ``` */ getBody(): ArkBody | undefined; setBody(body: ArkBody): void; /** * Release the method body (ArkBody/CFG/Stmt/Expr/Locals) and view tree to free memory. * Intended for module unload/eviction: the heavy IR data is dropped so it can be GC'd, * even if the ArkMethod skeleton is still referenced. The body/viewTree are rebuilt on * reload if the module is loaded again at BODIES level. */ clearBodyAndSupplementary(): void; /** * Get the CFG (i.e., control flow graph) of a method. * The CFG is a graphical representation of all possible control flow paths within a method's body. * A CFG consists of blocks, statements and goto control jumps. * @returns The CFG (i.e., control flow graph) of a method. * @example * 1. get stmt through ArkBody cfg. ```typescript body = arkMethod.getBody(); const cfg = body.getCfg(); for (const threeAddressStmt of cfg.getStmts()) { ... ... } ``` 2. get blocks through ArkBody cfg. ```typescript const body = arkMethod.getBody(); const blocks = [...body.getCfg().getBlocks()]; for (let i=0; i