Skip to content
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

Introduce column number in AST nodes #1724

Open
wants to merge 2 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
152 changes: 95 additions & 57 deletions rhino/src/main/java/org/mozilla/javascript/IRFactory.java

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions rhino/src/main/java/org/mozilla/javascript/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ public Node(int nodeType, Node left, Node mid, Node right) {
right.next = null;
}

public Node(int nodeType, int line) {
public Node(int nodeType, int line, int column) {
type = nodeType;
lineno = line;
setLineColumnNumber(line, column);
}

public Node(int nodeType, Node child, int line) {
public Node(int nodeType, Node child, int line, int column) {
this(nodeType, child);
lineno = line;
setLineColumnNumber(line, column);
}

public Node(int nodeType, Node left, Node right, int line) {
public Node(int nodeType, Node left, Node right, int line, int column) {
this(nodeType, left, right);
lineno = line;
setLineColumnNumber(line, column);
}

public Node(int nodeType, Node left, Node mid, Node right, int line) {
public Node(int nodeType, Node left, Node mid, Node right, int line, int column) {
this(nodeType, left, mid, right);
lineno = line;
setLineColumnNumber(line, column);
}

public static Node newNumber(double number) {
Expand Down Expand Up @@ -531,8 +531,9 @@ public int getLineno() {
return lineno;
}

public void setLineno(int lineno) {
public void setLineColumnNumber(int lineno, int column) {
this.lineno = lineno;
this.column = column;
}

/** Can only be called when <code>getType() == Token.NUMBER</code> */
Expand Down Expand Up @@ -1253,11 +1254,21 @@ private static void appendPrintId(Node n, Map<Node, Integer> printIds, StringBui
}
}

/**
* @return the column of where a Node is defined in source. If the column is -1, it was never
* initialized. One-based.
* <p>May be overridden by sub classes
*/
public int getColumn() {
return column;
}

protected int type = Token.ERROR; // type of the node, e.g. Token.NAME
protected Node next; // next sibling
protected Node first; // first element of a linked list of children
protected Node last; // last element of a linked list of children
protected int lineno = -1;
private int column = -1;

/**
* Linked list of properties. Since vast majority of nodes would have no more then 2 properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ private void transformCompilationUnit_r(
unwind = new Node(Token.LEAVEWITH);
}
if (unwindBlock == null) {
unwindBlock = new Node(Token.BLOCK, node.getLineno());
unwindBlock = new Node(Token.BLOCK);
unwind.setLineColumnNumber(node.getLineno(), node.getColumn());
}
unwindBlock.addChildToBack(unwind);
}
Expand Down Expand Up @@ -297,7 +298,8 @@ private void transformCompilationUnit_r(
// to a LETEXPR
if (n.getType() != Token.LETEXPR) throw Kit.codeBug();
}
Node pop = new Node(Token.EXPR_VOID, n, node.getLineno());
Node pop = new Node(Token.EXPR_VOID, n);
pop.setLineColumnNumber(node.getLineno(), node.getColumn());
result.addChildToBack(pop);
}
node = replaceCurrent(parent, previous, node, result);
Expand Down
Loading