@finos/legend-graph
Version:
Legend graph and graph manager
82 lines • 2.83 kB
JavaScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { InstanceValue } from './InstanceValue.js';
import { Multiplicity } from '../packageableElements/domain/Multiplicity.js';
import { hashArray } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../Core_HashUtils.js';
export class FunctionType {
/**
* Currently, we don't do type-inferencing
*
* @discrepancy model
*/
returnType;
parameters = [];
returnMultiplicity;
constructor(returnType, returnMultiplicity) {
this.returnType = returnType;
this.returnMultiplicity = returnMultiplicity;
}
get hashCode() {
return hashArray([
CORE_HASH_STRUCTURE.FUNCTION_TYPE,
this.returnType?.valueForSerialization ?? '',
hashArray(this.parameters),
this.returnMultiplicity,
]);
}
}
export class LambdaFunction {
functionType;
/**
* Engine saves `openVariables` as strings. We save them as a map of var name to the VariableExpression
* This is so we don't needless recreate VariableExpressions again and can leverage the same VariableExpression as
* the ones used in LambdaFunction expressions. This is especially useful when handling `let` statements.
*
* @discrepancy model
*/
openVariables = new Map();
expressionSequence = [];
constructor(type) {
this.functionType = type;
}
get hashCode() {
return hashArray([
CORE_HASH_STRUCTURE.LAMBDA_FUNCTION,
this.functionType,
hashArray(Array.from(this.openVariables.keys())),
hashArray(this.expressionSequence),
]);
}
}
export class LambdaFunctionInstanceValue extends InstanceValue {
values = [];
constructor() {
super(Multiplicity.ONE);
}
get hashCode() {
return hashArray([
CORE_HASH_STRUCTURE.LAMBDA_FUNCTION_INSTANCE_VALUE,
this.genericType?.ownerReference.valueForSerialization ?? '',
this.multiplicity,
hashArray(this.values),
]);
}
accept_ValueSpecificationVisitor(visitor) {
return visitor.visit_LambdaFunctionInstanceValue(this);
}
}
//# sourceMappingURL=LambdaFunction.js.map