Skip to content
Snippets Groups Projects
Commit b96ebc28 authored by Johannes Mey's avatar Johannes Mey
Browse files

cleanup

parent fdbee264
Branches
No related tags found
No related merge requests found
Showing
with 0 additions and 1598 deletions
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.simplecfg;
import org.extendj.ast.ExtendJFinding;
/**
* Produces findings using analyzers implemented in the ExtendJ compiler.
*/
public class ExtendJAnalyzerMain {
/**
* Run the ExtendJ analyzer on the files supplied on the command line.
* @param args command-line arguments
*/
public static void main(String[] args) {
ExtendJAnalyzerFrontend checker = new ExtendJAnalyzerFrontend();
int result = checker.run(args);
if (result != 0) {
System.exit(result);
}
System.out.println("Found " + checker.getFindings().size() + " findings.");
for (ExtendJFinding finding : checker.getFindings()) {
System.out.println(finding);
}
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.simplecfg;
import org.extendj.ast.BodyDecl;
import org.extendj.ast.CompilationUnit;
import org.extendj.ast.Program;
import org.extendj.ast.TypeDecl;
import org.extendj.parser.JavaParser;
import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Set;
/**
* Prints a Simplified Control Flow Graph for the first method in a Java program.
*/
public class PrintCfg {
public static void main(String args[]) {
int exitCode = new PrintCfg().run(args);
if (exitCode != 0) {
System.exit(exitCode);
}
}
private int run(String args[]) {
Set<String> argSet = new HashSet<>();
for (String arg : args) {
argSet.add(arg);
}
boolean reverse = argSet.contains("-reverse");
for (String path : args) {
if (!path.equals("-reverse")) {
try {
Program program = new Program();
program.setTypeLookupFilter(Program.BASE_LIBRARY_FILTER);
CompilationUnit unit = new JavaParser().parse(new FileInputStream(path), path);
// Attach the parsed unit to a program node so we have a healthy AST.
program.addCompilationUnit(unit);
// Ensure compilation unit is set to final. This is important to get
// caching to work right in the AST.
unit = program.getCompilationUnit(0);
for (TypeDecl type : unit.getTypeDeclList()) {
for (BodyDecl bd : type.getBodyDeclList()) {
if (reverse) {
bd.printReverseCfg();
} else {
bd.printCfg();
}
}
}
} catch (Exception e) {
System.err.println("Failed to parse input file: " + path);
e.printStackTrace();
return 1;
}
}
}
return 0;
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.simplecfg;
import org.extendj.ast.BodyDecl;
import org.extendj.ast.CompilationUnit;
import org.extendj.ast.Program;
import org.extendj.ast.TypeDecl;
import org.extendj.parser.JavaParser;
import java.io.FileInputStream;
/** Generate test cases for the first CFG of each input class. */
class TestGenerator {
public static void main(String args[]) {
int exitCode = new TestGenerator().run(args);
if (exitCode != 0) {
System.exit(exitCode);
}
}
private int run(String args[]) {
for (String path : args) {
try {
Program program = new Program();
program.setTypeLookupFilter(Program.BASE_LIBRARY_FILTER);
CompilationUnit unit = new JavaParser().parse(new FileInputStream(path), path);
// Attach the parsed unit to a program node so we have a healthy AST.
program.addCompilationUnit(unit);
// Ensure compilation unit is set to final. This is important to get
// caching to work right in the AST.
unit = program.getCompilationUnit(0);
if (unit.getNumTypeDecl() < 1) {
System.err.println("Error: no classes declared in file " + path);
return 1;
}
TypeDecl type = unit.getTypeDecl(0);
if (type.getNumBodyDecl() < 1) {
System.err.println("Error: first class has no body decls in file " + path);
return 1;
}
BodyDecl bd = type.getBodyDecl(0);
bd.printCfgTest();
} catch (Exception e) {
System.err.println("Failed to parse input file: " + path);
e.printStackTrace();
return 1;
}
}
return 0;
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.simplecfg;
import static com.google.common.truth.Truth.assertThat;
import org.extendj.ast.Program;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.Collection;
/** Integration tests for the already-closed checker. */
@RunWith(JUnit4.class)
public class AlreadyClosedTest {
@Test public void test01() {
Collection<String> findings = StmtCfgTest.findings("Close01", Program.ANALYZER_TYPE_FILTER);
assertThat(findings).containsExactly(
"testdata/Close01.javax:23:5: close() may have already been called on writer at this point");
}
/**
* Test that an already-closed finding was generated on the correct line for a simple positive
* test case.
*
* <p>This test case effectively checks that the type analysis works because the type used is
* java.io.Writer, and the analyzer will check if that type is a subtype of java.io.Closeable.
*/
@Test public void writer01() {
Collection<String> findings = StmtCfgTest.findings("AlreadyClosedWriter01",
Program.ANALYZER_TYPE_FILTER);
assertThat(findings).hasSize(1);
assertThat(findings).containsExactly(
"testdata/AlreadyClosedWriter01.javax:27:5: close() may have already been called on writer at this point");
}
@Test public void controlFlow01() {
Collection<Integer> lines = StmtCfgTest.findingLines("AlreadyClosedControlFlow01",
Program.NO_TYPE_FILTER);
assertThat(lines).containsExactly(34, 60, 68, 79, 84, 103, 118);
}
@Test public void negativeFindings01() {
Collection<String> findings = StmtCfgTest.findings("AlreadyClosedNegativeFindings01",
Program.ANALYZER_TYPE_FILTER);
assertThat(findings).isEmpty();
}
}
/**
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.simplecfg;
import static com.google.common.truth.Truth.assertThat;
import org.extendj.ast.CompilationUnit;
import org.extendj.ast.ExtendJFinding;
import org.extendj.ast.Program;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.Collection;
/**
* Integration tests for the nullable dereference checker.
*
* <p>Tests are grouped by the type of null guard used, and then split arbitrarily into separate
* tests/files in order to not have too many positive/negative finding tests in a single test file.
*/
@RunWith(JUnit4.class)
public class NullableDereferenceTest {
@Test public void suggestedFixEndsWithNewline() {
CompilationUnit unit = StmtCfgTest.parseFile("NullableNullGuard01",
Program.ANALYZER_TYPE_FILTER);
Collection<ExtendJFinding> findings = unit.findings();
assertThat(findings).isNotEmpty();
ExtendJFinding finding = findings.iterator().next();
assertThat(finding.fixes).hasSize(1);
assertThat(finding.fixes.iterator().next().newText).endsWith("\n");
}
@Test public void nullGuards01() {
Collection<String> findings = StmtCfgTest.findings("NullableNullGuard01");
assertThat(findings).containsExactly(
"testdata/NullableNullGuard01.javax:42:25: Dereferencing p, which was declared @Nullable.",
"testdata/NullableNullGuard01.javax:49:12: Dereferencing p, which was declared @Nullable.",
"testdata/NullableNullGuard01.javax:62:12: Dereferencing p, which was declared @Nullable.",
"testdata/NullableNullGuard01.javax:93:12: Dereferencing q, which was declared @Nullable."
);
}
@Test public void nullGuards02() {
Collection<String> findings = StmtCfgTest.findings("NullableNullGuard02");
assertThat(findings).containsExactly(
"testdata/NullableNullGuard02.javax:49:7: Dereferencing p, which was declared @Nullable.",
"testdata/NullableNullGuard02.javax:54:7: Dereferencing p, which was declared @Nullable."
);
}
@Test public void nullGuards03() {
Collection<Integer> lines = StmtCfgTest.findingLines("NullableNullGuard03",
Program.ANALYZER_TYPE_FILTER);
assertThat(lines).containsExactly(28, 34, 41, 48, 113, 119);
}
@Test public void methodNullGuard01() {
Collection<String> findings = StmtCfgTest.findings("NullableMethodNullGuard01");
assertThat(findings).isEmpty();
}
@Test public void dataflow01() {
Collection<String> findings = StmtCfgTest.findings("NullableDataflow01");
assertThat(findings).containsExactly(
"testdata/NullableDataflow01.javax:27:7: Dereferencing p, which was declared @Nullable.",
"testdata/NullableDataflow01.javax:35:7: Dereferencing p, which was declared @Nullable."
);
}
@Test public void instanceOf() {
Collection<String> findings = StmtCfgTest.findings("NullableInstanceOf");
assertThat(findings).isEmpty();
}
@Test public void variableArity() {
Collection<String> findings = StmtCfgTest.findings("NullableVariableArity");
assertThat(findings).isEmpty();
}
@Test public void nullableDereference01() {
Collection<String> findings = StmtCfgTest.findings("NullableDereference01");
assertThat(findings).containsExactly(
"testdata/NullableDereference01.javax:27:12: Dereferencing p, which was declared @Nullable.",
"testdata/NullableDereference01.javax:31:12: Dereferencing p, which was declared @Nullable."
);
}
/** Test false positive for GitHub issue #10. */
@Test public void issue10() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceIssue10");
assertThat(findings).containsExactly(
"testdata/NullableDereferenceIssue10.javax:34:31: Dereferencing y, which was declared @Nullable."
);
}
@Test public void issue11() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceIssue11");
assertThat(findings).isEmpty();
}
@Test public void issue12() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceIssue12");
assertThat(findings).isEmpty();
}
@Test public void eqExpr() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceEqExpr");
assertThat(findings).isEmpty();
}
@Test public void neExpr() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceNeExpr");
assertThat(findings).isEmpty();
}
@Test public void methodCall() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceMethodCall");
assertThat(findings).containsExactly(
"testdata/NullableDereferenceMethodCall.javax:41:16: "
+ "Dereferencing p, which was declared @Nullable.");
}
@Test public void issue13() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceIssue13");
assertThat(findings).containsExactly(
"testdata/NullableDereferenceIssue13.javax:33:7: "
+ "Dereferencing obj, which was declared @Nullable.");
}
}
This diff is collapsed.
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.extendj.ast;
import static com.google.common.truth.Truth.assertThat;
import java.util.Set;
import org.extendj.ast.IdentityTupleSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link IdentityTupleSet}. */
@RunWith(JUnit4.class)
public class IdentityTupleSetTest {
// Two unique objects used for testing.
private Object a = new Object();
private Object b = new Object();
@Test public void testSize() {
assertThat(new IdentityTupleSet<>(null, null)).hasSize(1);
assertThat(new IdentityTupleSet<>(a, a)).hasSize(1);
assertThat(new IdentityTupleSet<>(a, b)).hasSize(2);
assertThat(new IdentityTupleSet<>(null, b)).hasSize(2);
}
@Test public void testIsEmpty() {
assertThat(new IdentityTupleSet<>(null, null)).isNotEmpty();
assertThat(new IdentityTupleSet<>(a, a)).isNotEmpty();
assertThat(new IdentityTupleSet<>(a, b)).isNotEmpty();
assertThat(new IdentityTupleSet<>(null, b)).isNotEmpty();
}
@Test public void testDuplicateContains() {
assertThat(new IdentityTupleSet<>(null, null)).containsExactly((Object) null);
assertThat(new IdentityTupleSet<>(a, a)).containsExactly(a);
}
@Test public void testContains() {
assertThat(new IdentityTupleSet<>(a, b)).containsExactly(a, b);
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real code! This file is parsed by the Java API analyzer tests
* to check that the expected findings are reported for this file.
*/
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.FileInputStream;
/* This code is used to check that the already-closed analysis handles different control flow
* structures appropriately.
*/
class AlreadyClosedControlFlow01 {
void for01(FileInputStream in) {
for (int i = 0; i < 10; ++i) {
in.close();
}
// The analyzer does not know how many loop iterations are executed, assumes 0+
// iterations are possible.
in.skip(0); // Positive finding.
}
void for02() {
for (int i = 0; i < 10; ++i) {
FileInputStream in = new FileInputStream("somefile");
in.skip(0);
in.close(); // Negative finding: new instance each iteration.
}
}
void if01() {
Closeable in = new FileInputStream("somefile");
if (System.currentTimeMillis() & 1 == 0) {
in.read();
in.close();
} else {
in.read();
in.close();
}
}
void if02() {
Closeable in = new FileInputStream("somefile");
in.close();
if (System.currentTimeMillis() & 1 == 0) {
in.read(); // Positive finding.
}
}
void if03() {
Closeable in = new FileInputStream("foo");
in.close();
// Check that the if condition is analyzed.
if (in.read() == -1) { // Positive finding.
}
}
void while01() {
Closeable in = new FileInputStream("bar");
while (true) {
in.read();
in.close();
break;
}
in.read(); // Positive finding.
}
void while02() {
Closeable in = new FileInputStream("bar");
while (in.read() != -1) { // Positive finding.
in.close();
}
}
void try01(BufferedInputStream in) {
try {
in.close();
} catch (Throwable t) {
in.read(); // Negative finding: preceding close call interrupted by exception.
}
}
void try02(BufferedInputStream in) {
try {
in.close();
} catch (Throwable t) {
in.read();
} finally {
in.read(); // Positive finding: can be reached after an uninterrupted close call.
}
}
void switch01(BufferedInputStream in, int i) {
switch (i) {
case 1:
in.close();
break;
case 2:
in.read();
break;
case 3:
in.close();
case 4:
in.read(); // Positive finding.
break;
}
}
void switch02(BufferedInputStream in, int i) {
switch (i) {
case 1:
in.close();
break;
case 2:
in.read();
break;
case 3:
in.close();
return;
case 4:
in.read();
default:
in.close();
}
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real code! This file is parsed by the Java API analyzer tests
* to check that no findings are reported for this file.
*/
import java.io.Closeable;
import java.io.FileInputStream;
/* Negative findings for the already-closed analyzer. */
class AlreadyClosedNegativeFindings01 {
static class MyCloseable {
public void close() {
}
public void write() {
}
}
void f1() {
// MyCloseable does not implement java.io.Closeable, so it should not cause findings.
MyCloseable closeable = new MyCloseable();
closeable.close();
closeable.write();
}
void f2() {
while (true) {
// This is a new instance each iteration, so close is only called once per instance.
Closeable in = new FileInputStream("x");
in.read();
in.close();
if (System.currentTimeMillis() % 2 == 1) {
break;
}
}
void f3() {
// This local variable is not effectively final, so it should not be analyzed.
Closeable in = new FileInputStream("x");
in.read();
in.close();
in = new FileInputStream("y");
in.read();
}
void f4() {
// This local variable is not effectively final, so it should not be analyzed.
Closeable in = new FileInputStream("x");
in.read();
in.close();
in = new FileInputStream("y");
in.read();
}
void f5(Closeable in) {
// Repeated calls to close() are allowed and do not produce findings.
in.close();
in.close();
in.close();
in.close();
in.close();
}
String f6(ByteArrayOutputStream out) {
out.close();
return out.toString(); // Negative finding: calling toString() after close() is okay.
}
byte[] f7(ByteArrayOutputStream out) {
out.close();
return out.toByteArray(); // Negative finding: calling toByteArray() after close() is okay.
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real code! This file is parsed by the Java API analyzer tests
* to check that the expected findings are reported for this file.
*/
/* This code is used to check that the already-closed analyzer can identify java.io.Writer
* as a subtype of java.io.Closeable and report a finding for a simple call after close.
*/
class AlreadyClosedWriter01 {
void f(java.io.Writer writer) {
writer.close();
writer.flush(); // Finding: Calling flush() after close().
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
public class Close01 {
void f(java.io.Writer writer) {
writer.close();
writer.write(new byte[10]);
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class ConditionalExpr01 {
static {
// Conditional expressions work like if statements.
int unused = x() ? y() : z();
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class DoStmt01 {
{
do {
x();
} while (y());
z();
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class DoStmt02 {
{
// Test do statement with constant false condition.
do {
x();
} while (false);
y();
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class EnhancedFor01 {
{
for (int a : aList()) {
x();
}
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class Filtering01 {
int x(int c) {
// Test that uninteresting expressions are not included in the CFG.
int a = 4;
int b = 3;
for (int i = i(1, 4 * 5), j = j(); cond() && c == 3; u1(), j += c / 2, u2(), u3(), i++) {
stmt();
a += (--b) * c;
}
return a + b;
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class ForStmt01 {
void x() {
for (; call1(); ) {
}
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class ForStmt02 {
void x() {
for (; call1(); ) {
call2();
}
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class ForStmt03 {
void x() {
for (int i = init(); cond(); update())
stmt();
}
}
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This is test data, not real source code!
* StmtCfgTest builds and tests the CFG for the first block/method in this class.
*/
class ForStmt04 {
{
// Initializer expressions and update statements are evaluated in the order they are listed.
for (int i = i(), j = j(); cond(); u1(), u2(), u3()) {
stmt();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment