Search in sources :

Example 46 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleUpperBoundParameterizedTypeRef.

protected Result<TypeRef> applyRuleUpperBoundParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef ptr) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    Type _declaredType = ptr.getDeclaredType();
    if ((_declaredType instanceof TypeVariable)) {
        T = ptr;
    } else {
        T = ptr;
    }
    return new Result<TypeRef>(T);
}
Also used : 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) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) 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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 47 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleSubstTypeVariablesInFunctionTypeExprOrRef.

protected Result<TypeArgument> applyRuleSubstTypeVariablesInFunctionTypeExprOrRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final FunctionTypeExprOrRef typeRef) throws RuleFailedException {
    // output parameter
    TypeRef result = null;
    result = this.typeSystemHelper.createSubstitutionOfFunctionTypeExprOrRef(G, typeRef);
    return new Result<TypeArgument>(result);
}
Also used : 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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 48 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeSetterDeclaration.

protected Result<TypeRef> applyRuleTypeSetterDeclaration(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SetterDeclaration setter) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = setter.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = setter.getDeclaredTypeRef();
    }
    if ((T == null)) {
        T = RuleEnvironmentExtensions.anyTypeRef(G);
    }
    return new Result<TypeRef>(T);
}
Also used : 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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 49 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class N4JSStatementValidator method checkForInLoop.

/**
 * 9.1.4 Iteration Statements, Constraints 118 (For-In-Statement Constraints) Variable declaration must be a string
 */
@Check
public void checkForInLoop(ForStatement forStatement) {
    if (forStatement.isForIn()) {
        TypeRef loopVarType = null;
        EObject location = null;
        RuleEnvironment G = (RuleEnvironment) getContext().get(RuleEnvironment.class);
        if (G == null)
            // wrongly configured test
            return;
        if (!forStatement.getVarDeclsOrBindings().isEmpty()) {
            VariableDeclarationOrBinding varDeclOrBinding = forStatement.getVarDeclsOrBindings().iterator().next();
            location = varDeclOrBinding;
            if (varDeclOrBinding instanceof VariableDeclaration) {
                loopVarType = ((VariableDeclaration) varDeclOrBinding).getDeclaredTypeRef();
            } else {
                VariableBinding varBinding = (VariableBinding) varDeclOrBinding;
                Result<TypeRef> res = typeSystem.type(G, varBinding.getExpression());
                if (!res.failed()) {
                    loopVarType = res.getFirst();
                }
            }
        } else if (forStatement.getInitExpr() != null) {
            location = forStatement.getInitExpr();
            Result<TypeRef> res = typeSystem.type(G, forStatement.getInitExpr());
            if (!res.failed()) {
                loopVarType = res.getFirst();
            }
        }
        if (loopVarType != null) {
            Result<Boolean> res = typeSystem.subtype(G, RuleEnvironmentExtensions.stringTypeRef(G), loopVarType);
            if (res.failed() || !res.getFirst()) {
                addIssue(getMessageForTYS_FOR_IN_VAR_STRING(loopVarType.getTypeRefAsString()), location, TYS_FOR_IN_VAR_STRING);
            }
        }
    }
}
Also used : TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) VariableDeclarationOrBinding(org.eclipse.n4js.n4JS.VariableDeclarationOrBinding) VariableBinding(org.eclipse.n4js.n4JS.VariableBinding) Result(org.eclipse.xsemantics.runtime.Result) Check(org.eclipse.xtext.validation.Check)

Example 50 with Result

use of org.eclipse.xsemantics.runtime.Result in project n4js by eclipse.

the class InternalTypeSystem method applyRuleExpectedTypeOfRightSideInPropertyNameValuePair.

protected Result<TypeRef> applyRuleExpectedTypeOfRightSideInPropertyNameValuePair(final RuleEnvironment G, final RuleApplicationTrace _trace_, final PropertyNameValuePair pnvp, final Expression rhs) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = pnvp.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = pnvp.getDeclaredTypeRef();
    } else {
        T = RuleEnvironmentExtensions.topTypeRef(G);
    }
    return new Result<TypeRef>(T);
}
Also used : 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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Aggregations

Result (org.eclipse.xsemantics.runtime.Result)93 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)92 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)91 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)90 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)90 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)89 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)89 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)89 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)89 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)89 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)89 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)89 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)89 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)89 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)25 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)24 NewExpression (org.eclipse.n4js.n4JS.NewExpression)24 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)24 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)23 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)23