Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
9,304 changes: 7,930 additions & 1,374 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
* @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
164 changes: 161 additions & 3 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,12 +206,141 @@ 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) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the blank line at the start of this (and all getSpec methods)

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) {
BoaAstIntrinsics.context = context;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove added space

private static void openMap() {
try {
final Configuration conf = context.getConfiguration();
Expand Down Expand Up @@ -278,12 +412,26 @@ private static void openIssuesMap() {
e.printStackTrace();
}
}

private static void openSpecMap() {
final Configuration conf = new Configuration();
try {
final FileSystem fs = FileSystem.get(conf);
final Path p = new Path("hdfs://boa-njt/",
new Path(context.getConfiguration().get("boa.spec.dir", context.getConfiguration().get("boa.input.dir", "repcache/live")),
new Path("specs")));
specMap = 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 +463,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
10 changes: 8 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,10 @@ 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()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank line at end of block

}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/java/boa/types/proto/MethodProtoTuple.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014, Hridesh Rajan, Robert Dyer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file no longer needs changes. Please revert all changes so this file is not listed as changed.

* 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 @@ -30,6 +31,7 @@
* A {@link MethodProtoTuple}.
*
* @author rdyer
* @author jsu
*/
public class MethodProtoTuple extends BoaProtoTuple {
private final static List<BoaType> members = new ArrayList<BoaType>();
Expand Down Expand Up @@ -61,6 +63,7 @@ public class MethodProtoTuple extends BoaProtoTuple {

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

}

/**
Expand Down
62 changes: 62 additions & 0 deletions src/java/boa/types/proto/SpecCaseProtoTuple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2017, Hridesh Rajan, Robert Dyer, Jingyi Su
* Bowling Green State University
* and Iowa State University of Science and Technology
*
* 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 boa.types.proto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;

/**
* A {@link SpecCaseProtoTuple}.
*
* @author rdyer
* @author jsu
*/
public class SpecCaseProtoTuple extends BoaProtoTuple {
private final static List<BoaType> members = new ArrayList<BoaType>();
private final static Map<String, Integer> names = new HashMap<String, Integer>();

static {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this code to ensure TABs are used as indents, not spaces

int counter = 0;

names.put("modifiers", counter++);
members.add(new BoaProtoList(new ModifierProtoTuple()));

names.put("statements", counter++);
members.add(new BoaProtoList(new StatementProtoTuple()));
}

/**
* Construct a {@link SpecCaseProtoTuple}.
*/
public SpecCaseProtoTuple() {
super(members, names);
}

/** @{inheritDoc} */
@Override
public String toJavaType() {
return "boa.types.Ast.SpecCase";
}
}
Loading