Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-05-10 02:35:32 +0000
committerNathan Ridge2017-06-20 06:34:07 +0000
commit8d6cab41e7415bee996e6c354beeb1ae2975ff91 (patch)
treefb520afe1e880804c8d81c5b315199b34d0a7238 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom
parent3e0853ae0c3b9703f8e6e2112829dbc6a8485c4c (diff)
downloadorg.eclipse.cdt-8d6cab41e7415bee996e6c354beeb1ae2975ff91.tar.gz
org.eclipse.cdt-8d6cab41e7415bee996e6c354beeb1ae2975ff91.tar.xz
org.eclipse.cdt-8d6cab41e7415bee996e6c354beeb1ae2975ff91.zip
Bug 516338 - Introduce alias template specializations
We previously modelled alias template specializations as alias template instances, which was conceptually incorrect and problematic for a number of reasons. Change-Id: Ibca8b87bb3d54cd3ae312254a02e8522e446331d
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAliasTemplateSpecialization.java114
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java32
2 files changed, 146 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAliasTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAliasTemplateSpecialization.java
new file mode 100644
index 00000000000..8d3b58859c7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAliasTemplateSpecialization.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Nathan Ridge.
+ * Rapperswil, University of applied sciences.
+ * 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
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.pdom.dom.cpp;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
+import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * PDOM binding for alias template specializations.
+ */
+public class PDOMCPPAliasTemplateSpecialization extends PDOMCPPSpecialization implements ICPPAliasTemplate {
+ private static final int ALIASED_TYPE = PDOMCPPSpecialization.RECORD_SIZE; // TYPE_SIZE
+ private static final int TEMPLATE_PARAMS = ALIASED_TYPE + Database.TYPE_SIZE; // PTR_SIZE
+
+ @SuppressWarnings("hiding")
+ private static final int RECORD_SIZE = TEMPLATE_PARAMS + Database.PTR_SIZE;
+
+ private volatile IPDOMCPPTemplateParameter[] fParameters;
+
+ public PDOMCPPAliasTemplateSpecialization(PDOMCPPLinkage linkage, PDOMNode parent,
+ ICPPAliasTemplate aliasTemplateSpec, IPDOMBinding specialized)
+ throws CoreException, DOMException {
+ super(linkage, parent, (ICPPSpecialization) aliasTemplateSpec, specialized);
+ final ICPPTemplateParameter[] origParams = aliasTemplateSpec.getTemplateParameters();
+ fParameters = PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
+ final Database db = getDB();
+ long rec= PDOMTemplateParameterArray.putArray(db, fParameters);
+ db.putRecPtr(record + TEMPLATE_PARAMS, rec);
+ linkage.new ConfigureAliasTemplateSpecialization(aliasTemplateSpec, this);
+ }
+
+ public PDOMCPPAliasTemplateSpecialization(PDOMCPPLinkage linkage, long record) {
+ super(linkage, record);
+ }
+
+ public void initData(IType aliasedType) {
+ try {
+ getLinkage().storeType(record + ALIASED_TYPE, aliasedType);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
+ @Override
+ protected int getRecordSize() {
+ return RECORD_SIZE;
+ }
+
+ @Override
+ public int getNodeType() {
+ return IIndexCPPBindingConstants.CPP_ALIAS_TEMPLATE_SPECIALIZATION;
+ }
+
+ @Override
+ public boolean isSameType(IType type) {
+ if (type == null) {
+ return false;
+ }
+ return type.isSameType(getType());
+ }
+
+ @Override
+ public IPDOMCPPTemplateParameter[] getTemplateParameters() {
+ if (fParameters == null) {
+ try {
+ Database db = getDB();
+ long rec= db.getRecPtr(record + TEMPLATE_PARAMS);
+ if (rec == 0) {
+ fParameters= IPDOMCPPTemplateParameter.EMPTY_ARRAY;
+ } else {
+ fParameters= PDOMTemplateParameterArray.getArray(this, rec);
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ fParameters = IPDOMCPPTemplateParameter.EMPTY_ARRAY;
+ }
+ }
+ return fParameters;
+ }
+
+ @Override
+ public IType getType() {
+ try {
+ return getLinkage().loadType(record + ALIASED_TYPE);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ return null;
+ }
+ }
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index a61e6691603..8ced0892f45 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -515,6 +515,32 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
+ class ConfigureAliasTemplateSpecialization implements Runnable {
+ private final PDOMCPPAliasTemplateSpecialization fTemplate;
+ private final IPDOMCPPTemplateParameter[] fTemplateParameters;
+ private final ICPPTemplateParameter[] fOriginalTemplateParameters;
+ private final IType fOriginalAliasedType;
+
+ public ConfigureAliasTemplateSpecialization(ICPPAliasTemplate original,
+ PDOMCPPAliasTemplateSpecialization template) throws DOMException {
+ fTemplate = template;
+ fTemplateParameters= template.getTemplateParameters();
+ fOriginalTemplateParameters= original.getTemplateParameters();
+ fOriginalAliasedType= original.getType();
+ postProcesses.add(this);
+ }
+
+ @Override
+ public void run() {
+ for (int i = 0; i < fOriginalTemplateParameters.length; i++) {
+ final IPDOMCPPTemplateParameter tp = fTemplateParameters[i];
+ if (tp != null)
+ tp.configure(fOriginalTemplateParameters[i]);
+ }
+ fTemplate.initData(fOriginalAliasedType);
+ }
+ }
+
class ConfigureInstance implements Runnable {
PDOMCPPSpecialization fInstance;
@@ -933,6 +959,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
result= new PDOMCPPClassTemplateSpecialization(this, parent, (ICPPClassTemplate) special, orig);
} else if (special instanceof ICPPClassType) {
result= new PDOMCPPClassSpecialization(this, parent, (ICPPClassType) special, orig);
+ } else if (special instanceof ICPPAliasTemplate) {
+ result= new PDOMCPPAliasTemplateSpecialization(this, parent, (ICPPAliasTemplate) special, orig);
} else if (special instanceof ITypedef) {
result= new PDOMCPPTypedefSpecialization(this, parent, (ITypedef) special, orig);
} else if (special instanceof ICPPUsingDeclaration) {
@@ -1023,6 +1051,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPP_CLASS_TEMPLATE_SPECIALIZATION;
} else if (binding instanceof ICPPClassType) {
return CPP_CLASS_SPECIALIZATION;
+ } else if (binding instanceof ICPPAliasTemplate) {
+ return CPP_ALIAS_TEMPLATE_SPECIALIZATION;
} else if (binding instanceof ITypedef) {
return CPP_TYPEDEF_SPECIALIZATION;
}
@@ -1329,6 +1359,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPVariableTemplatePartialSpecialization(this, record);
case CPP_FIELD_TEMPLATE_PARTIAL_SPECIALIZATION:
return new PDOMCPPFieldTemplatePartialSpecialization(this, record);
+ case CPP_ALIAS_TEMPLATE_SPECIALIZATION:
+ return new PDOMCPPAliasTemplateSpecialization(this, record);
}
assert false : "nodeid= " + nodeType; //$NON-NLS-1$
return null;

Back to the top