use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.
the class InstanceValueUnbind method run.
@Override
public void run(InstanceValue instanceValue, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (CoreInstance value : instanceValue._valuesCoreInstance()) {
if (!(value instanceof Property)) {
((UnbindState) state).freeProcessedAndValidated(value);
}
Shared.cleanUpReferenceUsage(value, instanceValue, processorSupport);
// TODO replace call to Instance.instanceOf once we resolve issue with Path not being available in this module - circular dependency
if (value instanceof LambdaFunction || value instanceof SimpleFunctionExpression || Instance.instanceOf(value, M3Paths.Path, processorSupport) || value instanceof RootRouteNode) {
matcher.fullMatch(value, state);
} else if (Instance.instanceOf(value, M3Paths.RootGraphFetchTree, processorSupport)) {
matcher.fullMatch(value, state);
} else if (value instanceof KeyExpression) {
((UnbindState) state).freeProcessedAndValidated(modelRepository.newBooleanCoreInstance(((KeyExpression) value)._add()));
((UnbindState) state).freeProcessedAndValidated(((KeyExpression) value)._key());
matcher.fullMatch(((KeyExpression) value)._expression(), state);
} else {
Shared.cleanImportStub(value, processorSupport);
}
if (value instanceof ValueSpecification) {
matcher.fullMatch(value, state);
((ValueSpecification) value)._usageContextRemove();
}
}
}
use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.
the class Shared method cleanUpFunctionType.
private static void cleanUpFunctionType(FunctionType functionType, UnbindState state, ProcessorSupport processorSupport) {
GenericType returnType = functionType._returnType();
if (returnType != null) {
returnType._referenceUsagesRemove();
cleanUpGenericType(returnType, state, processorSupport);
}
for (VariableExpression variableExpression : functionType._parameters()) {
GenericType varGenericType = variableExpression._genericType();
if (varGenericType != null) {
cleanUpGenericType(varGenericType, state, processorSupport);
if (varGenericType instanceof InferredGenericType) {
variableExpression._genericTypeRemove();
variableExpression._multiplicityRemove();
}
}
}
}
use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.
the class Shared method cleanUpGenericType.
public static void cleanUpGenericType(GenericType genericType, UnbindState state, ProcessorSupport processorSupport) {
state.freeValidated(genericType);
genericType._referenceUsagesRemove();
CoreInstance rawType = genericType._rawTypeCoreInstance();
if (rawType != null) {
cleanUpReferenceUsage(rawType, genericType, processorSupport);
if (rawType instanceof FunctionType) {
cleanUpFunctionType((FunctionType) rawType, state, processorSupport);
} else {
cleanImportStub(rawType, processorSupport);
}
}
for (GenericType typeArgument : genericType._typeArguments()) {
cleanUpGenericType(typeArgument, state, processorSupport);
}
}
use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.
the class SimpleFunctionExpressionUnbind method cleanAutoMapPropertyIfNecessary.
private static void cleanAutoMapPropertyIfNecessary(FunctionExpression functionExpression, MatcherState state, Matcher matcher) {
ValueSpecification possiblePropertySfe = (ValueSpecification) Automap.getAutoMapExpressionSequence(functionExpression);
if (possiblePropertySfe != null) {
functionExpression._functionNameRemove();
ListIterable<? extends ValueSpecification> params = functionExpression._parametersValues().toList();
ValueSpecification firstParam = params.get(0);
ValueSpecification secondParam = params.get(1);
matcher.fullMatch(secondParam, state);
RichIterable<? extends ValueSpecification> possiblePropertySfeParams = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._parametersValues() : // params may have changed after unbinding for the Lambda
Lists.fixedSize.empty();
((UnbindState) state).freeProcessedAndValidated(secondParam);
GenericType secondParamGenericType = secondParam._genericType();
if (secondParamGenericType != null) {
((UnbindState) state).freeValidated(secondParamGenericType);
}
functionExpression._parametersValuesRemove();
MutableList<ValueSpecification> allVars = Lists.mutable.with(firstParam);
// add back qualified properties params
allVars.addAllIterable(possiblePropertySfeParams.toList().subList(1, possiblePropertySfeParams.size()));
functionExpression._parametersValues(allVars);
InstanceValue propertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._propertyName() : null;
if (propertyName == null) {
InstanceValue qualifiedPropertyName = possiblePropertySfe instanceof FunctionExpression ? ((FunctionExpression) possiblePropertySfe)._qualifiedPropertyName() : null;
functionExpression._qualifiedPropertyName(qualifiedPropertyName);
} else {
functionExpression._propertyName(propertyName);
}
}
}
use of org.finos.legend.pure.m3.compiler.unload.unbind.UnbindState in project legend-pure by finos.
the class TypeUnbind method run.
@Override
public void run(Type type, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
for (Generalization generalization : type._generalizations()) {
GenericType general = generalization._general();
Type generalRawType = null;
try {
generalRawType = (Type) ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
} catch (PureCompilationException ex) {
// Ignore - if we can't resolve this type was probably already unbound
}
if (generalRawType != null) {
ListIterable<? extends CoreInstance> specializationsToRemove = generalRawType.getValueInValueForMetaPropertyToManyByIndex(M3Properties.specializations, IndexSpecifications.getPropertyValueIndexSpec(M3Properties.specific), type);
for (CoreInstance specialization : specializationsToRemove.toList()) {
generalRawType._specializationsRemove((Generalization) specialization);
}
if (generalRawType.getValueForMetaPropertyToMany(M3Properties.specializations).isEmpty()) {
generalRawType._specializationsRemove();
}
}
Shared.cleanUpGenericType(general, (UnbindState) state, processorSupport);
}
}
Aggregations