use of org.finos.legend.pure.m3.serialization.runtime.pattern.URLPatternLibrary in project legend-pure by finos.
the class FunctionDefinitionProcessor method process.
public static void process(FunctionDefinition<?> functionDefinition, ProcessorState state, Matcher matcher, ModelRepository repository) {
ProcessorSupport processorSupport = state.getProcessorSupport();
VariableContext variableContext = state.getVariableContext();
FunctionType functionType = (FunctionType) processorSupport.function_getFunctionType(functionDefinition);
state.getObserver().startProcessingFunction(functionDefinition, functionType);
URLPatternLibrary urlPatternLibrary = state.getURLPatternLibrary();
if (urlPatternLibrary != null) {
urlPatternLibrary.possiblyRegister(functionDefinition, processorSupport);
}
boolean shouldSetTypeInferenceContext = (functionDefinition instanceof ConcreteFunctionDefinition) && (functionDefinition._classifierGenericType() != null) && (functionDefinition._classifierGenericType()._rawTypeCoreInstance() != null) && "ConcreteFunctionDefinition".equals(functionDefinition._classifierGenericType()._rawTypeCoreInstance().getName());
if (shouldSetTypeInferenceContext) {
state.newTypeInferenceContext(functionType);
}
functionType._parameters().forEach(var -> {
try {
variableContext.registerValue(var._name(), var);
} catch (VariableNameConflictException e) {
throw new PureCompilationException(functionDefinition.getSourceInformation(), e.getMessage());
}
GenericType propertyType = var._genericType();
// The property type may be null if it's a lambda expression...
if (propertyType != null) {
// We resolve because we want to fail fast if a given type is unknown...
org.finos.legend.pure.m3.navigation.generictype.GenericType.resolveGenericTypeUsingImports(propertyType, repository, processorSupport);
}
});
ListIterable<? extends ValueSpecification> expressions = functionDefinition._expressionSequence().toList();
if (expressions.isEmpty()) {
throw new PureCompilationException(functionDefinition.getSourceInformation(), "Function definition must contain at least one expression");
}
// The function is going to be processed again after inference
if (TypeInference.canProcessLambda(functionDefinition, state, processorSupport)) {
state.getObserver().shiftTab();
state.getObserver().startProcessingFunctionBody();
processExpressions(functionDefinition, expressions, matcher, state, processorSupport);
findReturnTypesForLambda(functionDefinition, functionType, processorSupport);
FunctionDefinitionValidator.validateFunctionReturnType(functionDefinition, functionType, processorSupport);
state.getObserver().finishedProcessingFunctionBody();
state.getObserver().unShiftTab();
state.addFunctionDefinition(functionDefinition);
}
if (shouldSetTypeInferenceContext) {
state.deleteTypeInferenceContext();
}
state.getVariableContext().buildAndRegister("return", functionType._returnType(), functionType._returnMultiplicity(), processorSupport);
RichIterable<? extends Constraint> constraints = functionDefinition._preConstraints();
if (constraints.notEmpty()) {
processConstraints(functionDefinition, constraints.toList(), matcher, state, processorSupport);
}
RichIterable<? extends Constraint> postConstraints = functionDefinition._postConstraints();
if (postConstraints.notEmpty()) {
processConstraints(functionDefinition, postConstraints.toList(), matcher, state, processorSupport);
}
state.getObserver().finishedProcessingFunction(functionType);
}
use of org.finos.legend.pure.m3.serialization.runtime.pattern.URLPatternLibrary in project legend-pure by finos.
the class PostProcessor method process.
public static SourceMutation process(Iterable<? extends CoreInstance> newInstancesConsolidated, ModelRepository modelRepository, ParserLibrary parserLibrary, InlineDSLLibrary inlineDSLLibrary, CodeStorage codeStorage, Context context, ProcessorSupport processorSupport, URLPatternLibrary URLPatternLibrary, Message message) throws PureCompilationException {
CoreInstance concreteFunctionDefinition = processorSupport.package_getByUserPath(M3Paths.ConcreteFunctionDefinition);
CoreInstance nativeFunction = processorSupport.package_getByUserPath(M3Paths.NativeFunction);
MutableSet<CoreInstance> set = Sets.mutable.with(concreteFunctionDefinition, nativeFunction);
validatePackages(newInstancesConsolidated, processorSupport);
renameFunctions(newInstancesConsolidated, modelRepository, set, context, processorSupport);
populateSpecializations(newInstancesConsolidated, processorSupport);
populateTemporalMilestonedProperties(newInstancesConsolidated, modelRepository, context, processorSupport);
MutableList<CoreInstance> allInstancesConsolidated = Lists.mutable.withAll(newInstancesConsolidated);
allInstancesConsolidated.addAllIterable(populatePropertiesFromAssociations(newInstancesConsolidated, modelRepository, context, processorSupport));
// Post Process
Matcher matcher = new Matcher(modelRepository, context, processorSupport);
addMatchersComingFromParsers(parserLibrary, matcher);
inlineDSLLibrary.getInlineDSLs().forEach(dsl -> dsl.getProcessors().forEach(matcher::addMatchIfTypeIsKnown));
ProcessorState state = new ProcessorState(VariableContext.newVariableContext(), parserLibrary, inlineDSLLibrary, processorSupport, URLPatternLibrary, codeStorage, message);
allInstancesConsolidated.forEach(coreInstance -> {
state.resetVariableContext();
processElement(matcher, coreInstance, state, processorSupport);
});
state.getFunctionDefinitions().forEach(functionDef -> GenericTypeTraceability.addTraceForFunctionDefinition((FunctionDefinition<?>) functionDef, modelRepository, processorSupport));
return state.getSourceMutation();
}
Aggregations