Skip to content

Commit dc56ce6

Browse files
committed
remove dead code, clean up
1 parent a261d9e commit dc56ce6

File tree

3 files changed

+10
-81
lines changed

3 files changed

+10
-81
lines changed

java/src/org/antlr/codebuff/CollectFeatures.java

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,15 @@ public class CollectFeatures {
9797

9898
public static final int NUM_FEATURES = 18;
9999

100-
// public static final int INDEX_RULE = 8; // what rule are we in?
101-
// public static final int INDEX_EARLIEST_RIGHT_ANCESTOR = 9;
102-
// public static final int INDEX_ANCESTORS_PARENT5_RULE = 11;
103-
// public static final int INDEX_ANCESTORS_PARENT4_RULE = 12;
104-
// public static final int INDEX_ANCESTORS_PARENT3_RULE = 13;
105-
// public static final int INDEX_ANCESTORS_PARENT3_WID = 14;
106-
// public static final int INDEX_ANCESTORS_PARENT2_RULE = 15;
107-
// public static final int INDEX_ANCESTORS_PARENT2_WID = 16;
108-
// public static final int INDEX_ANCESTORS_PARENT_RULE = 17;
109-
// public static final int INDEX_ANCESTORS_PARENT_WID = 18;
110-
// public static final int INDEX_NEXT_TYPE = 19;
111-
112-
113100
public static FeatureMetaData[] FEATURES_INJECT_WS = { // inject ws or nl
114101
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(-1)"}, 1),
115102
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(-1)", "right ancestor"}, 1),
116103
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(1)"}, 1),
117104
new FeatureMetaData(FeatureType.BOOL, new String[]{"Pair", "dif\\n"}, 1),
118105
FeatureMetaData.UNUSED,
119106
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
120-
// these previous 5 features seem to predict newline really well. whitespace ok too
121107
new FeatureMetaData(FeatureType.INT, new String[] {"ancestor", "child index"}, 1),
108+
// these previous 6 features seem to predict newline really well. whitespace ok too
122109
FeatureMetaData.UNUSED,
123110
FeatureMetaData.UNUSED,
124111
FeatureMetaData.UNUSED,
@@ -174,10 +161,6 @@ public class CollectFeatures {
174161
new FeatureMetaData(FeatureType.INFO_CHARPOS, new String[] {"char", "pos"}, 0)
175162
};
176163

177-
public static int getCurrentTokenType(int[] features) { return features[INDEX_CUR_TYPE]; }
178-
public static int getInfoLine(int[] features) { return features[INDEX_INFO_LINE]; }
179-
public static int getInfoCharPos(int[] features) { return features[INDEX_INFO_CHARPOS]; }
180-
181164
protected InputDocument doc;
182165
protected ParserRuleContext root;
183166
protected CommonTokenStream tokens; // track stream so we can examine previous tokens
@@ -444,48 +427,17 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
444427

445428
// Get context information for current token
446429
parent = (ParserRuleContext)node.getParent();
447-
int curTokensParentRuleIndex = parent.getRuleIndex();
448430
ParserRuleContext earliestLeftAncestor = earliestAncestorStartingWithToken(node, curToken);
449-
int earliestLeftAncestorRuleIndex = earliestLeftAncestor.getRuleIndex();
450-
int earliestLeftAncestorRuleAlt = earliestLeftAncestor.getAltNumber();
451431
ParserRuleContext earliestLeftAncestorParent = earliestLeftAncestor.getParent();
452432

453433
ParserRuleContext earliestLeftAncestorParent2 = earliestLeftAncestorParent!=null ? earliestLeftAncestorParent.getParent() : null;
454434
ParserRuleContext earliestLeftAncestorParent3 = earliestLeftAncestorParent2!=null ? earliestLeftAncestorParent2.getParent() : null;
455435
ParserRuleContext earliestLeftAncestorParent4 = earliestLeftAncestorParent3!=null ? earliestLeftAncestorParent3.getParent() : null;
456436

457437
ParserRuleContext earliestRightAncestor = earliestAncestorEndingWithToken(node, curToken);
458-
int earliestRightAncestorRuleIndex = earliestRightAncestor.getRuleIndex();
459-
int earliestRightAncestorRuleAlt = earliestRightAncestor.getAltNumber();
460438

461439
int matchingSymbolOnDiffLine = getMatchingSymbolOnDiffLine(doc, node, line);
462440

463-
// Get some context from parse tree
464-
// if ( earliestLeftAncestor==null ) { // just use regular parent then
465-
// ancestorParent = getParent(node);
466-
// if ( ancestorParent!=null ) {
467-
// ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
468-
// }
469-
// }
470-
// else {
471-
// ancestorParent = getParent(earliestLeftAncestor); // get parent but skip chain rules
472-
// if ( ancestorParent!=null ) {
473-
// ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
474-
// }
475-
// }
476-
// ParserRuleContext ancestorParent3 = ancestorParent2!=null ? ancestorParent2.getParent() : null;
477-
// ParserRuleContext ancestorParent4 = ancestorParent3!=null ? ancestorParent3.getParent() : null;
478-
// ParserRuleContext ancestorParent5 = ancestorParent4!=null ? ancestorParent4.getParent() : null;
479-
480-
// public static final int INDEX_PREV_TYPE = 0;
481-
// public static final int INDEX_PREV_EARLIEST_RIGHT_ANCESTOR = 1;
482-
// public static final int INDEX_CUR_TYPE = 2;
483-
// public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 3;
484-
// public static final int INDEX_FIRST_ON_LINE = 4; // a \n right before this token?
485-
// public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 5;
486-
// new FeatureMetaData(FeatureType.RULE, new String[] {"left ancestor", "parent"}, 1),
487-
// new FeatureMetaData(FeatureType.INT, new String[] {"left ancestor", "child index"}, 1),
488-
489441
boolean curTokenStartsNewLine = tokens.LT(1).getLine()>tokens.LT(-1).getLine();
490442
int[] features = {
491443
tokens.LT(-1).getType(),
@@ -510,7 +462,6 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
510462
curToken.getCharPositionInLine()
511463
};
512464
assert features.length == NUM_FEATURES;
513-
// System.out.print(curToken+": "+CodekNNClassifier._toString(features));
514465
return features;
515466
}
516467

@@ -762,10 +713,6 @@ public static List<Token> getRealTokens(CommonTokenStream tokens) {
762713
return real;
763714
}
764715

765-
public static ParserRuleContext getParent(TerminalNode p) {
766-
return parentClosure((ParserRuleContext)p.getParent());
767-
}
768-
769716
public static int getChildIndex(ParseTree t) {
770717
if ( t==null ) return -1;
771718
ParseTree parent = t.getParent();
@@ -790,26 +737,6 @@ public static int getChildIndex(ParseTree t) {
790737
return -1;
791738
}
792739

793-
/** Same as p.getParent() except we scan through chain rule nodes */
794-
public static ParserRuleContext getParent(ParserRuleContext p) {
795-
if ( p==null ) return null;
796-
ParserRuleContext lastValidParent = p.getParent();
797-
if ( lastValidParent==null ) return null; // must have hit the root
798-
799-
return parentClosure(p.getParent());
800-
}
801-
802-
// try to walk chain rules starting with the parent of the usual parent
803-
public static ParserRuleContext parentClosure(ParserRuleContext p) {
804-
ParserRuleContext lastValidParent = p;
805-
ParserRuleContext q = lastValidParent.getParent();
806-
while ( q!=null && q.getChildCount()==1 ) { // while is a chain rule
807-
lastValidParent = q;
808-
q = q.getParent();
809-
}
810-
return lastValidParent;
811-
}
812-
813740
/** Pack a rule index and an alternative number into the same 32-bit integer. */
814741
public static int rulealt(int rule, int alt) {
815742
if ( rule==-1 ) return -1;

java/src/org/antlr/codebuff/Formatter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class Formatter {
4848
protected Vector<TokenPositionAnalysis> analysis = new Vector<>();
4949

5050
protected CodekNNClassifier nlwsClassifier;
51-
protected CodekNNClassifier wsClassifier;
5251
protected CodekNNClassifier alignClassifier;
5352
protected int k;
5453

@@ -227,6 +226,10 @@ else if ( (align&0xFF)==CAT_INDENT_FROM_ANCESTOR_FIRST_TOKEN ) {
227226
/** Look into the token stream to get the comments to the left of current
228227
* token. Emit all whitespace and comments except for whitespace at the
229228
* end as we'll inject that per newline prediction.
229+
*
230+
* This assumes we are grooming not totally reformatting.
231+
* We able to see original input stream for comment purposes. With all
232+
* whitespace removed, we can't emit this stuff properly at moment.
230233
*/
231234
public void emitCommentsToTheLeft(int tokenIndexInStream) {
232235
List<Token> hiddenTokensToLeft = tokens.getHiddenTokensToLeft(tokenIndexInStream);
@@ -270,7 +273,7 @@ public void emitCommentsToTheLeft(int tokenIndexInStream) {
270273

271274
public TokenPositionAnalysis getTokenAnalysis(int[] features, int indexIntoRealTokens, int tokenIndexInStream,
272275
int injectNewline,
273-
int alignWithPrevious,
276+
int align,
274277
int ws)
275278
{
276279
CommonToken curToken = (CommonToken)tokens.get(tokenIndexInStream);
@@ -286,12 +289,11 @@ public TokenPositionAnalysis getTokenAnalysis(int[] features, int indexIntoRealT
286289

287290
boolean prevIsWS = prevToken.getChannel()==Token.HIDDEN_CHANNEL; // assume this means whitespace
288291
int actualNL = Tool.count(prevToken.getText(), '\n');
289-
int actualWS = Tool.count(prevToken.getText(), ' ');
290-
String newlinePredictionString = String.format("### line %d: predicted %d \\n actual %s",
292+
String newlinePredictionString = String.format("### line %d: predicted %d \\n actual ?",
291293
originalCurToken.getLine(), injectNewline, prevIsWS ? actualNL : "none");
292-
String alignPredictionString = String.format("### line %d: predicted %s actual %s",
294+
String alignPredictionString = String.format("### line %d: predicted %d actual %s",
293295
originalCurToken.getLine(),
294-
alignWithPrevious==1?"align":"unaligned",
296+
align,
295297
"?");
296298

297299
String newlineAnalysis = newlinePredictionString+"\n"+

java/src/org/antlr/codebuff/Neighbor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public String toString(FeatureMetaData[] FEATURES, List<Integer> Y) {
1717
int[] X = corpus.X.get(corpusVectorIndex);
1818
InputDocument doc = corpus.documents.get(corpusVectorIndex);
1919
String features = CollectFeatures._toString(FEATURES, doc, X);
20-
int line = CollectFeatures.getInfoLine(X);
20+
int line = X[CollectFeatures.INDEX_INFO_LINE];
2121
String lineText = doc.getLine(line);
2222
int col = X[CollectFeatures.INDEX_INFO_CHARPOS];
2323
// insert a dot right before char position

0 commit comments

Comments
 (0)