Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fcce1a75090defb46489ea92e8a61039d6b294d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM - Initial API and implementation
 * Markus Schorn (Wind River Systems)
 *******************************************************************************/
/*
 * Created on Mar 11, 2005
 */
package org.eclipse.cdt.internal.core.dom.parser.cpp;

import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;

/**
 * @author aniefer
 */
public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope {

	//private ICPPTemplateDefinition primaryDefinition;
	/**
	 * @param physicalNode
	 */
	public CPPTemplateScope(IASTNode physicalNode) {
		super(physicalNode);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope#getTemplateDefinition()
	 */
	public ICPPTemplateDefinition getTemplateDefinition() {
//		if (primaryDefinition == null) {
//			//primaryDefinition = CPPTemplates.getTemplateDefinition(this);
//			ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) getPhysicalNode();
//			IASTDeclaration decl = template.getDeclaration();
//			return new CPPTemplateDefinition(decl);
//		}
//		return primaryDefinition;
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName()
	 */
	public IName getScopeName() {
		ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) getPhysicalNode();
		return CPPTemplates.getTemplateName(template);
	}

	public IScope getParent() {
	    ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) getPhysicalNode();
	    IASTName name = CPPTemplates.getTemplateName(templateDecl);
	    IASTNode p = name != null ? name.getParent() : null;
	    if (p instanceof ICPPASTQualifiedName) {
	        ICPPASTQualifiedName qual = (ICPPASTQualifiedName) p;
	        IASTName[] names = qual.getNames();
	        int i = 0;
			for (; i < names.length; i++) {
				if (names[i] == name)
					break;
			}
			if (i > 0) {
			    try {
					IBinding binding = names[i - 1].resolveBinding();
					if (binding instanceof ICPPClassType) {
						return ((ICPPClassType) binding).getCompositeScope();
					} else if (binding instanceof ICPPNamespace) {
						return ((ICPPNamespace) binding).getNamespaceScope();
					} else if (binding instanceof ICPPInternalUnknown) {
					    return ((ICPPInternalUnknown) binding).getUnknownScope();
					} else if (binding instanceof IProblemBinding) {
						if (binding instanceof ICPPScope)
							return (IScope) binding;
						return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
								names[i - 1].toCharArray());
					}
			    } catch (DOMException e) {
			    	IScope result = e.getProblem();
			    	if (result instanceof ICPPScope) {
			    		return result;
			    	}
			        return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
			        		names[i - 1].toCharArray());
			    }
			} else if (qual.isFullyQualified()) {
			    return qual.getTranslationUnit().getScope();
			}
	    }
	    while (templateDecl.getParent() instanceof ICPPASTTemplateDeclaration)
	    	templateDecl = (ICPPASTTemplateDeclaration) templateDecl.getParent();
	    return CPPVisitor.getContainingScope(templateDecl);
	}
}

Back to the top