Skip to content

Request to merge Specs-2017-09 with master #158

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
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
161 changes: 159 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 Down Expand Up @@ -201,6 +202,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 == null || !f.hasKey())
return null;
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 null;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecMethod", formalParameters = { "Method" })
public static SpecMethod getspec(final Method f) {
if (f == null || !f.hasKey())
return null;
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 null;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecStatement", formalParameters = { "Statement" })
public static SpecStatement getspec(final Statement f) {
if (f == null || !f.hasKey())
return null;
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 null;
}
@SuppressWarnings("unchecked")
@FunctionSpec(name = "getspec", returnType = "SpecVariable", formalParameters = { "Variable" })
public static SpecVariable getspec(final Variable f) {
if (f == null || !f.hasKey())
return null;
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 null;
}

@SuppressWarnings("rawtypes")
public static void setup(final Context context) {
Expand Down Expand Up @@ -278,12 +399,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 +462,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
Loading