import { BoundedArrayType, AtomicType, PointerType, ArrayPointerType, ArrayElemType, Char, Int, CompleteObjectType, CompleteClassType } from "../compilation/types"; import { Observable } from "../../util/observe"; import { Value, RawValueType } from "./Value"; import { Memory } from "./Memory"; import { RuntimeConstruct } from "../constructs/CPPConstruct"; import { ParameterDefinition } from "../constructs/declarations/function/ParameterDefinition"; import { CompiledGlobalVariableDefinition } from "../constructs/declarations/variable/GlobalVariableDefinition"; import { LocalVariableDefinition } from "../constructs/declarations/variable/LocalVariableDefinition"; import { BoundReferenceEntity } from "../compilation/entities"; export interface ObjectDescription { name: string; message: string; } export declare type CPPObjectStorageKind = "automatic" | "dynamic" | "static" | "temporary" | "subobject" | "invalid"; declare type ObjectValueRepresentation = T extends AtomicType ? Value : T extends BoundedArrayType ? ObjectValueRepresentation[] : T extends CompleteClassType ? { [index: string]: ObjectRawValueRepresentation; } : never; declare type ObjectRawValueRepresentation = T extends AtomicType ? RawValueType : T extends BoundedArrayType ? ObjectRawValueRepresentation[] : T extends CompleteClassType ? { [index: string]: ObjectRawValueRepresentation; } : unknown; export declare abstract class CPPObject { private static _nextObjectId; readonly observable: Observable; /** * Objects that result from a named declaration will have a name. For others * (e.g. dynamically allocated objects, temporary objects), this will be undefined. */ readonly name?: string; readonly type: T; readonly size: number; readonly address: number; readonly objectId: number; abstract readonly storageKind: CPPObjectStorageKind; private readonly data; readonly isAlive: boolean; readonly deallocatedBy?: RuntimeConstruct; private _isValid; private readonly auxiliaryData; constructor(type: T, memory: Memory, address: number); getArrayElemSubobject(this: CPPObject, index: number): ArraySubobject; getArrayElemSubobjects(this: CPPObject): readonly ArraySubobject[]; numArrayElemSubobjects(this: CPPObject): number; getArrayElemSubobjectByAddress(this: CPPObject, address: number): ArraySubobject; /** * Only allowed if receiver matches CPPObject * Note that this returns CPPObject rather than MemberSubobject because * a reference member may refer to an external object that is not a subobject * @param this * @param name */ getMemberObject(this: CPPObject, name: string): CPPObject | undefined; bindMemberReference(this: CPPObject, name: string, obj: CPPObject): void; getBaseSubobject(this: CPPObject): BaseSubobject | undefined; subobjectValueWritten(): void; toString(): string; beginLifetime(): void; kill(rt?: RuntimeConstruct): void; getPointerTo(): Value>; decayToPointer(this: CPPObject): Value>; isBaseSubobject(): this is BaseSubobject; getValue(read?: boolean): ObjectValueRepresentation; rawValue(): ObjectRawValueRepresentation; readValue(): ObjectValueRepresentation; setValue(this: CPPObject, newValue: Value, write?: boolean): void; _onValueSet(write: boolean): void; writeValue(this: CPPObject, newValue: Value): void; /** * Begins this object's lifetime and initializes its value. * May only be called on objects of atomic type. * @param this * @param newValue */ initializeValue(this: CPPObject, newValue: Value): void; zeroInitialize(): void; isValueValid(this: CPPObject): boolean; callReceived(): void; callEnded(): void; setValidity(valid: boolean): void; abstract isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is CPPObject; hasStorage(storageKind: "dynamic"): this is DynamicObject; hasStorage(storageKind: "automatic"): this is AutoObject; hasStorage(storageKind: "subobject"): this is Subobject; hasStorage(storageKind: "temporary"): this is TemporaryObject; hasStorage(storageKind: "invalid"): this is InvalidObject; /** * Notify this object that a reference has been bound to it */ onReferenceBound(entity: BoundReferenceEntity): void; /** * Notify this object that a reference has been unbound from it * (e.g. that reference went out of scope) */ onReferenceUnbound(entity: BoundReferenceEntity): void; abstract describe(): ObjectDescription; setAuxiliaryData(key: string, data: any): void; getAuxiliaryData(key: string): any; } export declare class AutoObject extends CPPObject { readonly storageKind = "automatic"; readonly name: string; readonly def: LocalVariableDefinition | ParameterDefinition; constructor(def: LocalVariableDefinition | ParameterDefinition, type: T, memory: Memory, address: number); describe(): ObjectDescription; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is AutoObject; } export declare class MainReturnObject extends CPPObject { readonly storageKind = "static"; constructor(memory: Memory); isTyped(predicate: (t: Int) => t is NarrowedT): this is MainReturnObject; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is never; describe(): ObjectDescription; } export declare class StaticObject extends CPPObject { readonly def: CompiledGlobalVariableDefinition; readonly storageKind = "static"; readonly name: string; constructor(def: CompiledGlobalVariableDefinition, type: T, memory: Memory, address: number); isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is StaticObject; describe(): ObjectDescription; } export declare class DynamicObject extends CPPObject { readonly storageKind = "dynamic"; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is DynamicObject; describe(): ObjectDescription; } export declare class InvalidObject extends CPPObject { readonly storageKind = "invalid"; constructor(type: T, memory: Memory, address: number); isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is InvalidObject; describe(): ObjectDescription; } export declare class StringLiteralObject extends CPPObject> { readonly storageKind = "static"; constructor(type: BoundedArrayType, memory: Memory, address: number); isTyped>(predicate: (t: BoundedArrayType) => t is NarrowedT): this is StringLiteralObject; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is never; describe(): ObjectDescription; } declare abstract class Subobject extends CPPObject { readonly storageKind = "subobject"; readonly containingObject: CPPObject; constructor(containingObject: CPPObject, type: T, memory: Memory, address: number); _onValueSet(write: boolean): void; } export declare class ArraySubobject extends Subobject { readonly containingObject: CPPObject>; readonly index: number; constructor(arrObj: CPPObject>, index: number, memory: Memory, address: number); getPointerTo(): Value>; isTyped(predicate: (t: ArrayElemType) => t is NarrowedT): this is ArraySubobject; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is never; describe(): { name: string; message: string; }; } export declare class BaseSubobject extends Subobject { readonly containingObject: CPPObject; constructor(containingObject: CPPObject, type: CompleteClassType, memory: Memory, address: number); isTyped(predicate: (t: CompleteClassType) => t is NarrowedT): this is BaseSubobject; isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is never; isBaseSubobject(): this is BaseSubobject; describe(): ObjectDescription; } export declare class MemberSubobject extends Subobject { readonly containingObject: CPPObject; readonly name: string; constructor(containingObject: CPPObject, type: T, name: string, memory: Memory, address: number); isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is MemberSubobject; describe(): { name: string; message: string; }; } export declare class TemporaryObject extends CPPObject { readonly storageKind = "temporary"; private description; constructor(type: T, memory: Memory, address: number, description: string); isTyped(predicate: (t: CompleteObjectType) => t is NarrowedT): this is TemporaryObject; describe(): ObjectDescription; } export {};