01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
11:
12: import org.eclipse.jdt.internal.compiler.ASTVisitor;
13: import org.eclipse.jdt.internal.compiler.codegen.*;
14: import org.eclipse.jdt.internal.compiler.lookup.*;
15:
16: public class PostfixExpression extends CompoundAssignment {
17:
18: public PostfixExpression(Expression lhs, Expression expression,
19: int operator, int pos) {
20: super (lhs, expression, operator, pos);
21: this .sourceStart = lhs.sourceStart;
22: this .sourceEnd = pos;
23: }
24:
25: /**
26: * Code generation for PostfixExpression
27: *
28: * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
29: * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
30: * @param valueRequired boolean
31: */
32: public void generateCode(BlockScope currentScope,
33: CodeStream codeStream, boolean valueRequired) {
34: // various scenarii are possible, setting an array reference,
35: // a field reference, a blank final field reference, a field of an enclosing instance or
36: // just a local variable.
37:
38: int pc = codeStream.position;
39: ((Reference) this .lhs).generatePostIncrement(currentScope,
40: codeStream, this , valueRequired);
41: if (valueRequired) {
42: codeStream
43: .generateImplicitConversion(this .implicitConversion);
44: }
45: codeStream.recordPositionsFrom(pc, this .sourceStart);
46: }
47:
48: public String operatorToString() {
49: switch (this .operator) {
50: case PLUS:
51: return "++"; //$NON-NLS-1$
52: case MINUS:
53: return "--"; //$NON-NLS-1$
54: }
55: return "unknown operator"; //$NON-NLS-1$
56: }
57:
58: public StringBuffer printExpressionNoParenthesis(int indent,
59: StringBuffer output) {
60: return this .lhs.printExpression(indent, output).append(' ')
61: .append(operatorToString());
62: }
63:
64: public boolean restrainUsageToNumericTypes() {
65: return true;
66: }
67:
68: public void traverse(ASTVisitor visitor, BlockScope scope) {
69:
70: if (visitor.visit(this, scope)) {
71: this.lhs.traverse(visitor, scope);
72: }
73: visitor.endVisit(this, scope);
74: }
75: }
|