StripUnusedGlobals extends ScopeTrackingVisitor { public static void strip(TranslationUnit tu) { new StripUnusedGlobals(tu); } private  StripUnusedGlobals(TranslationUnit tu); static void strip(TranslationUnit tu); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitStructNameType(StructNameType structNameType); @Override void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr); @Override void visitVariableDeclInfo(VariableDeclInfo variableDeclInfo); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr);  }
@Test public void testDoNotStripStruct() throws Exception { final String original = "" + "struct S { int a; };" + "void main() {" + " S myS;" + "}"; final TranslationUnit tu = ParseHelper.parse(original); StripUnusedGlobals.strip(tu); CompareAsts.assertEqualAsts(original, tu); }
@Test public void testDoNotStripStructOnlyUsedAsConstructor() throws Exception { final String original = "" + "struct S { int a; };" + "void main() {" + " vec2(1.0, 2.0);" + " S(3);" + "}"; final TranslationUnit tu = ParseHelper.parse(original); StripUnusedGlobals.strip(tu); CompareAsts.assertEqualAsts(original, tu); }
@Test public void testDoNotStripConstantUsedToInitializeArray() throws Exception { final String original = "" + "const int N = 5;\n" + "int A[N];\n" + "void main() {" + " A[0] = 1;\n" + "}"; final TranslationUnit tu = ParseHelper.parse(original); StripUnusedGlobals.strip(tu); CompareAsts.assertEqualAsts(original, tu); }