Search in sources :

Example 66 with Expression

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

the class TaintedValueAnalyser method isUntaintedAssignee.

boolean isUntaintedAssignee(Symbol symbol, ControlFlowElement cfe) {
    if (cfe instanceof AssignmentExpression) {
        AssignmentExpression ae = (AssignmentExpression) cfe;
        Expression lhs = ae.getLhs();
        if (symbol.is(lhs)) {
            return assignedSymbolIsAnnotatedWith(symbol, "Untainted");
        }
    }
    return false;
}
Also used : AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression)

Example 67 with Expression

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

the class PrettyPrinterSwitch method caseArrowFunction.

@Override
public Boolean caseArrowFunction(ArrowFunction original) {
    if (original.isAsync()) {
        write("async");
    }
    write('(');
    process(original.getFpars(), ", ");
    write(')');
    processReturnTypeRef(original.getReturnTypeRef());
    write("=>");
    if (original.isHasBracesAroundBody()) {
        process(original.getBody());
    } else {
        if (!original.isSingleExprImplicitReturn()) {
            throw new IllegalStateException("arrow function without braces must be a valid single-expression arrow function");
        }
        final Expression singleExpr = original.getSingleExpression();
        process(singleExpr);
    }
    return DONE;
}
Also used : BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression)

Example 68 with Expression

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

the class AccessModifierXpectMethod method calculateActual.

private String calculateActual(EObject context) {
    String actual = null;
    if (context instanceof TMember) {
        TMember tMember = (TMember) context;
        actual = tMember.getMemberAccessModifier().getName();
    } else {
        FunctionDeclaration functionDeclaration = EcoreUtil2.getContainerOfType(context, FunctionDeclaration.class);
        if (functionDeclaration != null) {
            actual = functionDeclaration.getDefinedType().getTypeAccessModifier().getName();
        } else {
            VariableStatement variableStatement = EcoreUtil2.getContainerOfType(context, VariableStatement.class);
            if (variableStatement != null) {
                context = variableStatement.getVarDecl().get(0);
                if (context instanceof ExportedVariableDeclaration) {
                    actual = ((ExportedVariableDeclaration) context).getDefinedVariable().getTypeAccessModifier().getName();
                } else if (context instanceof VariableDeclaration) {
                    actual = "private";
                }
            } else if (context instanceof ExportDeclaration) {
                context = ((ExportDeclaration) context).getExportedElement();
                actual = calculateActual(context);
            } else if (context instanceof ParameterizedPropertyAccessExpression) {
                ParameterizedPropertyAccessExpression ppae = (ParameterizedPropertyAccessExpression) context;
                IdentifiableElement ie = ppae.getProperty();
                actual = calculateActual(ie);
            } else if (context instanceof ParameterizedCallExpression) {
                ParameterizedCallExpression pce = (ParameterizedCallExpression) context;
                Expression targetExpr = pce.getTarget();
                actual = calculateActual(targetExpr);
            } else {
                N4MemberDeclaration member = EcoreUtil2.getContainerOfType(context, N4MemberDeclaration.class);
                N4TypeDeclaration type = EcoreUtil2.getContainerOfType(context, N4TypeDeclaration.class);
                if (type == null && member == null) {
                    actual = "no element with access modifier found";
                } else if (type != null && (member == null || EcoreUtil.isAncestor(member, type))) {
                    actual = type.getDefinedType().getTypeAccessModifier().getName();
                } else {
                    actual = member.getDefinedTypeElement().getMemberAccessModifier().getName();
                }
            }
        }
    }
    return actual;
}
Also used : ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) FunctionDeclaration(org.eclipse.n4js.n4JS.FunctionDeclaration) VariableStatement(org.eclipse.n4js.n4JS.VariableStatement) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) N4TypeDeclaration(org.eclipse.n4js.n4JS.N4TypeDeclaration) TMember(org.eclipse.n4js.ts.types.TMember)

Example 69 with Expression

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

the class TypeXpectMethod method getTypeString.

private String getTypeString(IEObjectCoveringRegion offset, boolean expectedType) {
    final String calculatedString;
    EObject eobject = offset.getEObject();
    if (eobject instanceof LiteralOrComputedPropertyName) {
        eobject = eobject.eContainer();
    }
    RuleEnvironment G = newRuleEnvironment(eobject);
    Result<org.eclipse.n4js.ts.typeRefs.TypeRef> result;
    if (expectedType) {
        if (!(eobject instanceof Expression && eobject.eContainer() != null))
            return "Not an Expression at given region (required to obtain expected type); got instead: " + eobject.eClass().getName();
        result = ts.expectedTypeIn(G, eobject.eContainer(), (Expression) eobject);
    } else {
        if (eobject instanceof BindingProperty) {
            /*-
				 * Small tweak to allow testing the inferred type of variable declarations within binding patterns. For
				 * example, without this tweak, the following test would fail with a "Not a TypableElement at given
				 * region" exception:
				 *
				 * // Xpect type of 'len' --> number
				 * var {length:len} = "hello";
				 */
            if (((BindingProperty) eobject).getValue() != null && ((BindingProperty) eobject).getValue().getVarDecl() != null) {
                eobject = ((BindingProperty) eobject).getValue().getVarDecl();
            }
        }
        if (!(eobject instanceof TypableElement))
            return "Not a TypableElement at given region; got instead: " + eobject.eClass().getName();
        result = ts.type(G, (TypableElement) eobject);
    }
    if (result.getRuleFailedException() != null) {
        calculatedString = result.getRuleFailedException().getMessage();
    } else {
        calculatedString = result.getValue().getTypeRefAsString();
    }
    return calculatedString;
}
Also used : Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) TypableElement(org.eclipse.n4js.ts.types.TypableElement) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) RuleEnvironmentExtensions.newRuleEnvironment(org.eclipse.n4js.typesystem.RuleEnvironmentExtensions.newRuleEnvironment) BindingProperty(org.eclipse.n4js.n4JS.BindingProperty)

Example 70 with Expression

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

the class AssignmentRelationFactory method findInVariableDeclaration.

private void findInVariableDeclaration(Multimap<Symbol, Object> assgns, VariableDeclaration vd) {
    EObject parent = vd.eContainer();
    if (parent instanceof ForStatement) {
        ForStatement fs = (ForStatement) parent;
        if (!fs.isForPlain()) {
            findInForStatementInOf(assgns, vd, (ForStatement) parent);
            return;
        }
    }
    Expression rhs = vd.getExpression();
    if (rhs == null) {
        Symbol undefinedSymbol = symbolFactory.getUndefined();
        createRelation(assgns, vd, undefinedSymbol, null);
    } else {
        handleSubexpressions(assgns, vd, rhs);
    }
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) EObject(org.eclipse.emf.ecore.EObject) ForStatement(org.eclipse.n4js.n4JS.ForStatement)

Aggregations

Expression (org.eclipse.n4js.n4JS.Expression)111 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)58 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)40 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)38 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)37 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)35 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)33 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)31 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)31 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)31 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)31 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)27 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)27 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)27 MultiplicativeExpression (org.eclipse.n4js.n4JS.MultiplicativeExpression)27 ShiftExpression (org.eclipse.n4js.n4JS.ShiftExpression)27 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)26 CastExpression (org.eclipse.n4js.n4JS.CastExpression)26 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)26 NewExpression (org.eclipse.n4js.n4JS.NewExpression)26