-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
2869ade
9efadb8
68cd363
02d9ad9
1b4d846
7e478bc
fab0dd1
7f517b1
48fda11
778d1aa
3862b43
92a818d
18096c6
9d22b36
f17942c
c6cdf92
a685fc5
fc7b222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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 | ||
| * | ||
|
|
@@ -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, | ||
|
|
@@ -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. | ||
|
|
@@ -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) { | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
|
||
| private static void openMap() { | ||
| try { | ||
| final Configuration conf = context.getConfiguration(); | ||
|
|
@@ -278,12 +412,26 @@ private static void openIssuesMap() { | |
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| private static void openSpecMap() { | ||
psybers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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() { | ||
|
|
@@ -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) { | ||
|
|
||
| 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. | ||
|
|
@@ -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>(); | ||
|
|
@@ -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())); | ||
|
|
||
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
| 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. | ||
|
|
@@ -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>(); | ||
|
|
@@ -61,6 +63,7 @@ public class MethodProtoTuple extends BoaProtoTuple { | |
|
|
||
| names.put("comments", counter++); | ||
| members.add(new BoaProtoList(new CommentProtoTuple())); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
| 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 { | ||
|
||
| 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"; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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)