Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-08-12 14:50:50 +0000
committerMarkus Schorn2010-08-12 14:50:50 +0000
commit8311576fa8d8fb684fce0231d7922cc8c20964e8 (patch)
tree9bb7a258799bbf02786d27e1eaf53a7c3b9c8f47 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
parent4be5e0c3eb691a8fce22dfe990297af72161c074 (diff)
downloadorg.eclipse.cdt-8311576fa8d8fb684fce0231d7922cc8c20964e8.tar.gz
org.eclipse.cdt-8311576fa8d8fb684fce0231d7922cc8c20964e8.tar.xz
org.eclipse.cdt-8311576fa8d8fb684fce0231d7922cc8c20964e8.zip
Bug 305980: [C++0x] Inline namespaces
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java72
1 files changed, 64 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
index 6ccecac7e23..479d90d1ad5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2010 Wind River Systems, Inc. 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
@@ -48,15 +48,40 @@ import org.eclipse.cdt.internal.core.index.IIndexScope;
* scopes that can be reopened, i.e. namespaces.
*/
public class CPPScopeMapper {
+
+ /**
+ * Used for implicit inline directives for inline namespaces found in the index.
+ */
+ public static final class InlineNamespaceDirective implements ICPPUsingDirective {
+ private final ICPPInternalNamespaceScope fContainer;
+ private final ICPPInternalNamespaceScope fNominated;
+
+ public InlineNamespaceDirective(ICPPInternalNamespaceScope container, ICPPInternalNamespaceScope inline) {
+ fContainer= container;
+ fNominated= inline;
+ }
+ public IScope getContainingScope() {
+ return fContainer;
+ }
+ public ICPPNamespaceScope getNominatedScope() throws DOMException {
+ return fNominated;
+ }
+ public int getPointOfDeclaration() {
+ return 0;
+ }
+ }
+
/**
* Wrapper for namespace-scopes from the index.
*/
- private class NamespaceScopeWrapper implements ICPPNamespaceScope {
+ private class NamespaceScopeWrapper implements ICPPInternalNamespaceScope {
private final ICPPNamespaceScope fScope;
private ArrayList<ICPPUsingDirective> fUsingDirectives;
+ private ICPPNamespaceScope[] fEnclosingNamespaceSet;
public NamespaceScopeWrapper(ICPPNamespaceScope scope) {
fScope= scope;
+ assert fScope instanceof IIndexScope;
}
public EScopeKind getKind() {
@@ -90,19 +115,50 @@ public class CPPScopeMapper {
return fScope.getScopeName();
}
- public void addUsingDirective(ICPPUsingDirective usingDirective) throws DOMException {
- if (fUsingDirectives == null) {
- fUsingDirectives= new ArrayList<ICPPUsingDirective>(1);
- }
+ public void addUsingDirective(ICPPUsingDirective usingDirective) {
+ initUsingDirectives();
fUsingDirectives.add(usingDirective);
}
- public ICPPUsingDirective[] getUsingDirectives() throws DOMException {
+ private void initUsingDirectives() {
if (fUsingDirectives == null) {
- return ICPPUsingDirective.EMPTY_ARRAY;
+ fUsingDirectives= new ArrayList<ICPPUsingDirective>(1);
+ // Insert a using directive for every inline namespace
+ for (ICPPInternalNamespaceScope inline: getInlineNamespaces()) {
+ fUsingDirectives.add(new InlineNamespaceDirective(this, inline));
+ }
}
+ }
+
+ public ICPPUsingDirective[] getUsingDirectives() {
+ initUsingDirectives();
return fUsingDirectives.toArray(new ICPPUsingDirective[fUsingDirectives.size()]);
}
+
+ public ICPPNamespaceScope[] getEnclosingNamespaceSet() {
+ if (fEnclosingNamespaceSet == null)
+ return fEnclosingNamespaceSet= CPPNamespaceScope.computeEnclosingNamespaceSet(this);
+
+ return fEnclosingNamespaceSet;
+ }
+
+ public boolean isInlineNamepace() {
+ IIndexBinding binding = ((IIndexScope) fScope).getScopeBinding();
+ if (binding instanceof ICPPNamespace && ((ICPPNamespace) binding).isInline())
+ return true;
+
+ return false;
+ }
+
+ public ICPPInternalNamespaceScope[] getInlineNamespaces() {
+ // Obtain the inline namespaces from the index and map them to the ast
+ ICPPNamespaceScope[] pre = fScope.getInlineNamespaces();
+ ICPPInternalNamespaceScope[] result= new ICPPInternalNamespaceScope[pre.length];
+ for (int i = 0; i < result.length; i++) {
+ result[i]= (ICPPInternalNamespaceScope) mapToASTScope((IIndexScope) pre[i]);
+ }
+ return result;
+ }
}
/**

Back to the top