UNPKG

typir

Version:

General purpose type checking library

102 lines 6.59 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import { DefaultGraphAlgorithms } from './graph/graph-algorithms.js'; import { TypeGraph } from './graph/type-graph.js'; import { DefaultTypeResolver } from './initialization/type-descriptor.js'; import { BottomKind, BottomKindName } from './kinds/bottom/bottom-kind.js'; import { ClassKind, ClassKindName } from './kinds/class/class-kind.js'; import { FunctionKind, FunctionKindName } from './kinds/function/function-kind.js'; import { PrimitiveKind, PrimitiveKindName } from './kinds/primitive/primitive-kind.js'; import { TopKind, TopKindName } from './kinds/top/top-kind.js'; import { DefaultTypeAssignability } from './services/assignability.js'; import { DefaultLanguageNodeInferenceCaching, DefaultTypeRelationshipCaching } from './services/caching.js'; import { DefaultTypeConversion } from './services/conversion.js'; import { DefaultTypeEquality } from './services/equality.js'; import { DefaultTypeInferenceCollector } from './services/inference.js'; import { DefaultKindRegistry } from './services/kind-registry.js'; import { DefaultLanguageService } from './services/language.js'; import { DefaultOperatorFactory } from './services/operator.js'; import { DefaultTypeConflictPrinter } from './services/printing.js'; import { DefaultSubType } from './services/subtype.js'; import { DefaultValidationCollector, DefaultValidationConstraints } from './services/validation.js'; import { inject } from './utils/dependency-injection.js'; export function createDefaultTypirServicesModule() { return { Assignability: (services) => new DefaultTypeAssignability(services), Equality: (services) => new DefaultTypeEquality(services), Conversion: (services) => new DefaultTypeConversion(services), Subtype: (services) => new DefaultSubType(services), Inference: (services) => new DefaultTypeInferenceCollector(services), caching: { TypeRelationships: (services) => new DefaultTypeRelationshipCaching(services), LanguageNodeInference: () => new DefaultLanguageNodeInferenceCaching(), }, Printer: () => new DefaultTypeConflictPrinter(), Language: () => new DefaultLanguageService(), validation: { Collector: (services) => new DefaultValidationCollector(services), Constraints: (services) => new DefaultValidationConstraints(services), }, factory: { Primitives: (services) => services.infrastructure.Kinds.getOrCreateKind(PrimitiveKindName, services => new PrimitiveKind(services)), Functions: (services) => services.infrastructure.Kinds.getOrCreateKind(FunctionKindName, services => new FunctionKind(services)), Classes: (services) => services.infrastructure.Kinds.getOrCreateKind(ClassKindName, services => new ClassKind(services, { typing: 'Nominal' })), Top: (services) => services.infrastructure.Kinds.getOrCreateKind(TopKindName, services => new TopKind(services)), Bottom: (services) => services.infrastructure.Kinds.getOrCreateKind(BottomKindName, services => new BottomKind(services)), Operators: (services) => new DefaultOperatorFactory(services), }, infrastructure: { Graph: () => new TypeGraph(), GraphAlgorithms: (services) => new DefaultGraphAlgorithms(services), Kinds: (services) => new DefaultKindRegistry(services), TypeResolver: (services) => new DefaultTypeResolver(services), }, }; } /** * Creates the TypirServices with the default module containing the default implements for Typir, * which might be exchanged by the given optional customized modules. * @param customization1 optional Typir module with customizations * @param customization2 optional Typir module with customizations * @param customization3 optional Typir module with customizations * @param customization4 optional Typir module with customizations * @returns a Typir instance, i.e. the TypirServices with implementations for all services */ export function createTypirServices(customization1, customization2, customization3, customization4) { return inject( // use the default implementations for all core Typir services createDefaultTypirServicesModule(), // optionally add some more language-specific customization, e.g. for ... customization1, // ... production customization2, // ... testing (in order to replace some customizations of production) customization3, // ... testing (e.g. to have customizations for all test cases and for single test cases) customization4); } /** * Creates the TypirServices with the default module containing the default implementations for Typir, * which might be exchanged by the given optional customized modules. * Additionally, some new services are defined, and implementations for them are registered. * @param moduleForAdditionalServices contains the configurations for all added services * @param customization1 optional Typir module with customizations (for new and existing services) * @param customization2 optional Typir module with customizations (for new and existing services) * @param customization3 optional Typir module with customizations (for new and existing services) * @param customization4 optional Typir module with customizations (for new and existing services) * @returns a Typir instance, i.e. the TypirServices consisting of the default services and the added services, * with implementations for all services */ export function createTypirServicesWithAdditionalServices(moduleForAdditionalServices, customization1, customization2, customization3, customization4) { return inject( // use the default implementations for all core Typir services createDefaultTypirServicesModule(), // add implementations for all additional services moduleForAdditionalServices, // optionally add some more language-specific customization, e.g. for ... customization1, // ... production customization2, // ... testing (in order to replace some customizations of production) customization3, // ... testing (e.g. to have customizations for all test cases and for single test cases) customization4); } //# sourceMappingURL=typir.js.map