Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving issue #1016 #1127

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/graphicsfuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- 3.5
java-version:
- 8
# - 9
# - 9
runs-on: ${{ matrix.os }}
steps:

Expand Down
29 changes: 21 additions & 8 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions assembly-binaries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>assembly-binaries</artifactId>
<name>assembly-binaries</name>
Expand Down Expand Up @@ -231,13 +231,16 @@ limitations under the License.
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${ant-contrib:ant-contrib:jar}"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpath="${ant-contrib:ant-contrib:jar}"/>

<property name="shaders-zip" value="${com.graphicsfuzz:shaders:zip}"/>


<property name="assembly-zip" value="${project.build.directory}/${project.artifactId}-${project.version}.zip"/>
<property name="assembly-dir" value="${project.build.directory}/${project.artifactId}-${project.version}"/>
<property name="assembly-zip"
value="${project.build.directory}/${project.artifactId}-${project.version}.zip"/>
<property name="assembly-dir"
value="${project.build.directory}/${project.artifactId}-${project.version}"/>

<property name="touched-file" value="${project.build.directory}/touched.txt"/>

Expand Down Expand Up @@ -400,7 +403,7 @@ limitations under the License.

</java>
<unzip src="${assembly-zip}" dest="${assembly-dir}"/>
<chmod perm="ugo+x" dir="${assembly-dir}/bin" includes="**" />
<chmod perm="ugo+x" dir="${assembly-dir}/bin" includes="**"/>
<touch file="${touched-file}"/>
</sequential>
</outofdate>
Expand Down
6 changes: 3 additions & 3 deletions ast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>ast</artifactId>
<name>ast</name>
Expand Down
90 changes: 45 additions & 45 deletions ast/src/main/java/com/graphicsfuzz/common/ast/AstUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,55 @@

