Makefile fixup
[org.ibex.tool.git] / repo / org.ibex.tool / src / org / eclipse / jdt / internal / compiler / ast / QualifiedThisReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.*;
15 import org.eclipse.jdt.internal.compiler.flow.*;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
17
18 public class QualifiedThisReference extends ThisReference {
19         
20         public TypeReference qualification;
21         ReferenceBinding currentCompatibleType;
22         
23         public QualifiedThisReference(TypeReference name, int sourceStart, int sourceEnd) {
24                 super(sourceStart, sourceEnd);
25                 qualification = name;
26                 this.sourceStart = name.sourceStart;
27         }
28
29         public FlowInfo analyseCode(
30                 BlockScope currentScope,
31                 FlowContext flowContext,
32                 FlowInfo flowInfo) {
33
34                 return flowInfo;
35         }
36
37         public FlowInfo analyseCode(
38                 BlockScope currentScope,
39                 FlowContext flowContext,
40                 FlowInfo flowInfo,
41                 boolean valueRequired) {
42
43                 return flowInfo;
44         }
45
46         /**
47          * Code generation for QualifiedThisReference
48          *
49          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
50          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
51          * @param valueRequired boolean
52          */
53         public void generateCode(
54                 BlockScope currentScope,
55                 CodeStream codeStream,
56                 boolean valueRequired) {
57
58                 int pc = codeStream.position;
59                 if (valueRequired) {
60                         if ((bits & DepthMASK) != 0) {
61                                 Object[] emulationPath =
62                                         currentScope.getEmulationPath(this.currentCompatibleType, true /*only exact match*/, false/*consider enclosing arg*/);
63                                 codeStream.generateOuterAccess(emulationPath, this, this.currentCompatibleType, currentScope);
64                         } else {
65                                 // nothing particular after all
66                                 codeStream.aload_0();
67                         }
68                 }
69                 codeStream.recordPositionsFrom(pc, this.sourceStart);
70         }
71
72         public TypeBinding resolveType(BlockScope scope) {
73
74                 constant = NotAConstant;
75                 this.resolvedType = this.qualification.resolveType(scope);
76                 if (this.resolvedType == null) return null;
77
78                 // the qualification MUST exactly match some enclosing type name
79                 // Its possible to qualify 'this' by the name of the current class
80                 int depth = 0;
81                 this.currentCompatibleType = scope.referenceType().binding;
82                 while (this.currentCompatibleType != null
83                         && this.currentCompatibleType != this.resolvedType) {
84                         depth++;
85                         this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null : this.currentCompatibleType.enclosingType();
86                 }
87                 bits &= ~DepthMASK; // flush previous depth if any                      
88                 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
89
90                 if (this.currentCompatibleType == null) {
91                         scope.problemReporter().noSuchEnclosingInstance(this.resolvedType, this, false);
92                         return this.resolvedType;
93                 }
94
95                 // Ensure one cannot write code like: B() { super(B.this); }
96                 if (depth == 0) {
97                         checkAccess(scope.methodScope());
98                 } // if depth>0, path emulation will diagnose bad scenarii
99                 return this.resolvedType;
100         }
101
102         public StringBuffer printExpression(int indent, StringBuffer output) {
103
104                 return qualification.print(0, output).append(".this"); //$NON-NLS-1$
105         }
106
107         public void traverse(
108                 ASTVisitor visitor,
109                 BlockScope blockScope) {
110
111                 if (visitor.visit(this, blockScope)) {
112                         qualification.traverse(visitor, blockScope);
113                 }
114                 visitor.endVisit(this, blockScope);
115         }
116 }