use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class EnhancedForRewriter method handleArrayIteration.
private void handleArrayIteration(EnhancedForStatement node) {
Expression expression = node.getExpression();
ArrayType expressionType = (ArrayType) expression.getTypeMirror();
VariableElement loopVariable = node.getParameter().getVariableElement();
TypeMirror componentType = expressionType.getComponentType();
TypeElement iosArrayType = typeUtil.getIosArray(componentType);
TypeMirror bufferType = new PointerType(componentType);
VariableElement arrayVariable = GeneratedVariableElement.newLocalVar("a__", expressionType, null);
VariableElement bufferVariable = GeneratedVariableElement.newLocalVar("b__", bufferType, null).setTypeQualifiers("const*");
VariableElement endVariable = GeneratedVariableElement.newLocalVar("e__", bufferType, null).setTypeQualifiers("const*");
VariableElement bufferField = GeneratedVariableElement.newField("buffer", bufferType, iosArrayType).addModifiers(Modifier.PUBLIC);
VariableElement sizeField = GeneratedVariableElement.newField("size", typeUtil.getInt(), iosArrayType).addModifiers(Modifier.PUBLIC);
VariableDeclarationStatement arrayDecl = new VariableDeclarationStatement(arrayVariable, TreeUtil.remove(expression));
FieldAccess bufferAccess = new FieldAccess(bufferField, new SimpleName(arrayVariable));
VariableDeclarationStatement bufferDecl = new VariableDeclarationStatement(bufferVariable, bufferAccess);
InfixExpression endInit = new InfixExpression(bufferType, InfixExpression.Operator.PLUS, new SimpleName(bufferVariable), new FieldAccess(sizeField, new SimpleName(arrayVariable)));
VariableDeclarationStatement endDecl = new VariableDeclarationStatement(endVariable, endInit);
WhileStatement loop = new WhileStatement();
loop.setExpression(new InfixExpression(typeUtil.getBoolean(), InfixExpression.Operator.LESS, new SimpleName(bufferVariable), new SimpleName(endVariable)));
Block newLoopBody = makeBlock(TreeUtil.remove(node.getBody()));
loop.setBody(newLoopBody);
newLoopBody.addStatement(0, new VariableDeclarationStatement(loopVariable, new PrefixExpression(componentType, PrefixExpression.Operator.DEREFERENCE, new PostfixExpression(bufferVariable, PostfixExpression.Operator.INCREMENT))));
Block block = new Block();
List<Statement> stmts = block.getStatements();
stmts.add(arrayDecl);
stmts.add(bufferDecl);
stmts.add(endDecl);
stmts.add(loop);
replaceLoop(node, block, loop);
}
use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class OperatorRewriter method rewriteRegularAssignment.
private void rewriteRegularAssignment(Assignment node) {
VariableElement var = TreeUtil.getVariableElement(node.getLeftHandSide());
if (var == null) {
return;
}
handleRetainedLocal(var, node.getRightHandSide());
boolean isRetainedWith = ElementUtil.isRetainedWithField(var);
String funcName = getAssignmentFunctionName(node, var, isRetainedWith);
if (funcName == null) {
return;
}
TypeMirror type = node.getTypeMirror();
TypeMirror idType = TypeUtil.ID_TYPE;
TypeMirror declaredType = type.getKind().isPrimitive() ? type : idType;
Expression lhs = node.getLeftHandSide();
FunctionElement element = new FunctionElement(funcName, declaredType, null);
FunctionInvocation invocation = new FunctionInvocation(element, type);
List<Expression> args = invocation.getArguments();
if (isRetainedWith) {
element.addParameters(idType);
args.add(getRetainedWithTarget(node, var));
}
element.addParameters(TypeUtil.ID_PTR_TYPE, idType);
args.add(new PrefixExpression(new PointerType(lhs.getTypeMirror()), PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
args.add(TreeUtil.remove(node.getRightHandSide()));
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class OperatorRewriter method rewriteStringAppend.
private void rewriteStringAppend(Assignment node) {
List<Expression> operands = getStringAppendOperands(node);
Expression lhs = node.getLeftHandSide();
TypeMirror lhsType = lhs.getTypeMirror();
String funcName = "JreStrAppend" + translationUtil.getOperatorFunctionModifier(lhs);
FunctionElement element = new FunctionElement(funcName, TypeUtil.ID_TYPE, null).addParameters(TypeUtil.ID_PTR_TYPE, TypeUtil.NATIVE_CHAR_PTR).setIsVarargs(true);
FunctionInvocation invocation = new FunctionInvocation(element, lhsType);
List<Expression> args = invocation.getArguments();
args.add(new PrefixExpression(new PointerType(lhsType), PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
args.add(getStrcatTypesCString(operands));
args.addAll(operands);
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class Autoboxer method rewriteBoxedAssignment.
private void rewriteBoxedAssignment(Assignment node) {
Expression lhs = node.getLeftHandSide();
Expression rhs = node.getRightHandSide();
TypeMirror type = lhs.getTypeMirror();
TypeMirror primitiveType = typeUtil.unboxedType(type);
if (primitiveType == null) {
return;
}
TypeMirror pointerType = new PointerType(type);
String funcName = "JreBoxed" + getAssignFunctionName(node.getOperator()) + translationUtil.getOperatorFunctionModifier(lhs) + NameTable.capitalize(primitiveType.toString());
FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType, primitiveType);
FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
invocation.addArgument(TreeUtil.remove(rhs));
unbox(rhs);
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class ArrayRewriter method getMultiDimensionMethod.
private ExecutableElement getMultiDimensionMethod(TypeMirror componentType, TypeElement iosArrayType, boolean retainedResult) {
boolean isPrimitive = componentType.getKind().isPrimitive();
String selector = (retainedResult ? "newArray" : "array") + "WithDimensions:lengths:" + (isPrimitive ? "" : "type:");
GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(selector, TypeUtil.IOS_OBJECT_ARRAY.asType(), iosArrayType).addModifiers(Modifier.PUBLIC, Modifier.STATIC);
TypeMirror intType = typeUtil.getInt();
element.addParameter(GeneratedVariableElement.newParameter("dimensions", intType, element));
element.addParameter(GeneratedVariableElement.newParameter("dimensionLengths", new PointerType(intType), element));
if (!isPrimitive) {
element.addParameter(GeneratedVariableElement.newParameter("type", TypeUtil.IOS_CLASS.asType(), element));
}
return element;
}
Aggregations