1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
20 public class QualifiedThisReference extends ThisReference {
22 public TypeReference qualification;
24 ReferenceBinding currentCompatibleType;
26 public QualifiedThisReference(TypeReference name, int sourceStart,
28 super(sourceStart, sourceEnd);
30 this.sourceStart = name.sourceStart;
33 public FlowInfo analyseCode(BlockScope currentScope,
34 FlowContext flowContext, FlowInfo flowInfo) {
39 public FlowInfo analyseCode(BlockScope currentScope,
40 FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
46 * Code generation for QualifiedThisReference
49 * net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
51 * net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
52 * @param valueRequired
55 // public void generateCode(
56 // BlockScope currentScope,
57 // CodeStream codeStream,
58 // boolean valueRequired) {
60 // int pc = codeStream.position;
61 // if (valueRequired) {
62 // if ((bits & DepthMASK) != 0) {
63 // Object[] emulationPath =
64 // currentScope.getEmulationPath(this.currentCompatibleType, true /*only
65 // exact match*/, false/*consider enclosing arg*/);
66 // codeStream.generateOuterAccess(emulationPath, this,
67 // this.currentCompatibleType, currentScope);
69 // // nothing particular after all
70 // codeStream.aload_0();
73 // codeStream.recordPositionsFrom(pc, this.sourceStart);
75 public TypeBinding resolveType(BlockScope scope) {
77 constant = NotAConstant;
78 this.resolvedType = qualification.resolveType(scope);
79 if (this.resolvedType == null)
82 // the qualification MUST exactly match some enclosing type name
83 // Its possible to qualify 'this' by the name of the current class
85 this.currentCompatibleType = scope.referenceType().binding;
86 while (this.currentCompatibleType != null
87 && this.currentCompatibleType != this.resolvedType) {
89 this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null
90 : this.currentCompatibleType.enclosingType();
92 bits &= ~DepthMASK; // flush previous depth if any
93 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
95 if (this.currentCompatibleType == null) {
96 scope.problemReporter().noSuchEnclosingInstance(this.resolvedType,
98 return this.resolvedType;
101 // Ensure one cannot write code like: B() { super(B.this); }
103 checkAccess(scope.methodScope());
104 } // if depth>0, path emulation will diagnose bad scenarii
105 return this.resolvedType;
108 public String toStringExpression() {
110 return qualification.toString(0) + ".this"; //$NON-NLS-1$
113 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
115 if (visitor.visit(this, blockScope)) {
116 qualification.traverse(visitor, blockScope);
118 visitor.endVisit(this, blockScope);