Package de.fosd.typechef.featureexpr

Examples of de.fosd.typechef.featureexpr.FeatureExpr


            return FeatureExprLib.True();
        if (bdd.isZero()) return FeatureExprLib.False();

        allsat = (List) bdd.allsat();

        FeatureExpr result = FeatureExprLib.False();

        firstTerm = true;
        for (Object o : allsat) {
            byte[] sat;
            boolean first;

            FeatureExpr innerResult = FeatureExprLib.True();


            sat = (byte[]) o;
            first = true;
            for (int i = 0; i < sat.length; i++)
                if (sat[i] == 0 || sat[i] == 1) {
                    String fname = pc.getPCManager().vars.getName(i);

                    if (fname.length() > 10 && fname.substring(0, 9).equals("(defined ") && fname.substring(fname.length() - 1).equals(")"))
                        fname = fname.substring(9, fname.length() - 1);
                    else
                        fname = formulaToName(fname);
                    FeatureExpr var = FeatureExprLib.l().createDefinedExternal(fname);
                    if (sat[i] == 0) var = var.not();

                    innerResult = innerResult.and(var);
                }

            result = result.or(innerResult);
View Full Code Here


        BufferedReader checkFile = new BufferedReader(new InputStreamReader(
                inputStream));
        String line;
        String cleanedOutput = tokenStreamToString(lexerResult).replace("definedEx(",
                "defined(");
        FeatureExpr errorCondition = LexerFrontend.getErrorCondition(lexerResult);
        while ((line = checkFile.readLine()) != null) {
            //expecting NOT to find a token
            if (line.startsWith("!")) {
                String substring = line.substring(2);
                if (cleanedOutput.contains(substring)) {
                    System.err.println(cleanedOutput);
                    Assert.fail(substring
                            + " found but not expected in output\n"
                            + cleanedOutput);
                }
            }
            //expecting to find a token a specific number of times
            if (line.startsWith("+")) {
                int expected = Integer.parseInt(line.substring(1, 2));
                int found = 0;
                String substring = line.substring(3);

                String content = cleanedOutput;
                int idx = content.indexOf(substring);
                while (idx >= 0) {
                    found++;
                    content = content.substring(idx + substring.length());
                    idx = content.indexOf(substring);
                }

                if (expected != found) {
                    failOutput(cleanedOutput);
                    Assert.fail(substring + " found " + found
                            + " times, but expected " + expected + " times\n"
                            + content);
                }
            }
            //expect to find a token an arbitrary number of times
            if (line.startsWith("*")) {
                String substring = line.substring(2);

                int idx = cleanedOutput.indexOf(substring);
                if (idx < 0) {
                    failOutput(cleanedOutput);
                    Assert.fail(substring + " not found but expected\n"
                            + cleanedOutput);
                }
            }
            //expect to find a token with a specific presence condition
            if (line.startsWith("T")) {
                // checks presence condition for token
                // Syntax: T <tokenText> with <presenceCondition>
                String expectedName = line.substring(2);
                String expectedFeature = expectedName.substring(expectedName
                        .indexOf(" with ") + 6);
                expectedName = expectedName.substring(0, expectedName
                        .indexOf(" with "));
                FeatureExpr expectedExpr = FeatureExprLib.featureExprParser().parse(expectedFeature);
                boolean foundToken = false;

                for (LexerToken t : LexerFrontend.conditionalResultToList(lexerResult, FeatureExprFactory.True())) {
                    if (t.getText().equals(expectedName)) {
                        foundToken = true;
                        // expect equivalent presence conditions
                        Assert.assertTrue("found token " + expectedName
                                + " with " + t.getFeature()
                                + " instead of expected " + expectedExpr,
                                t.getFeature().equivalentTo(expectedExpr));
                    }
                }
                Assert.assertTrue("token " + expectedName + " not found.",
                        foundToken);
            }
            //expects a lexer error (always or under a specific condition)
            if (line.startsWith("error")) {
                //error <- fails under all conditions
                //error CONFIG_FOO | CONFIG_BAR <- fails under specific conditions
                String condition = line.substring(5).trim();
                if (condition.length() == 0)
                    condition = "1";
                FeatureExpr expectedErrorCondition = FeatureExprLib.featureExprParser().parse(condition);

                containsErrorCheck = true;
                Assert.assertTrue(
                        "Expected error IF " + expectedErrorCondition + ", but preprocessing succeeded unless " + errorCondition,
                        errorCondition.equivalentTo(expectedErrorCondition));
View Full Code Here

        if (sawElse())
            assert !localFeatures.isEmpty() : "else before #if?";

        if (localFeatures.isEmpty())
            return FeatureExprLib.True();
        FeatureExpr result = localFeatures.get(localFeatures.size() - 1);
        /*
           * if (sawElse) result = result.not();
           */
        for (int i = 0; i < localFeatures.size() - 1; i++)
            // result = result.and(localFeatures.get(i).not());
            result = result.and(localFeatures.get(i));

        return result;
    }
View Full Code Here

     *
     * @return
     */
    public FeatureExpr getFullPresenceCondition() {
        if (cache_fullPresenceCondition == null) {
            FeatureExpr result = getLocalFeatureExpr();
            if (parent != null)
                result = result.and(parent.getFullPresenceCondition());
            cache_fullPresenceCondition = result;
        }
        return cache_fullPresenceCondition;
    }
View Full Code Here

        // check with cache and parent before using SAT solver
        if (cache_isActive != null)
            return cache_isActive.booleanValue();
        if (parent != null && parent.isCachedInactive())
            return false;
        FeatureExpr condition = getFullPresenceCondition();
        cache_isActive = new Boolean(condition.isSatisfiable(featureModel));
        return cache_isActive.booleanValue();
    }
View Full Code Here

     * If a PreprocessorListener is installed, it receives the warning.
     * Otherwise, an exception is thrown.
     */
    protected void warning(int line, int column, String msg)
            throws LexerException {
        FeatureExpr fexpr =  state.getFullPresenceCondition();
        if (warnings.contains(Warning.ERROR))
            error(line, column, msg);
        else if (listener != null)
            listener
                    .handleWarning(sourceManager.getSource().getName(), line, column, msg, fexpr);
View Full Code Here

        } else {
            // check that every variant is covered, there is no case when this
            // macro
            // is not replaced
            // currentstate => (alt1 || alt2|| alt3)
            FeatureExpr commonCondition = getCommonCondition(macroExpansions);
            try {
                if (macroExpansions.length == 1 && isExaustive(commonCondition)) {
                    sourceManager.push_source(createMacroTokenSource(macroName,
                            args, macroExpansions[0], origInvokeTok, inlineCppExpression), true);
View Full Code Here

            throws IOException, LexerException, ParseParamException {
        boolean alternativesExaustive = isExaustive(commonCondition);

        List<Source> resultList = new ArrayList<Source>();
        for (int i = macroExpansions.length - 1; i >= 0; i--) {
            FeatureExpr feature = macroExpansions[i].getFeature();
            MacroData macroData = macroExpansions[i].getExpansion();

            if (i == macroExpansions.length - 1)
                resultList.add(new UnnumberedUnexpandingTokenStreamSource(
                        prependNL(OutputHelper.if_tokenStr(feature))));
View Full Code Here

            macroConstraints.add(new MacroConstraint(macroName,
                    MacroConstraintKind.NOTEXPANDING, commonCondition.not()));

        List<Source> resultList = new ArrayList<Source>();
        for (int i = macroExpansions.length - 1; i >= 0; i--) {
            FeatureExpr feature = macroExpansions[i].getFeature();
            MacroData macroData = macroExpansions[i].getExpansion();

            if (i > 0 || !alternativesExaustive)
                resultList.add(new UnnumberedUnexpandingTokenStreamSource(
                        OutputHelper.inlineIf_tokenStr(feature)));// "__IF__(feature,"
View Full Code Here

        //of the current presence condition.
        return commonCondition.isTautology(featureModel);
    }

    private FeatureExpr getCommonCondition(MacroExpansion<MacroData>[] macroExpansions) {
        FeatureExpr commonCondition = macroExpansions[0].getFeature();
        for (int i = macroExpansions.length - 1; i >= 1; i--)
            commonCondition = commonCondition.or(macroExpansions[i]
                    .getFeature());
        commonCondition = state.getFullPresenceCondition().implies(commonCondition);
        return commonCondition;
    }
View Full Code Here

TOP

Related Classes of de.fosd.typechef.featureexpr.FeatureExpr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.