Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14,812 changes: 10,906 additions & 3,906 deletions src/compiled-proto/boa/types/Ast.java

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/java/boa/compiler/SymbolTable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017, Anthony Urso, Hridesh Rajan, Robert Dyer,
* Copyright 2017, Anthony Urso, Hridesh Rajan, Robert Dyer, Jingyi Su
* Iowa State University of Science and Technology
* and Bowling Green State University
*
Expand Down Expand Up @@ -37,6 +37,7 @@
* @author anthonyu
* @author rdyer
* @author rramu
* @author jsu
*/
public class SymbolTable {
private static HashMap<String, Class<?>> aggregators;
Expand Down Expand Up @@ -117,6 +118,11 @@ public class SymbolTable {
new StatementProtoTuple(),
new TypeProtoTuple(),
new VariableProtoTuple(),
new SpecCaseProtoTuple(),
new SpecDeclarationProtoTuple(),
new SpecMethodProtoTuple(),
new SpecStatementProtoTuple(),
new SpecVariableProtoTuple(),
};
final BoaProtoMap[] dslMapTypes = {
new CFGNodeTypeProtoMap(),
Expand Down
165 changes: 163 additions & 2 deletions src/java/boa/functions/BoaAstIntrinsics.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017, Hridesh Rajan, Robert Dyer,
* Copyright 2017, Hridesh Rajan, Robert Dyer, Jingyi Su
* Iowa State University of Science and Technology
* and Bowling Green State University
*
Expand Down Expand Up @@ -47,11 +47,12 @@
* Boa functions for working with ASTs.
*
* @author rdyer
* @author jsu
*/
public class BoaAstIntrinsics {
@SuppressWarnings("rawtypes")
private static Context context;
private static MapFile.Reader map, commentsMap, issuesMap;
private static MapFile.Reader map, commentsMap, issuesMap, specMap;

public static enum ASTCOUNTER {
GETS_ATTEMPTED,
Expand All @@ -70,6 +71,10 @@ public static String changedfileToString(final ChangedFile f) {
private static final ASTRoot emptyAst = ASTRoot.newBuilder().build();
private static final CommentsRoot emptyComments = CommentsRoot.newBuilder().build();
private static final IssuesRoot emptyIssues = IssuesRoot.newBuilder().build();
private static final SpecDeclaration emptySpecDeclaration = SpecDeclaration.newBuilder().build();
private static final SpecMethod emptySpecMethod = SpecMethod.newBuilder().build();
private static final SpecStatement emptySpecStatement = SpecStatement.newBuilder().build();
private static final SpecVariable emptySpecVariable = SpecVariable.newBuilder().build();

/**
* Given a ChangedFile, return the AST for that file at that revision.
Expand Down Expand Up @@ -201,6 +206,126 @@ public static IssuesRoot getissues(final IssueRepository f) {
System.err.println("error with issues: " + f.getKey());
return emptyIssues;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecDeclaration", formalParameters = { "Declaration" })
public static SpecDeclaration getspec(final Declaration f) {
if (!f.hasKey())
return emptySpecDeclaration;
final String rowName = f.getKey() + "!!" + f.getName();

if (specMap == null)
openSpecMap();

try {
final BytesWritable value = new BytesWritable();
if (specMap.get(new Text(rowName), value) == null) {
final CodedInputStream _stream = CodedInputStream.newInstance(value.getBytes(), 0, value.getLength());
final SpecDeclaration specdeclaration = SpecDeclaration.parseFrom(_stream);
return specdeclaration;
}
} catch (final InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final Error e) {
e.printStackTrace();
}

System.err.println("error with SpecDeclaration: " + rowName);
return emptySpecDeclaration;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecMethod", formalParameters = { "Method" })
public static SpecMethod getspec(final Method f) {
if (!f.hasKey())
return emptySpecMethod;
final String rowName = f.getKey() + "!!" + f.getName();

if (specMap == null)
openSpecMap();

try {
final BytesWritable value = new BytesWritable();
if (specMap.get(new Text(rowName), value) == null) {
final CodedInputStream _stream = CodedInputStream.newInstance(value.getBytes(), 0, value.getLength());
final SpecMethod specmethod = SpecMethod.parseFrom(_stream);
return specmethod;
}
} catch (final InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final Error e) {
e.printStackTrace();
}

System.err.println("error with SpecMethod: " + rowName);
return emptySpecMethod;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecStatement", formalParameters = { "Statement" })
public static SpecStatement getspec(final Statement f) {
if (!f.hasKey())
return emptySpecStatement;
final String rowName = f.getKey();

if (specMap == null)
openSpecMap();

try {
final BytesWritable value = new BytesWritable();
if (specMap.get(new Text(rowName), value) == null) {
final CodedInputStream _stream = CodedInputStream.newInstance(value.getBytes(), 0, value.getLength());
final SpecStatement specstatement = SpecStatement.parseFrom(_stream);
return specstatement;
}
} catch (final InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final Error e) {
e.printStackTrace();
}

System.err.println("error with SpecStatement: " + rowName);
return emptySpecStatement;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecVariable", formalParameters = { "Variable" })
public static SpecVariable getspec(final Variable f) {
if (!f.hasKey())
return emptySpecVariable;
final String rowName = f.getKey() + "!!" + f.getName();

if (specMap == null)
openSpecMap();

try {
final BytesWritable value = new BytesWritable();
if (specMap.get(new Text(rowName), value) == null) {
final CodedInputStream _stream = CodedInputStream.newInstance(value.getBytes(), 0, value.getLength());
final SpecVariable specvariable = SpecVariable.parseFrom(_stream);
return specvariable;
}
} catch (final InvalidProtocolBufferException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final RuntimeException e) {
e.printStackTrace();
} catch (final Error e) {
e.printStackTrace();
}

System.err.println("error with SpecVariable: " + rowName);
return emptySpecVariable;
}

@SuppressWarnings("rawtypes")
public static void setup(final Context context) {
Expand Down Expand Up @@ -278,12 +403,38 @@ private static void openIssuesMap() {
e.printStackTrace();
}
}

private static void openSpecMap() {

try {
final Configuration conf = context.getConfiguration();
final FileSystem fs;
final Path p;
if (DefaultProperties.localDataPath != null) {
p = new Path(DefaultProperties.localIssuePath);
fs = FileSystem.getLocal(conf);
} else {
p = new Path(
context.getConfiguration().get("fs.default.name", "hdfs://boa-njt/"),
new Path(
conf.get("boa.spec.dir", conf.get("boa.input.dir", "repcache/live")),
new Path("specs")
)
);
fs = FileSystem.get(conf);
}
issuesMap = new MapFile.Reader(fs, p.toString(), conf);
} catch (final Exception e) {
e.printStackTrace();
}
}

@SuppressWarnings("rawtypes")
public static void cleanup(final Context context) {
closeMap();
closeCommentMap();
closeIssuesMap();
closeSpecMap();
}

private static void closeMap() {
Expand Down Expand Up @@ -315,6 +466,16 @@ private static void closeIssuesMap() {
}
issuesMap = null;
}

private static void closeSpecMap() {
if (specMap != null)
try {
specMap.close();
} catch (final IOException e) {
e.printStackTrace();
}
specMap = null;
}

@FunctionSpec(name = "type_name", returnType = "string", formalParameters = { "string" })
public static String type_name(final String s) {
Expand Down
50 changes: 48 additions & 2 deletions src/java/boa/runtime/BoaAbstractVisitor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014, Hridesh Rajan, Robert Dyer,
* and Iowa State University of Science and Technology
* Copyright 2017, Hridesh Rajan, Robert Dyer, Jingyi Su,
* Iowa State University of Science and Technology
* and Bowling Green State University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +38,7 @@
* By default, all <code>postVisit()</code> methods call {@link #defaultPostVisit()}.
*
* @author rdyer
* @author jsu
*/
public abstract class BoaAbstractVisitor {
/**
Expand Down Expand Up @@ -103,6 +105,18 @@ protected boolean preVisit(final Comment node) throws Exception {
protected boolean preVisit(final Person node) throws Exception {
return defaultPreVisit();
}
protected boolean preVisit(final SpecDeclaration node) throws Exception {
return defaultPreVisit();
}
protected boolean preVisit(final SpecMethod node) throws Exception {
return defaultPreVisit();
}
protected boolean preVisit(final SpecStatement node) throws Exception {
return defaultPreVisit();
}
protected boolean preVisit(final SpecVariable node) throws Exception {
return defaultPreVisit();
}

/**
* Provides a default action for post-visiting nodes.
Expand Down Expand Up @@ -155,6 +169,18 @@ protected void postVisit(final Comment node) throws Exception {
protected void postVisit(final Person node) throws Exception {
defaultPostVisit();
}
protected void postVisit(final SpecDeclaration node) throws Exception {
defaultPostVisit();
}
protected void postVisit(final SpecMethod node) throws Exception {
defaultPostVisit();
}
protected void postVisit(final SpecStatement node) throws Exception {
defaultPostVisit();
}
protected void postVisit(final SpecVariable node) throws Exception {
defaultPostVisit();
}

public final void visit(final Project node) throws Exception {
if (preVisit(node)) {
Expand Down Expand Up @@ -404,4 +430,24 @@ public final void visit(final Person node) throws Exception {
postVisit(node);
}
}
public final void visit(final SpecDeclaration node) throws Exception {
if (preVisit(node)) {
postVisit(node);
}
}
public final void visit(final SpecMethod node) throws Exception {
if (preVisit(node)) {
postVisit(node);
}
}
public final void visit(final SpecStatement node) throws Exception {
if (preVisit(node)) {
postVisit(node);
}
}
public final void visit(final SpecVariable node) throws Exception {
if (preVisit(node)) {
postVisit(node);
}
}
}
9 changes: 7 additions & 2 deletions src/java/boa/types/proto/DeclarationProtoTuple.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014, Hridesh Rajan, Robert Dyer,
* and Iowa State University of Science and Technology
* Copyright 2017, Hridesh Rajan, Robert Dyer, Jingyi Su
* Iowa State University of Science and Technology
* and Bowling Green State University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +32,7 @@
* A {@link DeclarationProtoTuple}.
*
* @author rdyer
* @author jsu
*/
public class DeclarationProtoTuple extends BoaProtoTuple {
private final static List<BoaType> members = new ArrayList<BoaType>();
Expand Down Expand Up @@ -65,6 +67,9 @@ public class DeclarationProtoTuple extends BoaProtoTuple {

names.put("comments", counter++);
members.add(new BoaProtoList(new CommentProtoTuple()));

names.put("specs", counter++);
members.add(new BoaProtoList(new SpecStatementProtoTuple()));
}

/**
Expand Down
Loading