@Test public void testSimple() throws Exception { GlobalBuildEnvironmentExpression globals = new GlobalBuildEnvironmentExpression(); CxxLanguageStandardRewritingVisitor rewriter = new CxxLanguageStandardRewritingVisitor(); rewriter.visit(globals); ModuleArchiveExpression archive = makeArchive(CxxLanguageFeatures.cxx_alignof); ModuleExpression module = new ModuleExpression(archive, new HashSet<Coordinate>()); Expression result = ((MultiStatementExpression) rewriter.visitModuleExpression(module)).statements[0]; InterpretingVisitor interpreter = new InterpretingVisitor(); Object callvalue = interpreter.visit(result); assertThat(callvalue.getClass()).isEqualTo(CxxLanguageFeatures[].class); }
@Override protected Expression visitModuleExpression(@NotNull ModuleExpression expr) { ModuleArchiveExpression archive = expr.archive; CxxLanguageFeatures requires[] = archive.requires; if (requires.length == 0) { return super.visitModuleExpression(expr); } archive = new ModuleArchiveExpression(archive.file, archive.sha256, archive.size, archive.include, archive.includePath, archive.libs, archive.libraryPaths, new CxxLanguageFeatures[0]); List<ConstantExpression> features = new ArrayList<>(); for (CxxLanguageFeatures require : requires) { features.add(constant(require)); } int minimumLanguageStandard = 0; for (CxxLanguageFeatures require : requires) { minimumLanguageStandard = Math.max( minimumLanguageStandard, require.standard); } List<StatementExpression> exprs = new ArrayList<>(); exprs.add( ifSwitch( supportsCompilerFeatures(), requiresCompilerFeatures(array(features.toArray(new ConstantExpression[requires.length]))), requireMinimumCxxCompilerStandard(constant(minimumLanguageStandard)))); exprs.add(archive); return new MultiStatementExpression(exprs.toArray(new StatementExpression[exprs.size()])); }
CxxLanguageStandardRewritingVisitor extends RewritingVisitor { @Override protected Expression visitModuleExpression(@NotNull ModuleExpression expr) { ModuleArchiveExpression archive = expr.archive; CxxLanguageFeatures requires[] = archive.requires; if (requires.length == 0) { return super.visitModuleExpression(expr); } archive = new ModuleArchiveExpression(archive.file, archive.sha256, archive.size, archive.include, archive.includePath, archive.libs, archive.libraryPaths, new CxxLanguageFeatures[0]); List<ConstantExpression> features = new ArrayList<>(); for (CxxLanguageFeatures require : requires) { features.add(constant(require)); } int minimumLanguageStandard = 0; for (CxxLanguageFeatures require : requires) { minimumLanguageStandard = Math.max( minimumLanguageStandard, require.standard); } List<StatementExpression> exprs = new ArrayList<>(); exprs.add( ifSwitch( supportsCompilerFeatures(), requiresCompilerFeatures(array(features.toArray(new ConstantExpression[requires.length]))), requireMinimumCxxCompilerStandard(constant(minimumLanguageStandard)))); exprs.add(archive); return new MultiStatementExpression(exprs.toArray(new StatementExpression[exprs.size()])); } }
CxxLanguageStandardRewritingVisitor extends RewritingVisitor { @Override protected Expression visitModuleExpression(@NotNull ModuleExpression expr) { ModuleArchiveExpression archive = expr.archive; CxxLanguageFeatures requires[] = archive.requires; if (requires.length == 0) { return super.visitModuleExpression(expr); } archive = new ModuleArchiveExpression(archive.file, archive.sha256, archive.size, archive.include, archive.includePath, archive.libs, archive.libraryPaths, new CxxLanguageFeatures[0]); List<ConstantExpression> features = new ArrayList<>(); for (CxxLanguageFeatures require : requires) { features.add(constant(require)); } int minimumLanguageStandard = 0; for (CxxLanguageFeatures require : requires) { minimumLanguageStandard = Math.max( minimumLanguageStandard, require.standard); } List<StatementExpression> exprs = new ArrayList<>(); exprs.add( ifSwitch( supportsCompilerFeatures(), requiresCompilerFeatures(array(features.toArray(new ConstantExpression[requires.length]))), requireMinimumCxxCompilerStandard(constant(minimumLanguageStandard)))); exprs.add(archive); return new MultiStatementExpression(exprs.toArray(new StatementExpression[exprs.size()])); }  }
CxxLanguageStandardRewritingVisitor extends RewritingVisitor { @Override protected Expression visitModuleExpression(@NotNull ModuleExpression expr) { ModuleArchiveExpression archive = expr.archive; CxxLanguageFeatures requires[] = archive.requires; if (requires.length == 0) { return super.visitModuleExpression(expr); } archive = new ModuleArchiveExpression(archive.file, archive.sha256, archive.size, archive.include, archive.includePath, archive.libs, archive.libraryPaths, new CxxLanguageFeatures[0]); List<ConstantExpression> features = new ArrayList<>(); for (CxxLanguageFeatures require : requires) { features.add(constant(require)); } int minimumLanguageStandard = 0; for (CxxLanguageFeatures require : requires) { minimumLanguageStandard = Math.max( minimumLanguageStandard, require.standard); } List<StatementExpression> exprs = new ArrayList<>(); exprs.add( ifSwitch( supportsCompilerFeatures(), requiresCompilerFeatures(array(features.toArray(new ConstantExpression[requires.length]))), requireMinimumCxxCompilerStandard(constant(minimumLanguageStandard)))); exprs.add(archive); return new MultiStatementExpression(exprs.toArray(new StatementExpression[exprs.size()])); }   }
CxxLanguageStandardRewritingVisitor extends RewritingVisitor { @Override protected Expression visitModuleExpression(@NotNull ModuleExpression expr) { ModuleArchiveExpression archive = expr.archive; CxxLanguageFeatures requires[] = archive.requires; if (requires.length == 0) { return super.visitModuleExpression(expr); } archive = new ModuleArchiveExpression(archive.file, archive.sha256, archive.size, archive.include, archive.includePath, archive.libs, archive.libraryPaths, new CxxLanguageFeatures[0]); List<ConstantExpression> features = new ArrayList<>(); for (CxxLanguageFeatures require : requires) { features.add(constant(require)); } int minimumLanguageStandard = 0; for (CxxLanguageFeatures require : requires) { minimumLanguageStandard = Math.max( minimumLanguageStandard, require.standard); } List<StatementExpression> exprs = new ArrayList<>(); exprs.add( ifSwitch( supportsCompilerFeatures(), requiresCompilerFeatures(array(features.toArray(new ConstantExpression[requires.length]))), requireMinimumCxxCompilerStandard(constant(minimumLanguageStandard)))); exprs.add(archive); return new MultiStatementExpression(exprs.toArray(new StatementExpression[exprs.size()])); }    }