ConstCleaner extends ScopeTrackingVisitor { public static void clean(TranslationUnit tu) { new ConstCleaner(tu); } private  ConstCleaner(TranslationUnit tu); static void clean(TranslationUnit tu); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration);  }
@Test public void testCleanWithGlobalsGlsl100Misc() throws Exception { final String program = "" + "uniform float _FLOAT_CONST[1];" + "float foo(vec3 p, vec2 t) {" + " vec2 q = vec2(_FLOAT_CONST[0]);" + " return _FLOAT_CONST[0];" + "}" + "void main() { }"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(program, tu); }
@Test public void testClean() throws Exception { final String program = "void main() {" + " int x;" + " const int y = x + 2;" + "}"; final String expectedProgram = "void main() {" + " int x;" + " int y = x + 2;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }
@Test public void testCleanLarger() throws Exception { final String program = "#version 440\n" + "void main() {" + " int x;" + " const int y = x + 2;" + " const int z = 2 + y;" + "}"; final String expectedProgram = "#version 440\n" + "void main() {" + " int x;" + " int y = x + 2;" + " int z = 2 + y;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }
@Test public void testCleanWithGlobals() throws Exception { final String program = "" + "int g1;" + "const int g2 = g1;" + "void main() {" + "}"; final String expectedProgram = "" + "int g1;" + "int g2;" + "void main() {" + " g2 = g1;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }
@Test public void testCleanWithGlobalsGlsl100() throws Exception { final String program = "" + "int g1;" + "int g2 = g1;" + "void main() {" + "}"; final String expectedProgram = "" + "int g1;" + "int g2;" + "void main() {" + " g2 = g1;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }
@Test public void testCleanWithGlobalsGlsl440() throws Exception { final String program = "#version 440\n" + "int g1;" + "int g2 = g1;" + "void main() {" + "}"; final String expectedProgram = "#version 440\n" + "int g1;" + "int g2 = g1;" + "void main() {" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }
@Test public void testCleanWithGlobalsGlsl100MultipleDeclarations() throws Exception { final String program = "" + "int g1;" + "int g2 = g1, g3 = g1, g4 = 5;" + "void main() {" + "}"; final String expectedProgram = "" + "int g1;" + "int g2, g3, g4;" + "void main() {" + " g2 = g1;" + " g3 = g1;" + " g4 = 5;" + "}"; final TranslationUnit tu = ParseHelper.parse(program); ConstCleaner.clean(tu); CompareAsts.assertEqualAsts(expectedProgram, tu); }