Search in sources :

Example 1 with ExpressionInstanceContext

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;
}
Also used : GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ExpressionInstanceParserPropertyAssignmentContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceParserPropertyAssignmentContext) SimpleFunctionExpressionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpressionInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) Token(org.antlr.v4.runtime.Token) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) InstanceValueInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValueInstance) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) VariableExpressionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionInstance) ImportStubInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance)

Aggregations

Token (org.antlr.v4.runtime.Token)1 ImportStubInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStubInstance)1 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)1 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)1 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)1 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)1 InstanceValueInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValueInstance)1 SimpleFunctionExpressionInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpressionInstance)1 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1 VariableExpressionInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpressionInstance)1 ExpressionInstanceParserPropertyAssignmentContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionInstanceParserPropertyAssignmentContext)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1 AntlrSourceInformation (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation)1