public final class AstUtil {

private AstUtil() {
// Utility class should not be instantiable.
}
private AstUtil() {
// Utility class should not be instantiable.
}

/**
* Gets prototypes for all the functions declared, either via full declarations or
* just prototypes, in the given shader.
*
* @param shader A shader from which function prototypes should be extracted
* @return set of prototypes for all functions declared fully or via prototypes in the shader
*/
public static List<FunctionPrototype> getFunctionPrototypesFromShader(TranslationUnit shader) {
return getPrototypesForAllFunctions(shader.getTopLevelDeclarations());
}
/**
* Gets prototypes for all the functions declared, either via full declarations or
* just prototypes, in the given shader.
*
* @param shader A shader from which function prototypes should be extracted
* @return set of prototypes for all functions declared fully or via prototypes in the shader
*/
public static List<FunctionPrototype> getFunctionPrototypesFromShader(TranslationUnit shader) {
return getPrototypesForAllFunctions(shader.getTopLevelDeclarations());
}

/**
* Gets prototypes for all the functions declarations or prototypes in the given list of
* declarations.
*
* @param decls A list of declarations
* @return set of prototypes for all functions declared fully or via prototypes in the declaration
* list
*/
public static List<FunctionPrototype> getPrototypesForAllFunctions(List<Declaration> decls) {
// Grab all prototypes associated with function definitions
List<FunctionPrototype> result =
getFunctionDefinitions(decls).map(x -> x.getPrototype()).collect(Collectors.toList());
// Add any additional prototypes
// TODO: we only check whether a function definition with a matching name is present;
// we should strengthen this to consider instead an exact prototype match.
result.addAll(
getFunctionPrototypes(decls).filter(
x -> !getFunctionNames(result)
.contains(x.getName())).collect(Collectors.toList()));
return result;
}
/**
* Gets prototypes for all the functions declarations or prototypes in the given list of
* declarations.
*
* @param decls A list of declarations
* @return set of prototypes for all functions declared fully or via prototypes in the declaration
* list
*/
public static List<FunctionPrototype> getPrototypesForAllFunctions(List<Declaration> decls) {
// Grab all prototypes associated with function definitions
List<FunctionPrototype> result =
getFunctionDefinitions(decls).map(x -> x.getPrototype()).collect(Collectors.toList());
// Add any additional prototypes
// TODO: we only check whether a function definition with a matching name is present;
// we should strengthen this to consider instead an exact prototype match.
result.addAll(
getFunctionPrototypes(decls).filter(
x -> !getFunctionNames(result)
.contains(x.getName())).collect(Collectors.toList()));
return result;
}

private static Stream<FunctionDefinition> getFunctionDefinitions(List<Declaration> decls) {
return decls.stream().filter(x -> x instanceof FunctionDefinition)
.map(x -> ((FunctionDefinition) x));
}
private static Stream<FunctionDefinition> getFunctionDefinitions(List<Declaration> decls) {
return decls.stream().filter(x -> x instanceof FunctionDefinition)
.map(x -> ((FunctionDefinition) x));
}

private static Stream<FunctionPrototype> getFunctionPrototypes(List<Declaration> decls) {
return decls.stream().filter(x -> x instanceof FunctionPrototype)
.map(x -> (FunctionPrototype) x);
}
private static List<String> getFunctionNames(List<FunctionPrototype> prototypes) {
return prototypes.stream().map(y -> y.getName()).collect(Collectors.toList());
}

private static List<String> getFunctionNames(List<FunctionPrototype> prototypes) {
return prototypes.stream().map(y -> y.getName()).collect(Collectors.toList());
}
private static Stream<FunctionPrototype> getFunctionPrototypes(List<Declaration> decls) {
return decls.stream().filter(x -> x instanceof FunctionPrototype)
.map(x -> (FunctionPrototype) x);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

public class ChildDoesNotExistException extends RuntimeException {

private final IAstNode nonChild;
private final IAstNode wouldBeParent;
private final IAstNode nonChild;
private final IAstNode wouldBeParent;

public ChildDoesNotExistException(IAstNode nonChild, IAstNode wouldBeParent) {
this.nonChild = nonChild;
this.wouldBeParent = wouldBeParent;
}
public ChildDoesNotExistException(IAstNode nonChild, IAstNode wouldBeParent) {
this.nonChild = nonChild;
this.wouldBeParent = wouldBeParent;
}

@Override
public String getMessage() {
return nonChild + " is not a child of " + wouldBeParent;
}
@Override
public String getMessage() {
return nonChild + " is not a child of " + wouldBeParent;
}

}
89 changes: 44 additions & 45 deletions ast/src/main/java/com/graphicsfuzz/common/ast/IAstNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,55 @@

public interface IAstNode extends Cloneable {

void accept(IAstVisitor visitor);
void accept(IAstVisitor visitor);

IAstNode clone();
IAstNode clone();

/**
* Replaces a child of the node with a new child.
* Only available on selected classes where this has proven to be a sensible operation to perform;
* throws an exception by default.
* Developers should add to further classes as and when appropriate.
*
* @param child The child to be replaced
* @param newChild The replacement child
* @throws ChildDoesNotExistException if there is no such child.
* @throws UnsupportedOperationException if the operation is not available, or if
* the new child is not suitable.
*/
default void replaceChild(IAstNode child, IAstNode newChild) {
throw new UnsupportedOperationException(
"Child replacement not supported for nodes of type " + this.getClass());
}


/**
* Checks whether the node has a particular child.
* Only available on selected classes where this has proven to be a sensible operation to perform;
* throws an exception by default.
* Developers should add to further classes as and when appropriate.
*
* @param candidateChild The potential child node.
* @throws UnsupportedOperationException if the operation is not supported.
*/
default boolean hasChild(IAstNode candidateChild) {
throw new UnsupportedOperationException(
"Child querying not supported for nodes of type " + this.getClass());
}
/**
* Uses the pretty printer to turn a node into a text representation.
*
* @return Text representation of a node
*/
default String getText() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

try (PrintStream stream = new PrintStream(baos)) {
new PrettyPrinterVisitor(stream).visit(this);
return baos.toString("UTF8");
} catch (UnsupportedEncodingException exception) {
return "<unknown>";
}
}

/**
* Uses the pretty printer to turn a node into a text representation.
* @return Text representation of a node
*/
default String getText() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
/**
* Checks whether the node has a particular child.
* Only available on selected classes where this has proven to be a sensible operation to perform;
* throws an exception by default.
* Developers should add to further classes as and when appropriate.
*
* @param candidateChild The potential child node.
* @throws UnsupportedOperationException if the operation is not supported.
*/
default boolean hasChild(IAstNode candidateChild) {
throw new UnsupportedOperationException(
"Child querying not supported for nodes of type " + this.getClass());
}

try (PrintStream stream = new PrintStream(baos)) {
new PrettyPrinterVisitor(stream).visit(this);
return baos.toString("UTF8");
} catch (UnsupportedEncodingException exception) {
return "<unknown>";
/**
* Replaces a child of the node with a new child.
* Only available on selected classes where this has proven to be a sensible operation to perform;
* throws an exception by default.
* Developers should add to further classes as and when appropriate.
*
* @param child The child to be replaced
* @param newChild The replacement child
* @throws ChildDoesNotExistException if there is no such child.
* @throws UnsupportedOperationException if the operation is not available, or if
* the new child is not suitable.
*/
default void replaceChild(IAstNode child, IAstNode newChild) {
throw new UnsupportedOperationException(
"Child replacement not supported for nodes of type " + this.getClass());
}
}

}
10 changes: 5 additions & 5 deletions ast/src/main/java/com/graphicsfuzz/common/ast/IParentMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

public interface IParentMap {

boolean hasParent(IAstNode node);
static IParentMap createParentMap(IAstNode root) {
return new ParentMap(root);
}

IAstNode getParent(IAstNode node);
IAstNode getParent(IAstNode node);

static IParentMap createParentMap(IAstNode root) {
return new ParentMap(root);
}
boolean hasParent(IAstNode node);

}
Loading