use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceContext in project legend-pure by finos.
the class AntlrContextToM3CoreInstance method expressionInstanceParser.
private SimpleFunctionExpression expressionInstanceParser(ExpressionInstanceContext ctx, MutableList<String> typeParametersNames, LambdaContext lambdaContext, ImportGroup importId, boolean addLines, String space) {
ListIterable<GenericType> renderedTypeArguments = null;
ListIterable<Multiplicity> renderedMultiplicityArguments = null;
MutableList<CoreInstance> keyExpressions = Lists.mutable.empty();
Token end = ctx.getStop();
if (ctx.expressionInstanceParserPropertyAssignment() != null) {
for (ExpressionInstanceParserPropertyAssignmentContext propCtx : ctx.expressionInstanceParserPropertyAssignment()) {
keyExpressions.add(this.expressionInstanceParserPropertyAssignment(propCtx, typeParametersNames, importId, addLines, spacePlusTabs(space, 8), lambdaContext));
}
}
if (ctx.typeArguments() != null) {
renderedTypeArguments = this.typeArguments(ctx.typeArguments(), typeParametersNames, importId, addLines);
}
if (ctx.multiplicityArguments() != null) {
renderedMultiplicityArguments = this.multiplicityArguments(ctx.multiplicityArguments());
}
SourceInformation sourceInfo = this.sourceInformation.getPureSourceInformation(ctx.NEW_SYMBOL().getSymbol(), ctx.identifier() == null ? ctx.NEW_SYMBOL().getSymbol() : ctx.identifier().getStart(), end);
SimpleFunctionExpressionInstance sfei = SimpleFunctionExpressionInstance.createPersistent(this.repository, sourceInfo, null, null, importId, null);
sfei._functionName(ctx.variable() == null ? "new" : "copy");
MutableList<ValueSpecification> paramValues = Lists.mutable.of();
if (ctx.variable() == null) {
GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.NEW_SYMBOL().getSymbol()));
Type type = (Type) this.processorSupport.package_getByUserPath(M3Paths.Class);
genericTypeInstance._rawTypeCoreInstance(type);
GenericTypeInstance ta = GenericTypeInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.qualifiedName().getStart(), ctx.qualifiedName().getStop(), ctx.qualifiedName().getStop()));
ImportStubInstance is = ImportStubInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.qualifiedName().getStart(), ctx.qualifiedName().getStop(), ctx.qualifiedName().getStop()), this.getQualifiedNameString(ctx.qualifiedName()), importId);
ta._rawTypeCoreInstance(is);
if (renderedTypeArguments != null) {
ta._typeArguments(renderedTypeArguments);
}
if (renderedMultiplicityArguments != null) {
ta._multiplicityArguments(renderedMultiplicityArguments);
}
genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(ta));
InstanceValueInstance iv = InstanceValueInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.qualifiedName().identifier().getStart()), genericTypeInstance, this.getPureOne());
// todo: shouldn't be necessary
iv._values(Lists.fixedSize.<CoreInstance>empty());
paramValues.add(iv);
} else {
VariableExpressionInstance vei = VariableExpressionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(ctx.variable().getStart()), null, null, ctx.variable().identifier().getText());
paramValues.add(vei);
}
InstanceValue nameCi = ctx.identifier() == null ? this.doWrap(Lists.mutable.of(this.repository.newStringCoreInstance_cached(""))) : this.doWrap(ctx.identifier(), false);
paramValues.add(nameCi);
if (!keyExpressions.isEmpty()) {
InstanceValue keyExpr = this.doWrap(keyExpressions);
paramValues.add(keyExpr);
}
sfei._parametersValues(paramValues);
return sfei;
}
Aggregations