Search in sources :

Example 1 with ParameterizedCallExpression

use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeIdentifierRef.

protected Result<TypeRef> applyRuleTypeIdentifierRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final IdentifierRef idref) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* G |- idref.id : T */
    IdentifiableElement _id = idref.getId();
    Result<TypeRef> result = typeInternal(G, _trace_, _id);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    T = (TypeRef) result.getFirst();
    T = this.versionResolver.<TypeRef, IdentifierRef>resolveVersion(T, idref);
    if (((idref.eContainer() instanceof ParameterizedCallExpression) && (idref.eContainmentFeature() == N4JSPackage.eINSTANCE.getParameterizedCallExpression_Target()))) {
        final TMethod callableCtorFunction = this.typeSystemHelper.getCallableClassConstructorFunction(G, T);
        if ((callableCtorFunction != null)) {
            T = TypeExtensions.ref(callableCtorFunction);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 2 with ParameterizedCallExpression

use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeSuperLiteral.

protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
    /* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
    {
        RuleFailedException previousFailure = null;
        try {
            if ((containingMemberDecl == null)) {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            } else {
                EObject _eContainer = containingMemberDecl.eContainer();
                Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
                final TClass containingClass = ((TClass) _definedType);
                final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
                TClassifier effectiveSuperClass = superClass;
                boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
                if (_isStaticPolyfill) {
                    effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
                }
                /* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                {
                    try {
                        /* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
                        if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
                            sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
                        }
                        boolean _isStatic = containingMemberDecl.isStatic();
                        if (_isStatic) {
                            TypeRef _createConstructorTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
                            }
                            T = _createConstructorTypeRef;
                        } else {
                            ParameterizedTypeRef _createTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
                            }
                            T = _createTypeRef;
                        }
                        if ((T != null)) {
                            T = TypeUtils.enforceNominalTyping(T);
                        }
                    } catch (Exception e) {
                        previousFailure = extractRuleFailedException(e);
                        /* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                        {
                            try {
                                EObject _eContainer_1 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof ParameterizedCallExpression */
                                if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
                                }
                                if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
                                    final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
                                    ParameterizedTypeRef _createTypeRef_1 = null;
                                    if (ctor != null) {
                                        _createTypeRef_1 = TypeUtils.createTypeRef(ctor);
                                    }
                                    T = _createTypeRef_1;
                                } else {
                                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                                }
                            } catch (Exception e_1) {
                                previousFailure = extractRuleFailedException(e_1);
                                EObject _eContainer_2 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof NewExpression */
                                if (!(_eContainer_2 instanceof NewExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e_2) {
            previousFailure = extractRuleFailedException(e_2);
            T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) TMethod(org.eclipse.n4js.ts.types.TMethod) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) NewExpression(org.eclipse.n4js.n4JS.NewExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) TClass(org.eclipse.n4js.ts.types.TClass)

Example 3 with ParameterizedCallExpression

use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.

the class MethodDeclarationImpl method existsExplicitSuperCall.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean existsExplicitSuperCall() {
    final Function1<ExpressionStatement, Expression> _function = new Function1<ExpressionStatement, Expression>() {

        public Expression apply(final ExpressionStatement it) {
            return it.getExpression();
        }
    };
    final Function1<ParameterizedCallExpression, Boolean> _function_1 = new Function1<ParameterizedCallExpression, Boolean>() {

        public Boolean apply(final ParameterizedCallExpression it) {
            Expression _target = it.getTarget();
            return Boolean.valueOf((_target instanceof SuperLiteral));
        }
    };
    final boolean existsSuperCall = IteratorExtensions.<ParameterizedCallExpression>exists(Iterators.<ParameterizedCallExpression>filter(IteratorExtensions.<ExpressionStatement, Expression>map(Iterators.<ExpressionStatement>filter(EcoreUtilN4.<Statement>getAllDirectlyFoundContentsOfType(this.getBody(), Statement.class), ExpressionStatement.class), _function), ParameterizedCallExpression.class), _function_1);
    return existsSuperCall;
}
Also used : Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) Statement(org.eclipse.n4js.n4JS.Statement) ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral)

Example 4 with ParameterizedCallExpression

use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.

the class TypeStatesAnalyser method getDeclaredStates.

private Set<String> getDeclaredStates(ControlFlowElement container, String stateName) {
    Set<String> states = new HashSet<>();
    if (container instanceof ParameterizedCallExpression) {
        ParameterizedCallExpression pce = (ParameterizedCallExpression) container;
        TFunction tFunc = (TFunction) ts.tau(pce);
        for (TAnnotation ann : tFunc.getAnnotations()) {
            if (stateName.equals(ann.getName())) {
                for (TAnnotationArgument arg : ann.getArgs()) {
                    states.add(arg.getArgAsString());
                }
            }
        }
    }
    return states;
}
Also used : TFunction(org.eclipse.n4js.ts.types.TFunction) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) TAnnotationArgument(org.eclipse.n4js.ts.types.TAnnotationArgument) HashSet(java.util.HashSet) TAnnotation(org.eclipse.n4js.ts.types.TAnnotation)

Example 5 with ParameterizedCallExpression

use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.

the class N4IDLModuleWrappingTransformation method createVersionedExportExpression.

/**
 * Creates an export expression that exports an versioned element under its versioned internal name.
 *
 * @param element
 *            The versioned internal name
 * @param expression
 *            The expression to export.
 */
private ParameterizedCallExpression createVersionedExportExpression(IdentifiableElement element, Expression expression) {
    if (!VersionUtils.isTVersionable(element)) {
        throw new IllegalArgumentException("Cannot export non-versionable element " + element + " as versionable.");
    }
    final ParameterizedCallExpression callExpression = TranspilerBuilderBlocks._CallExpr();
    callExpression.setTarget(TranspilerBuilderBlocks._IdentRef(steFor_$n4Export()));
    final EList<Argument> arguments = callExpression.getArguments();
    arguments.add(TranspilerBuilderBlocks._Argument(TranspilerBuilderBlocks._StringLiteral(N4IDLTranspilerUtils.getVersionedInternalName(element))));
    arguments.add(TranspilerBuilderBlocks._Argument(expression));
    return callExpression;
}
Also used : Argument(org.eclipse.n4js.n4JS.Argument) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression)

Aggregations

ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)13 Expression (org.eclipse.n4js.n4JS.Expression)6 SuperLiteral (org.eclipse.n4js.n4JS.SuperLiteral)6 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)5 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)5 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)5 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)5 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)4 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)4 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)4 NewExpression (org.eclipse.n4js.n4JS.NewExpression)4 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)4 EObject (org.eclipse.emf.ecore.EObject)3 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)3 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)3 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)3 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)3 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)3 CastExpression (org.eclipse.n4js.n4JS.CastExpression)3 CommaExpression (org.eclipse.n4js.n4JS.CommaExpression)3