UNPKG

@specs-feup/lara

Version:

A js port of the popular framework for building source-to-source compilers

207 lines 6.19 kB
import { LaraJoinPoint } from "../../LaraJoinPoint.js"; type ElementType = { content: string | number; type: number; }; /** * Logger object, for inserting code that prints/saves information to files. * * @param isGlobal - Not implemented, please ignore * @param filename - If set, instead of printing, will insert code for writing output to this file * */ export default abstract class LoggerBase<T extends LaraJoinPoint> { protected isGlobal: boolean; protected filename: string | undefined; protected currentElements: ElementType[]; private functionMap; protected afterJp: T | undefined; Type: Map<string, number>; constructor(isGlobal?: boolean, filename?: string); /** * Used for both C and Java printf functions */ printfFormat: Record<number, string | undefined>; isGlobalFn(): void; /** * The 'last' join point after .log() is called. * */ getAfterJp(): T | undefined; private clear; abstract log($jp: T, insertBefore: boolean): void; /** * Helper method which call 'log' with 'insertBefore' set to true * */ logBefore($jp: T): void; /** * Verifies that the given $jp is inside a function. * * Requires global attribute 'ancestor'. * * @returns true if $jp is inside a function, false otherwise */ _validateJp($jp: any, functionJpName?: string): boolean; _insert($jp: T, insertBefore: boolean, code: string): void; /** * Inserts the given code before/after the given join point. * * Override this method if you need to specialize the insertion. */ _insertCode($jp: any, insertBefore: boolean, code: string): void; /** * Appends the given string to the current buffer. * * @param text - The text to append * @returns The current logger instance */ append(text: string): this; /** * The same as 'append'. * * @param text - the text to append * @returns The current logger instance */ text(text: string): this; /** * The same as 'append', but adds a new line at the end of the buffer. * * @param text - the text to append * @returns The current logger instance */ appendln(text: string): this; /** * Appends a new line to the buffer. * * @returns The current logger instance */ ln(): this; /** * Appends a tab to the buffer. * * @returns The current logger instance */ tab(): this; /** * Appends an expression that represents a double. * * @param expr - The expression to append * @returns The current logger instance */ appendDouble(expr: T | string): this; /** * The same as 'appendDouble'. * * @param expr - The expression to append * @returns The current logger instance */ double(expr: T | string): this; /** * Appends an expression that represents a int. * * @param expr - The expression to append * @returns The current logger instance */ appendInt(expr: T | string): this; /** * The same as 'appendInt'. * * @param expr - The expression to append * @returns The current logger instance */ int(expr: T | string): this; /** * Appends an expression that represents a long. * * @param expr - The expression to append * @returns The current logger instance */ appendLong(expr: T | string): this; /** * The same as 'appendLong'. * * @param expr - The expression to append * @returns The current logger instance */ long(expr: T | string): this; /** * Appends an expression that represents a string. * * @param expr - The expression to append * @returns The current logger instance */ appendString(expr: T | string): this; /** * The same as 'appendString'. * * @param expr - The expression to append * @returns The current logger instance */ string(expr: T | string): this; /** * Appends an expression that represents a char. * * @param expr - The expression to append * @returns The current logger instance */ appendChar(expr: T | string): this; /** * The same as 'appendChar'. * * @param expr - The expression to append * @returns The current logger instance */ char(expr: T | string): this; /** * Appends an expression that represents a hex number. * * @param expr - The expression to append * @returns The current logger instance */ appendHex(expr: T | string): this; /** * The same as 'appendHex'. * * @param expr - The expression to append * @returns The current logger instance */ hex(expr: T | string): this; /** * Appends an expression that represents an octal. * * @param expr - The expression to append * @returns The current logger instance */ appendOctal(expr: T | string): this; /** * The same as 'appendOctal'. * * @param expr - The expression to append * @returns The current logger instance */ octal(expr: T | string): this; /**** PRIVATE METHODS ****/ protected _append_private(message: T | string, type?: number): this; protected _warn(message: string): void; protected _info(message: string): void; protected _getPrintableContent(element: ElementType): string; /** * Generates printf like code for c and java * * @param printFunctionName - The name of the function to use (printf for C, System.out.println for Java) */ protected _printfFormat(printFunctionName: string, prefix?: string, suffix?: string, delimiter?: string): string; /** * * * @param $function - Function where name will be declared * @param nameGenerator - Function that receives no arguments and generates a new name */ protected _declareName(functionId: string, nameGenerator: () => string): { name: string; alreadyDeclared: boolean; }; } export {}; //# sourceMappingURL=LoggerBase.d.ts.map