Skip to content

Commit

Permalink
Use 'grandparent' instead of 'gramps'
Browse files Browse the repository at this point in the history
Created with:

   replace_string ramps randparent

Dropped the leading 'g' so I don't have to deal with case.

See http://geekfeminism.wikia.com/wiki/Nonsexist_language

Same idea as cl/84045417 (a2c0068)
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=99516865
  • Loading branch information
tbreisacher authored and blickly committed Jul 31, 2015
1 parent 3c07f2f commit be020b8
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 84 deletions.
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/CallGraph.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ private void updateFunctionForUse(Function function, Node useNode) {
// but we have to check for using them in .call and .apply. // but we have to check for using them in .call and .apply.


if (useParent.isGetProp()) { if (useParent.isGetProp()) {
Node gramps = useParent.getParent(); Node grandparent = useParent.getParent();
if (NodeUtil.isFunctionObjectApply(gramps) || if (NodeUtil.isFunctionObjectApply(grandparent) ||
NodeUtil.isFunctionObjectCall(gramps)) { NodeUtil.isFunctionObjectCall(grandparent)) {
function.isExposedToCallOrApply = true; function.isExposedToCallOrApply = true;
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/CheckGlobalThis.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
} }


// Don't traverse functions that are getting lent to a prototype. // Don't traverse functions that are getting lent to a prototype.
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
if (NodeUtil.isObjectLitKey(parent)) { if (NodeUtil.isObjectLitKey(parent)) {
JSDocInfo maybeLends = gramps.getJSDocInfo(); JSDocInfo maybeLends = grandparent.getJSDocInfo();
if (maybeLends != null && if (maybeLends != null &&
maybeLends.getLendsName() != null && maybeLends.getLendsName() != null &&
maybeLends.getLendsName().endsWith(".prototype")) { maybeLends.getLendsName().endsWith(".prototype")) {
Expand Down
34 changes: 17 additions & 17 deletions src/com/google/javascript/jscomp/CollapseProperties.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ private void flattenSimpleStubDeclaration(Name name, String alias) {


Preconditions.checkState(ref.node.getParent().isExprResult()); Preconditions.checkState(ref.node.getParent().isExprResult());
Node parent = ref.node.getParent(); Node parent = ref.node.getParent();
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
gramps.replaceChild(parent, varNode); grandparent.replaceChild(parent, varNode);
compiler.reportCodeChange(); compiler.reportCodeChange();
} }


Expand Down Expand Up @@ -737,19 +737,19 @@ private void collapseDeclarationOfNameAndDescendants(Name n, String alias) {
private void updateSimpleDeclaration(String alias, Name refName, Ref ref) { private void updateSimpleDeclaration(String alias, Name refName, Ref ref) {
Node rvalue = ref.node.getNext(); Node rvalue = ref.node.getNext();
Node parent = ref.node.getParent(); Node parent = ref.node.getParent();
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
Node greatGramps = gramps.getParent(); Node greatGrandparent = grandparent.getParent();


if (rvalue != null && rvalue.isFunction()) { if (rvalue != null && rvalue.isFunction()) {
checkForHosedThisReferences(rvalue, refName.docInfo, refName); checkForHosedThisReferences(rvalue, refName.docInfo, refName);
} }


// Create the new alias node. // Create the new alias node.
Node nameNode = NodeUtil.newName(compiler, alias, gramps.getFirstChild(), Node nameNode = NodeUtil.newName(compiler, alias, grandparent.getFirstChild(),
refName.getFullName()); refName.getFullName());
NodeUtil.copyNameAnnotations(ref.node.getLastChild(), nameNode); NodeUtil.copyNameAnnotations(ref.node.getLastChild(), nameNode);


if (gramps.isExprResult()) { if (grandparent.isExprResult()) {
// BEFORE: a.b.c = ...; // BEFORE: a.b.c = ...;
// exprstmt // exprstmt
// assign // assign
Expand All @@ -769,7 +769,7 @@ private void updateSimpleDeclaration(String alias, Name refName, Ref ref) {
nameNode.addChildToFront(rvalue); nameNode.addChildToFront(rvalue);


Node varNode = IR.var(nameNode); Node varNode = IR.var(nameNode);
greatGramps.replaceChild(gramps, varNode); greatGrandparent.replaceChild(grandparent, varNode);
} else { } else {
// This must be a complex assignment. // This must be a complex assignment.
Preconditions.checkNotNull(ref.getTwin()); Preconditions.checkNotNull(ref.getTwin());
Expand All @@ -781,8 +781,8 @@ private void updateSimpleDeclaration(String alias, Name refName, Ref ref) {
// var x$y; // var x$y;
// ... (x$y = 3); // ... (x$y = 3);


Node current = gramps; Node current = grandparent;
Node currentParent = gramps.getParent(); Node currentParent = grandparent.getParent();
for (; !currentParent.isScript() && for (; !currentParent.isScript() &&
!currentParent.isBlock(); !currentParent.isBlock();
current = currentParent, current = currentParent,
Expand Down Expand Up @@ -866,13 +866,13 @@ private void updateObjLitOrFunctionDeclarationAtAssignNode(
Node rvalue = ref.node.getNext(); Node rvalue = ref.node.getNext();
Node varNode = new Node(Token.VAR); Node varNode = new Node(Token.VAR);
Node varParent = ref.node.getAncestor(3); Node varParent = ref.node.getAncestor(3);
Node gramps = ref.node.getAncestor(2); Node grandparent = ref.node.getAncestor(2);
boolean isObjLit = rvalue.isObjectLit(); boolean isObjLit = rvalue.isObjectLit();
boolean insertedVarNode = false; boolean insertedVarNode = false;


if (isObjLit && n.canEliminate()) { if (isObjLit && n.canEliminate()) {
// Eliminate the object literal altogether. // Eliminate the object literal altogether.
varParent.replaceChild(gramps, varNode); varParent.replaceChild(grandparent, varNode);
ref.node = null; ref.node = null;
insertedVarNode = true; insertedVarNode = true;


Expand All @@ -898,7 +898,7 @@ private void updateObjLitOrFunctionDeclarationAtAssignNode(
} }
varNode.addChildToBack(nameNode); varNode.addChildToBack(nameNode);
nameNode.addChildToFront(rvalue); nameNode.addChildToFront(rvalue);
varParent.replaceChild(gramps, varNode); varParent.replaceChild(grandparent, varNode);


// Update the node ancestry stored in the reference. // Update the node ancestry stored in the reference.
ref.node = nameNode; ref.node = nameNode;
Expand Down Expand Up @@ -963,23 +963,23 @@ private void updateObjLitOrFunctionDeclarationAtVarNode(
String name = ref.node.getString(); String name = ref.node.getString();
Node rvalue = ref.node.getFirstChild(); Node rvalue = ref.node.getFirstChild();
Node varNode = ref.node.getParent(); Node varNode = ref.node.getParent();
Node gramps = varNode.getParent(); Node grandparent = varNode.getParent();


boolean isObjLit = rvalue.isObjectLit(); boolean isObjLit = rvalue.isObjectLit();
int numChanges = 0; int numChanges = 0;


if (isObjLit) { if (isObjLit) {
numChanges += declareVarsForObjLitValues( numChanges += declareVarsForObjLitValues(
n, name, rvalue, varNode, gramps.getChildBefore(varNode), n, name, rvalue, varNode, grandparent.getChildBefore(varNode),
gramps); grandparent);
} }


numChanges += addStubsForUndeclaredProperties(n, name, gramps, varNode); numChanges += addStubsForUndeclaredProperties(n, name, grandparent, varNode);


if (isObjLit && n.canEliminate()) { if (isObjLit && n.canEliminate()) {
varNode.removeChild(ref.node); varNode.removeChild(ref.node);
if (!varNode.hasChildren()) { if (!varNode.hasChildren()) {
gramps.removeChild(varNode); grandparent.removeChild(varNode);
} }
numChanges++; numChanges++;


Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/CrossModuleCodeMotion.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private boolean maybeProcessDeclaration(
ReferenceCollectingCallback collector, Reference ref, NamedInfo info) { ReferenceCollectingCallback collector, Reference ref, NamedInfo info) {
Node name = ref.getNode(); Node name = ref.getNode();
Node parent = name.getParent(); Node parent = name.getParent();
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
switch (parent.getType()) { switch (parent.getType()) {
case Token.VAR: case Token.VAR:
if (canMoveValue(collector, ref.getScope(), name.getFirstChild())) { if (canMoveValue(collector, ref.getScope(), name.getFirstChild())) {
Expand Down Expand Up @@ -411,7 +411,7 @@ private boolean maybeProcessDeclaration(
return false; return false;


case Token.CALL: case Token.CALL:
if (NodeUtil.isExprCall(gramps)) { if (NodeUtil.isExprCall(grandparent)) {
SubclassRelationship relationship = SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(parent); compiler.getCodingConvention().getClassesDefinedByCall(parent);
if (relationship != null && if (relationship != null &&
Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/ExpressionDecomposer.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ private Node extractConditional(
// Only conditionals that are the direct child of an expression statement // Only conditionals that are the direct child of an expression statement
// don't need results, for those simply replace the expression statement. // don't need results, for those simply replace the expression statement.
Preconditions.checkArgument(parent.isExprResult()); Preconditions.checkArgument(parent.isExprResult());
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
gramps.replaceChild(parent, ifNode); grandparent.replaceChild(parent, ifNode);
} }


return ifNode; return ifNode;
Expand Down
30 changes: 15 additions & 15 deletions src/com/google/javascript/jscomp/GlobalNamespace.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ public void collect(JSModule module, Scope scope, Node n) {
case Token.GETPROP: case Token.GETPROP:
return; return;
case Token.FUNCTION: case Token.FUNCTION:
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
if (gramps == null || NodeUtil.isFunctionExpression(parent)) { if (grandparent == null || NodeUtil.isFunctionExpression(parent)) {
return; return;
} }
isSet = true; isSet = true;
Expand Down Expand Up @@ -461,40 +461,40 @@ String getNameForObjLitKey(Node n) {
Node parent = n.getParent(); Node parent = n.getParent();
Preconditions.checkState(parent.isObjectLit()); Preconditions.checkState(parent.isObjectLit());


Node gramps = parent.getParent(); Node grandparent = parent.getParent();
if (gramps == null) { if (grandparent == null) {
return null; return null;
} }


Node greatGramps = gramps.getParent(); Node greatGrandparent = grandparent.getParent();
String name; String name;
switch (gramps.getType()) { switch (grandparent.getType()) {
case Token.NAME: case Token.NAME:
// VAR // VAR
// NAME (gramps) // NAME (grandparent)
// OBJLIT (parent) // OBJLIT (parent)
// STRING (n) // STRING (n)
if (greatGramps == null || !NodeUtil.isNameDeclaration(greatGramps)) { if (greatGrandparent == null || !NodeUtil.isNameDeclaration(greatGrandparent)) {
return null; return null;
} }
name = gramps.getString(); name = grandparent.getString();
break; break;
case Token.ASSIGN: case Token.ASSIGN:
// ASSIGN (gramps) // ASSIGN (grandparent)
// NAME|GETPROP // NAME|GETPROP
// OBJLIT (parent) // OBJLIT (parent)
// STRING (n) // STRING (n)
Node lvalue = gramps.getFirstChild(); Node lvalue = grandparent.getFirstChild();
name = lvalue.getQualifiedName(); name = lvalue.getQualifiedName();
break; break;
case Token.STRING_KEY: case Token.STRING_KEY:
// OBJLIT // OBJLIT
// STRING (gramps) // STRING (grandparent)
// OBJLIT (parent) // OBJLIT (parent)
// STRING (n) // STRING (n)
if (greatGramps != null && if (greatGrandparent != null &&
greatGramps.isObjectLit()) { greatGrandparent.isObjectLit()) {
name = getNameForObjLitKey(gramps); name = getNameForObjLitKey(grandparent);
} else { } else {
return null; return null;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/InferJSDocInfo.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
// /** ... */ x = function () { ... } // /** ... */ x = function () { ... }
// 3) A NAME parent. // 3) A NAME parent.
// var x, /** ... */ y = function() { ... } // var x, /** ... */ y = function() { ... }
// 4) A VAR gramps. // 4) A VAR grandparent.
// /** ... */ var x = function() { ... } // /** ... */ var x = function() { ... }
docInfo = n.getJSDocInfo(); docInfo = n.getJSDocInfo();
if (docInfo == null && if (docInfo == null &&
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/InlineFunctions.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ static boolean isCandidateUsage(Node name) {
&& name == parent.getFirstChild() && name == parent.getFirstChild()
&& name.getNext().isString() && name.getNext().isString()
&& name.getNext().getString().equals("call")) { && name.getNext().getString().equals("call")) {
Node gramps = name.getAncestor(2); Node grandparent = name.getAncestor(2);
if (gramps.isCall() if (grandparent.isCall()
&& gramps.getFirstChild() == parent) { && grandparent.getFirstChild() == parent) {
// Yep, a ".call". // Yep, a ".call".
return true; return true;
} }
Expand Down
10 changes: 5 additions & 5 deletions src/com/google/javascript/jscomp/InlineObjectLiterals.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -158,22 +158,22 @@ private boolean isInlinableObject(List<Reference> refs) {
for (Reference ref : refs) { for (Reference ref : refs) {
Node name = ref.getNode(); Node name = ref.getNode();
Node parent = ref.getParent(); Node parent = ref.getParent();
Node gramps = ref.getGrandparent(); Node grandparent = ref.getGrandparent();


// Ignore most indirect references, like x.y (but not x.y(), // Ignore most indirect references, like x.y (but not x.y(),
// since the function referenced by y might reference 'this'). // since the function referenced by y might reference 'this').
// //
if (parent.isGetProp()) { if (parent.isGetProp()) {
Preconditions.checkState(parent.getFirstChild() == name); Preconditions.checkState(parent.getFirstChild() == name);
// A call target may be using the object as a 'this' value. // A call target may be using the object as a 'this' value.
if (gramps.isCall() if (grandparent.isCall()
&& gramps.getFirstChild() == parent) { && grandparent.getFirstChild() == parent) {
return false; return false;
} }


// Deleting a property has different semantics from deleting // Deleting a property has different semantics from deleting
// a variable, so deleted properties should not be inlined. // a variable, so deleted properties should not be inlined.
if (gramps.isDelProp()) { if (grandparent.isDelProp()) {
return false; return false;
} }


Expand All @@ -187,7 +187,7 @@ private boolean isInlinableObject(List<Reference> refs) {
// isn't a perfect algorithm, but it should catch most cases. // isn't a perfect algorithm, but it should catch most cases.
String propName = parent.getLastChild().getString(); String propName = parent.getLastChild().getString();
if (!validProperties.contains(propName)) { if (!validProperties.contains(propName)) {
if (NodeUtil.isVarOrSimpleAssignLhs(parent, gramps)) { if (NodeUtil.isVarOrSimpleAssignLhs(parent, grandparent)) {
validProperties.add(propName); validProperties.add(propName);
} else { } else {
return false; return false;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void process(Node externs, Node root) {


@Override @Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
Node gramps = n.getAncestor(2); Node grandparent = n.getAncestor(2);
return gramps == null || !gramps.isScript(); return grandparent == null || !grandparent.isScript();
} }


@Override @Override
Expand Down
14 changes: 7 additions & 7 deletions src/com/google/javascript/jscomp/NameAnalyzer.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ private class PrototypeSetNode extends JsNameRefNode {
} }


@Override public void remove() { @Override public void remove() {
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
if (gramps.isExprResult()) { if (grandparent.isExprResult()) {
// name.prototype.foo = function() { ... }; // name.prototype.foo = function() { ... };
changeProxy.removeChild(gramps.getParent(), gramps); changeProxy.removeChild(grandparent.getParent(), grandparent);
} else { } else {
// ... name.prototype.foo = function() { ... } ... // ... name.prototype.foo = function() { ... } ...
changeProxy.replaceWith(gramps, parent, changeProxy.replaceWith(grandparent, parent,
parent.getLastChild().detachFromParent()); parent.getLastChild().detachFromParent());
} }
} }
Expand Down Expand Up @@ -378,7 +378,7 @@ Node getParent() {
return node.getParent(); return node.getParent();
} }


Node getGramps() { Node getGrandparent() {
return node.getParent() == null ? null : node.getParent().getParent(); return node.getParent() == null ? null : node.getParent().getParent();
} }
} }
Expand Down Expand Up @@ -406,7 +406,7 @@ public void remove() {
Preconditions.checkState(node.isCall()); Preconditions.checkState(node.isCall());
Node parent = getParent(); Node parent = getParent();
if (parent.isExprResult()) { if (parent.isExprResult()) {
changeProxy.removeChild(getGramps(), parent); changeProxy.removeChild(getGrandparent(), parent);
} else { } else {
changeProxy.replaceWith(parent, node, IR.voidNode(IR.number(0))); changeProxy.replaceWith(parent, node, IR.voidNode(IR.number(0)));
} }
Expand All @@ -433,7 +433,7 @@ private class InstanceOfCheckNode extends SpecialReferenceNode {


@Override @Override
public void remove() { public void remove() {
changeProxy.replaceWith(getGramps(), getParent(), IR.falseNode()); changeProxy.replaceWith(getGrandparent(), getParent(), IR.falseNode());
} }
} }


Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/NodeUtil.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3780,9 +3780,9 @@ static boolean isExpressionResultUsed(Node expr) {
case Token.OR: case Token.OR:
return (expr == parent.getFirstChild()) || isExpressionResultUsed(parent); return (expr == parent.getFirstChild()) || isExpressionResultUsed(parent);
case Token.COMMA: case Token.COMMA:
Node gramps = parent.getParent(); Node grandparent = parent.getParent();
if (gramps.isCall() && if (grandparent.isCall() &&
parent == gramps.getFirstChild()) { parent == grandparent.getFirstChild()) {
// Semantically, a direct call to eval is different from an indirect // Semantically, a direct call to eval is different from an indirect
// call to an eval. See ECMA-262 S15.1.2.1. So it's OK for the first // call to an eval. See ECMA-262 S15.1.2.1. So it's OK for the first
// expression to a comma to be a no-op if it's used to indirect // expression to a comma to be a no-op if it's used to indirect
Expand Down
14 changes: 7 additions & 7 deletions src/com/google/javascript/jscomp/Normalize.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ public void onRedeclaration(
* the scope creator, as the next node of interest is the parent's * the scope creator, as the next node of interest is the parent's
* next sibling. * next sibling.
*/ */
private void replaceVarWithAssignment(Node n, Node parent, Node gramps) { private void replaceVarWithAssignment(Node n, Node parent, Node grandparent) {
if (n.hasChildren()) { if (n.hasChildren()) {
// The * is being initialize, preserve the new value. // The * is being initialize, preserve the new value.
parent.removeChild(n); parent.removeChild(n);
Expand All @@ -800,19 +800,19 @@ private void replaceVarWithAssignment(Node n, Node parent, Node gramps) {
Node replacement = IR.assign(n, value); Node replacement = IR.assign(n, value);
replacement.setJSDocInfo(parent.getJSDocInfo()); replacement.setJSDocInfo(parent.getJSDocInfo());
replacement.copyInformationFrom(parent); replacement.copyInformationFrom(parent);
gramps.replaceChild(parent, NodeUtil.newExpr(replacement)); grandparent.replaceChild(parent, NodeUtil.newExpr(replacement));
} else { } else {
// It is an empty reference remove it. // It is an empty reference remove it.
if (NodeUtil.isStatementBlock(gramps)) { if (NodeUtil.isStatementBlock(grandparent)) {
gramps.removeChild(parent); grandparent.removeChild(parent);
} else if (gramps.isFor()) { } else if (grandparent.isFor()) {
// This is the "for (var a in b)..." case. We don't need to worry // This is the "for (var a in b)..." case. We don't need to worry
// about initializers in "for (var a;;)..." as those are moved out // about initializers in "for (var a;;)..." as those are moved out
// as part of the other normalizations. // as part of the other normalizations.
parent.removeChild(n); parent.removeChild(n);
gramps.replaceChild(parent, n); grandparent.replaceChild(parent, n);
} else { } else {
Preconditions.checkState(gramps.isLabel()); Preconditions.checkState(grandparent.isLabel());
// We should never get here. LABELs with a single VAR statement should // We should never get here. LABELs with a single VAR statement should
// already have been normalized to have a BLOCK. // already have been normalized to have a BLOCK.
throw new IllegalStateException("Unexpected LABEL"); throw new IllegalStateException("Unexpected LABEL");
Expand Down
Loading

0 comments on commit be020b8

Please sign in to comment.