Skip to content

Commit

Permalink
Rename FunctionBinding to FunctionElement.
Browse files Browse the repository at this point in the history
	Change on 2016/10/26 by kstanger <kstanger@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137283621
  • Loading branch information
kstanger authored and tomball committed Nov 4, 2016
1 parent 056fc2e commit 8e1d5a1
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 140 deletions.
2 changes: 1 addition & 1 deletion translator/Makefile
Expand Up @@ -273,7 +273,7 @@ JAVA_SOURCES = \
translate/VariableRenamer.java \ translate/VariableRenamer.java \
types/AbstractTypeBinding.java \ types/AbstractTypeBinding.java \
types/ExecutablePair.java \ types/ExecutablePair.java \
types/FunctionBinding.java \ types/FunctionElement.java \
types/GeneratedElement.java \ types/GeneratedElement.java \
types/GeneratedExecutableElement.java \ types/GeneratedExecutableElement.java \
types/GeneratedMethodBinding.java \ types/GeneratedMethodBinding.java \
Expand Down
Expand Up @@ -15,7 +15,7 @@
package com.google.devtools.j2objc.ast; package com.google.devtools.j2objc.ast;


import com.google.devtools.j2objc.jdt.BindingConverter; import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;


import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.ITypeBinding;


Expand All @@ -28,26 +28,26 @@
*/ */
public class FunctionInvocation extends Expression { public class FunctionInvocation extends Expression {


private FunctionBinding functionBinding = null; private FunctionElement functionElement = null;
// The context-specific known type of this expression. // The context-specific known type of this expression.
private TypeMirror typeMirror = null; private TypeMirror typeMirror = null;
private boolean hasRetainedResult = false; private boolean hasRetainedResult = false;
private final ChildList<Expression> arguments = ChildList.create(Expression.class, this); private final ChildList<Expression> arguments = ChildList.create(Expression.class, this);


public FunctionInvocation(FunctionInvocation other) { public FunctionInvocation(FunctionInvocation other) {
super(other); super(other);
functionBinding = other.getFunctionBinding(); functionElement = other.getFunctionElement();
typeMirror = other.getTypeMirror(); typeMirror = other.getTypeMirror();
arguments.copyFrom(other.getArguments()); arguments.copyFrom(other.getArguments());
} }


public FunctionInvocation(FunctionBinding functionBinding, ITypeBinding typeBinding) { public FunctionInvocation(FunctionElement functionElement, ITypeBinding typeBinding) {
this.functionBinding = functionBinding; this.functionElement = functionElement;
this.typeMirror = BindingConverter.getType(typeBinding); this.typeMirror = BindingConverter.getType(typeBinding);
} }


public FunctionInvocation(FunctionBinding functionBinding, TypeMirror typeMirror) { public FunctionInvocation(FunctionElement functionElement, TypeMirror typeMirror) {
this.functionBinding = functionBinding; this.functionElement = functionElement;
this.typeMirror = typeMirror; this.typeMirror = typeMirror;
} }


Expand All @@ -56,12 +56,12 @@ public Kind getKind() {
return Kind.FUNCTION_INVOCATION; return Kind.FUNCTION_INVOCATION;
} }


public FunctionBinding getFunctionBinding() { public FunctionElement getFunctionElement() {
return functionBinding; return functionElement;
} }


public String getName() { public String getName() {
return hasRetainedResult ? functionBinding.getRetainedResultName() : functionBinding.getName(); return hasRetainedResult ? functionElement.getRetainedResultName() : functionElement.getName();
} }


@Override @Override
Expand Down
Expand Up @@ -33,7 +33,7 @@
import com.google.devtools.j2objc.ast.TypeLiteral; import com.google.devtools.j2objc.ast.TypeLiteral;
import com.google.devtools.j2objc.ast.UnitTreeVisitor; import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.jdt.BindingConverter; import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.types.GeneratedTypeBinding; import com.google.devtools.j2objc.types.GeneratedTypeBinding;
import com.google.devtools.j2objc.types.GeneratedVariableBinding; import com.google.devtools.j2objc.types.GeneratedVariableBinding;
import com.google.devtools.j2objc.types.IOSMethodBinding; import com.google.devtools.j2objc.types.IOSMethodBinding;
Expand Down Expand Up @@ -255,9 +255,9 @@ private Expression newArrayAccess(
funcName += "Ref"; funcName += "Ref";
returnType = declaredReturnType = typeEnv.getPointerType(componentType); returnType = declaredReturnType = typeEnv.getPointerType(componentType);
} }
FunctionBinding binding = new FunctionBinding(funcName, declaredReturnType, iosArrayElement); FunctionElement element = new FunctionElement(funcName, declaredReturnType, iosArrayElement)
binding.addParameters(iosArrayElement.asType(), typeEnv.resolveJavaTypeMirror("int")); .addParameters(iosArrayElement.asType(), typeEnv.resolveJavaTypeMirror("int"));
FunctionInvocation invocation = new FunctionInvocation(binding, returnType); FunctionInvocation invocation = new FunctionInvocation(element, returnType);
invocation.addArgument(arrayAccessNode.getArray().copy()); invocation.addArgument(arrayAccessNode.getArray().copy());
invocation.addArgument(arrayAccessNode.getIndex().copy()); invocation.addArgument(arrayAccessNode.getIndex().copy());
if (assignable) { if (assignable) {
Expand All @@ -281,9 +281,9 @@ private FunctionInvocation newArrayAssignment(
} }
TypeElement objArrayType = typeEnv.getObjectArrayElement(); TypeElement objArrayType = typeEnv.getObjectArrayElement();
TypeMirror idType = typeEnv.getIdTypeMirror(); TypeMirror idType = typeEnv.getIdTypeMirror();
FunctionBinding binding = new FunctionBinding(funcName, idType, objArrayType); FunctionElement element = new FunctionElement(funcName, idType, objArrayType)
binding.addParameters(objArrayType.asType(), typeEnv.resolveJavaTypeMirror("int"), idType); .addParameters(objArrayType.asType(), typeEnv.resolveJavaTypeMirror("int"), idType);
FunctionInvocation invocation = new FunctionInvocation(binding, componentType); FunctionInvocation invocation = new FunctionInvocation(element, componentType);
List<Expression> args = invocation.getArguments(); List<Expression> args = invocation.getArguments();
args.add(TreeUtil.remove(arrayAccessNode.getArray())); args.add(TreeUtil.remove(arrayAccessNode.getArray()));
args.add(TreeUtil.remove(arrayAccessNode.getIndex())); args.add(TreeUtil.remove(arrayAccessNode.getIndex()));
Expand Down
Expand Up @@ -46,7 +46,7 @@
import com.google.devtools.j2objc.ast.UnitTreeVisitor; import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.ast.VariableDeclarationFragment; import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.ast.WhileStatement; import com.google.devtools.j2objc.ast.WhileStatement;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.util.ElementUtil; import com.google.devtools.j2objc.util.ElementUtil;
import com.google.devtools.j2objc.util.NameTable; import com.google.devtools.j2objc.util.NameTable;
import com.google.devtools.j2objc.util.TranslationUtil; import com.google.devtools.j2objc.util.TranslationUtil;
Expand Down Expand Up @@ -169,9 +169,9 @@ private void rewriteBoxedAssignment(Assignment node) {
String funcName = "JreBoxed" + getAssignFunctionName(node.getOperator()) String funcName = "JreBoxed" + getAssignFunctionName(node.getOperator())
+ TranslationUtil.getOperatorFunctionModifier(lhs) + TranslationUtil.getOperatorFunctionModifier(lhs)
+ NameTable.capitalize(primitiveType.toString()); + NameTable.capitalize(primitiveType.toString());
FunctionBinding binding = new FunctionBinding(funcName, type, TypeUtil.asTypeElement(type)); FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type))
binding.addParameters(pointerType, primitiveType); .addParameters(pointerType, primitiveType);
FunctionInvocation invocation = new FunctionInvocation(binding, type); FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression( invocation.addArgument(new PrefixExpression(
pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs))); pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
invocation.addArgument(TreeUtil.remove(rhs)); invocation.addArgument(TreeUtil.remove(rhs));
Expand Down Expand Up @@ -378,9 +378,9 @@ private void rewriteBoxedPrefixOrPostfix(TreeNode node, Expression operand, Stri
TypeMirror pointerType = typeEnv.getPointerType(type); TypeMirror pointerType = typeEnv.getPointerType(type);
funcName = "JreBoxed" + funcName + TranslationUtil.getOperatorFunctionModifier(operand) funcName = "JreBoxed" + funcName + TranslationUtil.getOperatorFunctionModifier(operand)
+ NameTable.capitalize(typeEnv.getPrimitiveType(type).toString()); + NameTable.capitalize(typeEnv.getPrimitiveType(type).toString());
FunctionBinding binding = new FunctionBinding(funcName, type, TypeUtil.asTypeElement(type)); FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type))
binding.addParameters(pointerType); .addParameters(pointerType);
FunctionInvocation invocation = new FunctionInvocation(binding, type); FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression( invocation.addArgument(new PrefixExpression(
pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(operand))); pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(operand)));
node.replaceWith(invocation); node.replaceWith(invocation);
Expand Down
Expand Up @@ -40,7 +40,7 @@
import com.google.devtools.j2objc.ast.UnitTreeVisitor; import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.ast.VariableDeclarationFragment; import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.jdt.BindingConverter; import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.types.IOSMethodBinding; import com.google.devtools.j2objc.types.IOSMethodBinding;
import com.google.devtools.j2objc.util.BindingUtil; import com.google.devtools.j2objc.util.BindingUtil;
import java.util.ArrayList; import java.util.ArrayList;
Expand Down Expand Up @@ -109,9 +109,9 @@ public void endVisit(CastExpression node) {


private Expression rewriteFloatToIntegralCast( private Expression rewriteFloatToIntegralCast(
ITypeBinding castType, Expression expr, String funcName, ITypeBinding funcReturnType) { ITypeBinding castType, Expression expr, String funcName, ITypeBinding funcReturnType) {
FunctionBinding binding = new FunctionBinding(funcName, funcReturnType, null); FunctionElement element = new FunctionElement(funcName, funcReturnType, null)
binding.addParameters(typeEnv.resolveJavaTypeMirror("double")); .addParameters(typeEnv.resolveJavaTypeMirror("double"));
FunctionInvocation invocation = new FunctionInvocation(binding, funcReturnType); FunctionInvocation invocation = new FunctionInvocation(element, funcReturnType);
invocation.addArgument(TreeUtil.remove(expr)); invocation.addArgument(TreeUtil.remove(expr));
Expression newExpr = invocation; Expression newExpr = invocation;
if (!castType.isEqualTo(funcReturnType)) { if (!castType.isEqualTo(funcReturnType)) {
Expand All @@ -126,15 +126,15 @@ private FunctionInvocation createCastCheck(ITypeBinding type, Expression expr) {
FunctionInvocation invocation = null; FunctionInvocation invocation = null;
if ((type.isInterface() && !type.isAnnotation()) if ((type.isInterface() && !type.isAnnotation())
|| (type.isArray() && !type.getComponentType().isPrimitive())) { || (type.isArray() && !type.getComponentType().isPrimitive())) {
FunctionBinding binding = new FunctionBinding("cast_check", idType, null); FunctionElement element = new FunctionElement("cast_check", idType, null)
binding.addParameters(idType, typeEnv.getIOSClassMirror()); .addParameters(idType, typeEnv.getIOSClassMirror());
invocation = new FunctionInvocation(binding, idType); invocation = new FunctionInvocation(element, idType);
invocation.addArgument(TreeUtil.remove(expr)); invocation.addArgument(TreeUtil.remove(expr));
invocation.addArgument(new TypeLiteral(type, typeEnv)); invocation.addArgument(new TypeLiteral(type, typeEnv));
} else if (type.isClass() || type.isArray() || type.isAnnotation() || type.isEnum()) { } else if (type.isClass() || type.isArray() || type.isAnnotation() || type.isEnum()) {
FunctionBinding binding = new FunctionBinding("cast_chk", idType, null); FunctionElement element = new FunctionElement("cast_chk", idType, null)
binding.addParameters(idType, idType); .addParameters(idType, idType);
invocation = new FunctionInvocation(binding, idType); invocation = new FunctionInvocation(element, idType);
invocation.addArgument(TreeUtil.remove(expr)); invocation.addArgument(TreeUtil.remove(expr));
IOSMethodBinding classBinding = IOSMethodBinding.newMethod( IOSMethodBinding classBinding = IOSMethodBinding.newMethod(
"class", Modifier.STATIC, idType, BindingConverter.getType(type)); "class", Modifier.STATIC, idType, BindingConverter.getType(type));
Expand Down Expand Up @@ -207,7 +207,7 @@ private ITypeBinding getDeclaredType(Expression expr) {
return typeEnv.getIdType(); return typeEnv.getIdType();
case FUNCTION_INVOCATION: case FUNCTION_INVOCATION:
return BindingConverter.unwrapTypeMirrorIntoTypeBinding( return BindingConverter.unwrapTypeMirrorIntoTypeBinding(
((FunctionInvocation) expr).getFunctionBinding().getReturnType()); ((FunctionInvocation) expr).getFunctionElement().getReturnType());
case LAMBDA_EXPRESSION: case LAMBDA_EXPRESSION:
// Lambda expressions are generated as function calls that return "id". // Lambda expressions are generated as function calls that return "id".
return typeEnv.getIdType(); return typeEnv.getIdType();
Expand Down Expand Up @@ -336,7 +336,7 @@ public void endVisit(FieldAccess node) {


@Override @Override
public void endVisit(FunctionInvocation node) { public void endVisit(FunctionInvocation node) {
maybeCastArguments(node.getArguments(), node.getFunctionBinding().getParameterTypes()); maybeCastArguments(node.getArguments(), node.getFunctionElement().getParameterTypes());
} }


@Override @Override
Expand Down
Expand Up @@ -34,7 +34,7 @@
import com.google.devtools.j2objc.ast.TypeDeclaration; import com.google.devtools.j2objc.ast.TypeDeclaration;
import com.google.devtools.j2objc.ast.UnitTreeVisitor; import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.types.ExecutablePair; import com.google.devtools.j2objc.types.ExecutablePair;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.types.GeneratedExecutableElement; import com.google.devtools.j2objc.types.GeneratedExecutableElement;
import com.google.devtools.j2objc.types.GeneratedVariableElement; import com.google.devtools.j2objc.types.GeneratedVariableElement;
import com.google.devtools.j2objc.util.ElementUtil; import com.google.devtools.j2objc.util.ElementUtil;
Expand Down Expand Up @@ -210,11 +210,12 @@ private void addDefaultMethodShim(String selector, ExecutablePair method) {
// if required. // if required.
TypeElement declaringClass = ElementUtil.getDeclaringClass(method.element()); TypeElement declaringClass = ElementUtil.getDeclaringClass(method.element());
String name = nameTable.getFullFunctionName(method.element()); String name = nameTable.getFullFunctionName(method.element());
FunctionBinding fb = new FunctionBinding( FunctionElement funcElement = new FunctionElement(
name, method.element().getReturnType(), declaringClass); name, method.element().getReturnType(), declaringClass)
fb.addParameters(declaringClass.asType()); .addParameters(declaringClass.asType())
fb.addParameters(((ExecutableType) method.element().asType()).getParameterTypes()); .addParameters(((ExecutableType) method.element().asType()).getParameterTypes());
FunctionInvocation invocation = new FunctionInvocation(fb, method.type().getReturnType()); FunctionInvocation invocation =
new FunctionInvocation(funcElement, method.type().getReturnType());


// All default method implementations require self as the first function call argument. // All default method implementations require self as the first function call argument.
invocation.addArgument(new ThisExpression(typeElem.asType())); invocation.addArgument(new ThisExpression(typeElem.asType()));
Expand Down
Expand Up @@ -37,7 +37,7 @@
import com.google.devtools.j2objc.ast.UnitTreeVisitor; import com.google.devtools.j2objc.ast.UnitTreeVisitor;
import com.google.devtools.j2objc.ast.VariableDeclarationFragment; import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.jdt.BindingConverter; import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.types.GeneratedExecutableElement; import com.google.devtools.j2objc.types.GeneratedExecutableElement;
import com.google.devtools.j2objc.util.BindingUtil; import com.google.devtools.j2objc.util.BindingUtil;
import com.google.devtools.j2objc.util.NameTable; import com.google.devtools.j2objc.util.NameTable;
Expand Down Expand Up @@ -147,13 +147,13 @@ private Statement createRelease(IVariableBinding var) {
} }
ITypeBinding voidType = typeEnv.resolveJavaType("void"); ITypeBinding voidType = typeEnv.resolveJavaType("void");
TypeMirror idType = typeEnv.getIdTypeMirror(); TypeMirror idType = typeEnv.getIdTypeMirror();
FunctionBinding binding = new FunctionBinding(funcName, voidType, null); FunctionElement element = new FunctionElement(funcName, voidType, null);
FunctionInvocation releaseInvocation = new FunctionInvocation(binding, voidType); FunctionInvocation releaseInvocation = new FunctionInvocation(element, voidType);
if (isRetainedWith) { if (isRetainedWith) {
binding.addParameters(idType); element.addParameters(idType);
releaseInvocation.addArgument(new ThisExpression(var.getDeclaringClass())); releaseInvocation.addArgument(new ThisExpression(var.getDeclaringClass()));
} }
binding.addParameters(isVolatile ? typeEnv.getPointerType(idType) : idType); element.addParameters(isVolatile ? typeEnv.getPointerType(idType) : idType);
Expression arg = new SimpleName(var); Expression arg = new SimpleName(var);
if (isVolatile) { if (isVolatile) {
arg = new PrefixExpression( arg = new PrefixExpression(
Expand Down
Expand Up @@ -46,7 +46,7 @@
import com.google.devtools.j2objc.ast.VariableDeclarationFragment; import com.google.devtools.j2objc.ast.VariableDeclarationFragment;
import com.google.devtools.j2objc.ast.VariableDeclarationStatement; import com.google.devtools.j2objc.ast.VariableDeclarationStatement;
import com.google.devtools.j2objc.jdt.BindingConverter; import com.google.devtools.j2objc.jdt.BindingConverter;
import com.google.devtools.j2objc.types.FunctionBinding; import com.google.devtools.j2objc.types.FunctionElement;
import com.google.devtools.j2objc.types.GeneratedMethodBinding; import com.google.devtools.j2objc.types.GeneratedMethodBinding;
import com.google.devtools.j2objc.types.GeneratedTypeBinding; import com.google.devtools.j2objc.types.GeneratedTypeBinding;
import com.google.devtools.j2objc.types.GeneratedVariableBinding; import com.google.devtools.j2objc.types.GeneratedVariableBinding;
Expand Down Expand Up @@ -212,10 +212,10 @@ private void addNonArcInitialization(EnumDeclaration node) {
new NativeExpression("ptr += " + sizeName, voidType)))); new NativeExpression("ptr += " + sizeName, voidType))));
String initName = nameTable.getFullFunctionName( String initName = nameTable.getFullFunctionName(
BindingConverter.getExecutableElement(methodBinding)); BindingConverter.getExecutableElement(methodBinding));
FunctionBinding initBinding = new FunctionBinding(initName, voidType, valueType); FunctionElement initElement = new FunctionElement(initName, voidType, valueType)
initBinding.addParameters(valueType); .addParameters(valueType)
initBinding.addParameters(methodBinding.getParameterTypes()); .addParameters(methodBinding.getParameterTypes());
FunctionInvocation initFunc = new FunctionInvocation(initBinding, type); FunctionInvocation initFunc = new FunctionInvocation(initElement, type);
initFunc.addArgument(new SimpleName(localEnum)); initFunc.addArgument(new SimpleName(localEnum));
TreeUtil.copyList(constant.getArguments(), initFunc.getArguments()); TreeUtil.copyList(constant.getArguments(), initFunc.getArguments());
initFunc.addArgument(new StringLiteral(varBinding.getName(), typeEnv)); initFunc.addArgument(new StringLiteral(varBinding.getName(), typeEnv));
Expand Down

0 comments on commit 8e1d5a1

Please sign in to comment.