import { CompilerNote } from "./errors"; import { UnqualifiedName } from "./lexical"; import { TranslationUnit } from "./Program"; import { CompleteClassType, PotentialParameterType } from "./types"; import { VariableEntity, FunctionEntity, ClassEntity, FunctionOverloadGroup } from "./entities"; interface NormalLookupOptions { readonly kind: "normal"; readonly noParent?: boolean; readonly noBase?: boolean; } interface ExactLookupOptions { readonly kind: "exact"; readonly noParent?: boolean; readonly noBase?: boolean; readonly paramTypes: readonly PotentialParameterType[]; readonly receiverType?: CompleteClassType; } export declare type NameLookupOptions = NormalLookupOptions | ExactLookupOptions; /** * Discriminated union over entities introduced into a scope by a declaration. * Discriminated by .declarationKind property. */ export declare type DeclaredEntity = VariableEntity | FunctionEntity | ClassEntity; /** * Possible results of name lookup. */ export declare type DeclaredScopeEntry = VariableEntity | FunctionOverloadGroup | ClassEntity; export declare class Scope { private readonly entities; private readonly hiddenClassEntities; private readonly typeEntities; readonly translationUnit: TranslationUnit; readonly parent?: Scope; readonly name?: string; readonly children: { [index: string]: NamedScope | undefined; }; constructor(translationUnit: TranslationUnit, parent?: Scope); addChild(child: NamedScope): void; /** Attempts to declare a variable in this scope. * @param newEntity The variable being declared. * @returns Either the entity that was added, or an existing one already there, assuming it was compatible. * If an error prevents the entity being added successfully, returns the error instead. (e.g. A previous * declaration with the same name but a different type.) */ declareVariableEntity(newEntity: EntityT): EntityT | CompilerNote; protected variableEntityCreated(newEntity: VariableEntity): void; /** Attempts to declare a function in this scope. * @param newEntity - The function being declared. * @returns Either the entity that was added, or an existing one already there, assuming it was compatible. * If an error prevents the entity being added successfully, returns the error instead. (e.g. A previous * function declaration with the same signature but a different return type.) */ declareFunctionEntity(newEntity: FunctionEntity): FunctionEntity> | CompilerNote; /** Attempts to declare a class in this scope. TODO docs: this documentation is out of date * @param newEntity - The class being declared. * @returns Either the entity that was added, or an existing one already there, assuming it was compatible. * If an error prevents the entity being added successfully. (e.g. An error due to * multiple definitions of the same class within a single translation unit.) */ declareClassEntity(newEntity: ClassEntity): CompilerNote | ClassEntity; protected classEntityCreated(newEntity: ClassEntity): void; /** * Performs unqualified name lookup of a given name in this scope. Returns the entity found, or undefined * if no entity can be found. Note that the entity found may be a function overload group. Lookup may * may search through parent scopes. The lookup process can be customized by providing a set of `NameLookupOptions` ( * see documentation for the `NameLookupOptions` type for more details.) If the entity found is not a * function overload group, "normal" lookup is the same as "exact lookup" (the contextual parameter types * and receiver type are ignored at that point even if provided.) * @param name An unqualified name to be looked up. * @param options A set of options to customize the lookup process. * @returns */ lookup(name: UnqualifiedName, options?: NameLookupOptions): DeclaredScopeEntry | undefined; availableVars(): VariableEntity[]; } export declare class BlockScope extends Scope { } export declare class NamedScope extends Scope { readonly name: string; constructor(translationUnit: TranslationUnit, name: string, parent?: Scope); } export declare class NamespaceScope extends NamedScope { constructor(translationUnit: TranslationUnit, name: string, parent?: NamespaceScope); protected variableEntityCreated(newEntity: VariableEntity): void; } export declare class ClassScope extends NamedScope { readonly base?: ClassScope; /** * * @param translationUnit * @param name The unqualified name of the class * @param parent * @param base */ constructor(translationUnit: TranslationUnit, name: string, parent?: Scope | ClassScope, base?: ClassScope); createAlternateParentProxy(newParent: Scope): any; protected variableEntityCreated(newEntity: VariableEntity): void; /** * Performs unqualified name lookup of a given name in this class scope. The * behavior and customization options are similar to `lookup()` in the Scope * class, except that the base class scope (if it exists) will be searched * before parent scopes. * @param name An unqualified name to be looked up. * @param options A set of options to customize the lookup process. */ lookup(name: string, options?: NameLookupOptions): DeclaredScopeEntry | undefined; } export {};