1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Merge remote-tracking branch 'cdt/master' into sd90

This commit is contained in:
Andrew Gvozdev 2012-12-06 17:11:25 -05:00
commit 1ecb41ebc0
133 changed files with 4571 additions and 1481 deletions

View file

@ -58,6 +58,9 @@ public class AllManagedBuildTests {
TestSuite suite = new TestSuite("Test for org.eclipse.cdt.managedbuild.core.tests");
//$JUnit-BEGIN$
// Preconditions
suite.addTestSuite(Preconditions.class);
// build.core.scannerconfig.tests
suite.addTest(CfgScannerConfigProfileManagerTests.suite());
suite.addTestSuite(GCCSpecsConsoleParserTest.class);

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2012,2012 Andrew Gvozdev 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:
* Andrew Gvozdev - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.tests.suite;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
public class Preconditions extends TestCase {
@Override
protected void setUp() throws Exception {
}
/**
* Many MBS tests run make and gcc and will inspect resulting artifacts of the build.
* Make sure GNU tool-chain is available for the tests.
*/
public void testGnu() {
IPath make = PathUtil.findProgramLocation("make");
assertNotNull("Precodition FAILED - program 'make' is not found in path.", make);
IPath gcc = PathUtil.findProgramLocation("gcc");
assertNotNull("Precodition FAILED - program 'gcc' is not found in path.", gcc);
}
/**
* Generated makefiles will often contain dependency lines for all file extension
* corresponding content types set in preferences. Make sure that this set has not been
* changed when the tests are run.
*/
public void testContentTypes() {
Set<String> fileExts = new TreeSet<String>();
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
Set<String> expectedExts = new TreeSet<String>(Arrays.asList(new String[] {"C", "c", "c++", "cc", "cpp", "cxx"}));
assertEquals("Precodition FAILED - Content Types do not match expected defaults.", expectedExts.toString(), fileExts.toString());
}
}

View file

@ -51,8 +51,8 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
private static final String PROVIDER_ID = "provider.id";
private static final String PROVIDER_NAME = "provider name";
private static final String LANGUAGE_ID = "language.test.id";
private static final String CUSTOM_PARAMETER = "customParameter";
private static final String CUSTOM_PARAMETER_2 = "customParameter2";
private static final String CUSTOM_COMMAND_1 = "echo 1";
private static final String CUSTOM_COMMAND_2 = "echo 2";
private static final String ELEM_TEST = "test";
// those attributes must match that in AbstractBuiltinSpecsDetector
@ -203,7 +203,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
List<String> languages = new ArrayList<String>();
languages.add(LANGUAGE_ID);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER);
properties.put(ATTR_PARAMETER, CUSTOM_COMMAND_1);
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
entries.add(entry);
@ -213,13 +213,13 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
assertEquals(PROVIDER_NAME, provider.getName());
assertEquals(languages, provider.getLanguageScope());
assertEquals(entries, provider.getSettingEntries(null, null, null));
assertEquals(CUSTOM_PARAMETER, provider.getCommand());
assertEquals(CUSTOM_COMMAND_1, provider.getCommand());
assertEquals(false, provider.isConsoleEnabled());
assertEquals(false, provider.isExecuted());
// setters
provider.setCommand(CUSTOM_PARAMETER_2);
assertEquals(CUSTOM_PARAMETER_2, provider.getCommand());
provider.setCommand(CUSTOM_COMMAND_2);
assertEquals(CUSTOM_COMMAND_2, provider.getCommand());
provider.setConsoleEnabled(true);
assertEquals(true, provider.isConsoleEnabled());
@ -259,7 +259,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
// configure provider
Map<String, String> properties = new HashMap<String, String>();
properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER);
properties.put(ATTR_PARAMETER, CUSTOM_COMMAND_1);
provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties);
assertEquals(false, provider.isConsoleEnabled());
provider.setConsoleEnabled(true);

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
/**
* @author bnicolle
*
*/
public class IStructureTests extends IntegratedCModelTest {
/**
@ -229,10 +228,8 @@ public class IStructureTests extends IntegratedCModelTest {
try {
myElementUnion = tu.getElement("testUnion1");
myElementNonUnion = tu.getElement("testStruct1");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElementUnion);
assertTrue(myElementUnion.getElementType() == ICElement.C_UNION);
@ -246,6 +243,7 @@ public class IStructureTests extends IntegratedCModelTest {
assertNotNull(myStructNonUnion);
assertFalse(myStructNonUnion.isUnion());
}
public void testIsStruct() throws CModelException {
ITranslationUnit tu = getTU();
ICElement myElementStruct = null;
@ -253,10 +251,8 @@ public class IStructureTests extends IntegratedCModelTest {
try {
myElementStruct = tu.getElement("testStruct1");
myElementNonStruct = tu.getElement("testClass1");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElementStruct);
assertTrue(myElementStruct.getElementType() == ICElement.C_STRUCT);
@ -278,10 +274,8 @@ public class IStructureTests extends IntegratedCModelTest {
try {
myElementClass = tu.getElement("testClass1");
myElementNonClass = tu.getElement("testStruct1");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElementClass);
assertTrue(myElementClass.getElementType() == ICElement.C_CLASS);
@ -303,10 +297,8 @@ public class IStructureTests extends IntegratedCModelTest {
try {
myElementAbstract = tu.getElement("testClass4Abstract");
myElementNonAbstract = tu.getElement("testClass1");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElementAbstract);
assertTrue(myElementAbstract.getElementType() == ICElement.C_CLASS);
@ -333,10 +325,8 @@ public class IStructureTests extends IntegratedCModelTest {
IStructure myStructDerived = (IStructure) myElementDerived;
assertNotNull(myStructDerived);
myBaseTypes = myStructDerived.getSuperClassesNames();
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
String[] myExpectedBaseTypes = {
@ -372,10 +362,8 @@ public class IStructureTests extends IntegratedCModelTest {
ASTAccessVisibility myAccessControl = myStructDerived.getSuperClassAccess(myBaseTypes[i]);
assertEquals("Failed on " + i, myExpectedAccessControl[i], myAccessControl);
}
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
}
@ -399,10 +387,8 @@ public class IStructureTests extends IntegratedCModelTest {
ICElement myElement = null;
try {
myElement = tu.getElement("testAnonymousStructObject1");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElement);
assertEquals(ICElement.C_VARIABLE, myElement.getElementType());
@ -413,10 +399,8 @@ public class IStructureTests extends IntegratedCModelTest {
ICElement myElement = null;
try {
myElement = tu.getElement("testStruct8");
}
catch( CModelException c )
{
assertNotNull("CModelException thrown",c);
} catch (CModelException e) {
assertNotNull("CModelException thrown", e);
}
assertNotNull(myElement);
IStructure myIStruct = (IStructure) myElement;

View file

@ -8,10 +8,6 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 3, 2003
* by bnicolle
*/
package org.eclipse.cdt.core.model.tests;
import java.io.FileInputStream;
@ -33,18 +29,13 @@ import org.eclipse.core.runtime.Path;
/**
* @author bnicolle
*
*/
public abstract class IntegratedCModelTest extends BaseTestCase {
private ICProject fCProject;
private IFile sourceFile;
private NullProgressMonitor monitor;
private boolean structuralParse = false;
/**
*
*/
public IntegratedCModelTest() {
super();
}
@ -113,5 +104,4 @@ public abstract class IntegratedCModelTest extends BaseTestCase {
public void setStructuralParse(boolean structuralParse) {
this.structuralParse = structuralParse;
}
}

View file

@ -713,19 +713,20 @@ public class AST2BaseTest extends BaseTestCase {
}
private IBinding binding(String section, int len) {
IASTName name = findName(section, len);
IASTName astName = findName(section, len);
final String selection = section.substring(0, len);
assertNotNull("Did not find \"" + selection + "\"", name);
assertEquals(selection, name.getRawSignature());
assertNotNull("No AST name for \"" + selection + "\"", astName);
assertEquals(selection, astName.getRawSignature());
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
IBinding binding = astName.resolveBinding();
assertNotNull("No binding for " + astName.getRawSignature(), binding);
return name.resolveBinding();
return astName.resolveBinding();
}
private IBinding binding(String context, String name) {
IASTName astName = findName(context, name);
assertNotNull("No AST name for \"" + name + "\"", astName);
assertEquals(name, astName.getRawSignature());
IBinding binding = astName.resolveBinding();

View file

@ -8436,13 +8436,20 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE, pt.getID());
}
// auto x = x; // Self referring type.
// auto x = y + z;
// auto y = x;
// auto z = x;
// void test() {
// for (auto a : a) {}
// }
public void testAutoType_305970() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPVariable x= bh.assertNonProblem("x =", 1);
IProblemType pt= (IProblemType) x.getType();
assertEquals(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE, pt.getID());
BindingAssertionHelper bh = getAssertionHelper();
ICPPVariable x= bh.assertNonProblem("x =", 1, ICPPVariable.class);
IProblemType xt= (IProblemType) x.getType();
assertEquals(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE, xt.getID());
ICPPVariable a= bh.assertNonProblem("a :", "a", ICPPVariable.class);
IProblemType at= (IProblemType) a.getType();
assertEquals(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE, at.getID());
}
// struct A { auto a = 1; }; // Auto-typed non-static fields are not allowed.
@ -9951,4 +9958,19 @@ public class AST2CPPTests extends AST2BaseTest {
public void testOrderInAmbiguityResolution_390759() throws Exception {
parseAndCheckBindings();
}
// namespace N {
// enum E { A, B };
// void bar(E);
// }
// struct S {
// void operator()(N::E);
// };
// S bar;
// int main() {
// bar(N::A);
// }
public void testADLForFunctionObject_388287() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -126,6 +126,12 @@ public class AST2TemplateTests extends AST2BaseTest {
return new BindingAssertionHelper(code, true);
}
private CPPNameCollector getCPPNameCollector(IASTTranslationUnit ast) {
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
return collector;
}
public void testBasicClassTemplate() throws Exception {
IASTTranslationUnit tu = parse("template <class T> class A{ T t; };", CPP); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
@ -6211,15 +6217,17 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.x = 42;
// }
public void testSimpleAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPClassType S = (ICPPClassType) collector.getName(0).resolveBinding();
ICPPField x = (ICPPField) collector.getName(1).resolveBinding();
ITypedef Alias = (ITypedef) collector.getName(2).resolveBinding();
IFunction foo = (IFunction) collector.getName(4).resolveBinding();
IVariable myA = (IVariable) collector.getName(6).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPClassType S = assertionHelper.assertNonProblem("struct S {", "S", ICPPClassType.class);
ICPPField x = assertionHelper.assertNonProblem("int x", "x", ICPPField.class);
ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S", "Alias", ITypedef.class);
IFunction foo = assertionHelper.assertNonProblem("void foo() {", "foo", IFunction.class);
IVariable myA = assertionHelper.assertNonProblem("Alias myA", "myA", IVariable.class);
assertInstances(collector, S, 2);
assertInstances(collector, x, 2);
@ -6238,15 +6246,17 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.x = 42;
// }
public void testSpecifiedTemplateAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPClassType S = (ICPPClassType) collector.getName(1).resolveBinding();
ICPPField x = (ICPPField) collector.getName(3).resolveBinding();
ITypedef Alias = (ITypedef) collector.getName(4).resolveBinding();
IVariable myA = (IVariable) collector.getName(9).resolveBinding();
ICPPSpecialization xRef = (ICPPSpecialization) collector.getName(11).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPClassType S = assertionHelper.assertNonProblem("struct S", "S", ICPPClassType.class);
ICPPField x = assertionHelper.assertNonProblem("T x;", "x", ICPPField.class);
ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S<int>;", "Alias", ITypedef.class);
IVariable myA = assertionHelper.assertNonProblem("Alias myA;", "myA", IVariable.class);
ICPPSpecialization xRef = assertionHelper.assertNonProblem("myA.x = 42;", "x", ICPPSpecialization.class);
assertInstances(collector, S, 2);
assertInstances(collector, Alias, 2);
@ -6261,38 +6271,41 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA = 42;
// }
public void testTemplatedAliasBasicType() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPAliasTemplate Alias = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
ICPPAliasTemplateInstance AliasFloatInstance = (ICPPAliasTemplateInstance) collector.getName(3).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPAliasTemplate Alias = assertionHelper.assertNonProblem("using Alias = int;", "Alias", ICPPAliasTemplate.class);
ICPPAliasTemplateInstance aliasFloatInstance = assertionHelper.assertNonProblem("Alias<float> myA;", "Alias<float>", ICPPAliasTemplateInstance.class);
assertInstances(collector, Alias, 2);
assertSameType(AliasFloatInstance, new CPPBasicType(IBasicType.Kind.eInt, 0));
assertSameType(aliasFloatInstance, new CPPBasicType(IBasicType.Kind.eInt, 0));
}
// template<typename T>
// struct S {
// T t;
// };
// template<typename T>
// using TAlias = S<T>;
// template<typename _T>
// using TAlias = S<_T>;
// void foo() {
// TAlias<int> myA;
// myA.t = 42;
// }
public void testTemplatedAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPClassType S = (ICPPClassType) collector.getName(1).resolveBinding();
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
ICPPTemplateParameter T = (ICPPTemplateParameter) collector.getName(4).resolveBinding();
ICPPTemplateParameter TRef = (ICPPTemplateParameter) collector.getName(8).resolveBinding();
ICPPAliasTemplate TAlias = (ICPPAliasTemplate) collector.getName(5).resolveBinding();
ICPPVariable myA = (ICPPVariable) collector.getName(12).resolveBinding();
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(14).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPClassType S = assertionHelper.assertNonProblem("struct S {", "S", ICPPClassType.class);
ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class);
ICPPTemplateParameter T = assertionHelper.assertNonProblem("template<typename _T>", "_T", ICPPTemplateParameter.class);
ICPPTemplateParameter TRef = assertionHelper.assertNonProblem("using TAlias = S<_T>;", "_T", ICPPTemplateParameter.class);
ICPPAliasTemplate TAlias = assertionHelper.assertNonProblem("using TAlias = S<_T>;", "TAlias", ICPPAliasTemplate.class);
ICPPVariable myA = assertionHelper.assertNonProblem("TAlias<int> myA;", "myA", ICPPVariable.class);
ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = 42;", "t", ICPPSpecialization.class);
assertInstances(collector, S, 2);
assertInstances(collector, T, 2);
@ -6319,26 +6332,26 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t3 = true;
// }
public void testTemplatedAliasDeclarationMultipleParameters() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPField t1 = (ICPPField) collector.getName(5).resolveBinding();
ICPPField t2 = (ICPPField) collector.getName(7).resolveBinding();
ICPPField t3 = (ICPPField) collector.getName(9).resolveBinding();
parseAndCheckBindings();
ICPPTemplateParameter P1 = (ICPPTemplateParameter) collector.getName(10).resolveBinding();
ICPPTemplateParameter P2 = (ICPPTemplateParameter) collector.getName(11).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPTemplateParameter P1Ref = (ICPPTemplateParameter) collector.getName(16).resolveBinding();
ICPPTemplateParameter P2Ref = (ICPPTemplateParameter) collector.getName(15).resolveBinding();
ICPPField t1 = assertionHelper.assertNonProblem("T1 t1;", "t1", ICPPField.class);
ICPPField t2 = assertionHelper.assertNonProblem("T2 t2;", "t2", ICPPField.class);
ICPPField t3 = assertionHelper.assertNonProblem("T3 t3;", "t3", ICPPField.class);
ICPPAliasTemplateInstance TAliasInstance = (ICPPAliasTemplateInstance) collector.getName(18).resolveBinding();
ICPPTemplateParameter P1 = assertionHelper.assertNonProblem("template<typename P1, typename P2>", "P1", ICPPTemplateParameter.class);
ICPPTemplateParameter P2 = assertionHelper.assertNonProblem("template<typename P1, typename P2>", "P2", ICPPTemplateParameter.class);
ICPPTemplateParameter P1Ref = assertionHelper.assertNonProblem("using TAlias = S<int, P2, P1>;", "P1", ICPPTemplateParameter.class);
ICPPTemplateParameter P2Ref = assertionHelper.assertNonProblem("using TAlias = S<int, P2, P1>;", "P2", ICPPTemplateParameter.class);
ICPPAliasTemplateInstance TAliasInstance = assertionHelper.assertNonProblem("TAlias<bool, float> myA;", "TAlias<bool, float>", ICPPAliasTemplateInstance.class);
ICPPTemplateInstance aliasedTypeInstance = (ICPPTemplateInstance) TAliasInstance.getType();
ICPPSpecialization t1Ref = (ICPPSpecialization) collector.getName(22).resolveBinding();
ICPPSpecialization t2Ref = (ICPPSpecialization) collector.getName(24).resolveBinding();
ICPPSpecialization t3Ref = (ICPPSpecialization) collector.getName(26).resolveBinding();
ICPPSpecialization t1Ref = assertionHelper.assertNonProblem("myA.t1 = 42;", "t1", ICPPSpecialization.class);
ICPPSpecialization t2Ref = assertionHelper.assertNonProblem("myA.t2 = 42.0f;", "t2", ICPPSpecialization.class);
ICPPSpecialization t3Ref = assertionHelper.assertNonProblem("myA.t3 = true;", "t3", ICPPSpecialization.class);
assertEquals(P1, P1Ref);
assertEquals(P2, P2Ref);
@ -6362,13 +6375,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t = S<int>();
// }
public void testTemplatedAliasDeclarationTemplateArgument() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
IType TAliasSInt = (IType) collector.getName(10).resolveBinding();
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(16).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class);
ICPPAliasTemplateInstance TAliasSInt = assertionHelper.assertNonProblem("TAlias<S<int>> myA;", "TAlias<S<int>>", ICPPAliasTemplateInstance.class);
ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S<int>()", "t", ICPPSpecialization.class);
assertEquals(t, tRef.getSpecializedBinding());
assertSameType(TAliasSInt, (IType)tRef.getOwner());
@ -6385,13 +6398,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t = S<int>();
// }
public void testTemplatedAliasAsTemplateArgument() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
ICPPTemplateInstance STAliasInt = (ICPPTemplateInstance) collector.getName(10).resolveBinding();
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(16).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class);
ICPPTemplateInstance STAliasInt = assertionHelper.assertNonProblem("S<TAlias<int>> myA;", "S<TAlias<int>>", ICPPTemplateInstance.class);
ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S<int>();", "t", ICPPSpecialization.class);
assertEquals(t, tRef.getSpecializedBinding());
assertEquals(STAliasInt, tRef.getOwner());
@ -6408,12 +6421,12 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.buff[0] = 1;
// }
public void testTemplatedAliasDeclarationValueArgument() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPField buff = (ICPPField) collector.getName(3).resolveBinding();
ICPPSpecialization buffRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField buff = assertionHelper.assertNonProblem("int buff [Size];", "buff", ICPPField.class);
ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class);
assertEquals(buff, buffRef.getSpecializedBinding());
assertEquals(buffRef.getTemplateParameterMap().getArgument(0).getNonTypeValue().numericalValue(), new Long(4));
@ -6431,13 +6444,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.buff[0] = 1;
// }
public void testTemplatedAliasDefaultArguments() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPField buff = (ICPPField) collector.getName(4).resolveBinding();
ICPPAliasTemplateInstance myA = (ICPPAliasTemplateInstance) collector.getName(14).resolveBinding();
ICPPSpecialization buffRef = (ICPPSpecialization) collector.getName(18).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField buff = assertionHelper.assertNonProblem("T buff [Size];", "buff", ICPPField.class);
ICPPAliasTemplateInstance myA = assertionHelper.assertNonProblem("TAlias<> myA;", "TAlias<>", ICPPAliasTemplateInstance.class);
ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class);
assertEquals(buff, buffRef.getSpecializedBinding());
assertSameType(buffRef.getTemplateParameterMap().getArgument(0).getTypeValue(), new CPPBasicType(IBasicType.Kind.eInt, 0));
@ -6455,14 +6468,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t = S<int>();
// }
public void testTemplatedAliasTemplateArgument() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
ICPPClassSpecialization Sint = (ICPPClassSpecialization) collector.getName(18).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class);
ICPPSpecialization tRef = assertionHelper.assertNonProblem(" myA.t = S<int>();", "t", ICPPSpecialization.class);
ICPPClassSpecialization Sint = assertionHelper.assertNonProblem("myA.t = S<int>();", "S<int>", ICPPClassSpecialization.class);
assertEquals(t, tRef.getSpecializedBinding());
assertSameType(tRef.getTemplateParameterMap().getArgument(0).getTypeValue(), Sint);
@ -6483,14 +6495,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// bar(myS);
// }
public void testTemplatedAliasAsFunctionParameter() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPFunction bar = (ICPPFunction) collector.getName(9).resolveBinding();
ICPPFunction barRefAlias = (ICPPFunction) collector.getName(17).resolveBinding();
ICPPFunction barRefSInt = (ICPPFunction) collector.getName(22).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPFunction bar = assertionHelper.assertNonProblem("void bar(TAlias<int> arg){", "bar", ICPPFunction.class);
ICPPFunction barRefAlias = assertionHelper.assertNonProblem("bar(myA);", "bar", ICPPFunction.class);
ICPPFunction barRefSInt = assertionHelper.assertNonProblem("bar(myS);", "bar", ICPPFunction.class);
assertEquals(bar, barRefAlias);
assertEquals(bar, barRefSInt);
@ -6509,13 +6520,12 @@ public class AST2TemplateTests extends AST2BaseTest {
// bar(myA);
// }
public void testTemplatedAliasAsFunctionArgument() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPFunction bar = (ICPPFunction) collector.getName(9).resolveBinding();
ICPPFunction barRefAlias = (ICPPFunction) collector.getName(17).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPFunction bar = assertionHelper.assertNonProblem("void bar(S<int> arg){", "bar", ICPPFunction.class);
ICPPFunction barRefAlias = assertionHelper.assertNonProblem("bar(myA);", "bar", ICPPFunction.class);
assertEquals(bar, barRefAlias);
}
@ -6559,13 +6569,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// function f = &foo;
// }
public void testSimpleFunctionAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ITypedef function = (ITypedef) collector.getName(0).resolveBinding();
ICPPFunction foo = (ICPPFunction) collector.getName(2).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ITypedef function = assertionHelper.assertNonProblem("using function = void (&)(int)", "function", ITypedef.class);
ICPPFunction foo = assertionHelper.assertNonProblem("void foo(int)", "foo", ICPPFunction.class);
assertInstances(collector, function, 2);
assertInstances(collector, foo, 2);
@ -6584,12 +6594,12 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t = 42;
// }
public void testTemplatedAliasForTemplateReference() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
ICPPClassSpecialization SInt = (ICPPClassSpecialization) collector.getName(10).resolveBinding();
ICPPAliasTemplateInstance TAliasInt = (ICPPAliasTemplateInstance) collector.getName(13).resolveBinding();
parseAndCheckBindings();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPClassSpecialization SInt = assertionHelper.assertNonProblem("S<int> myS;", "S<int>", ICPPClassSpecialization.class);
ICPPAliasTemplateInstance TAliasInt = assertionHelper.assertNonProblem("TAlias<int> myA = myS;", "TAlias<int>", ICPPAliasTemplateInstance.class);
assertSameType(new CPPReferenceType(SInt, false), TAliasInt);
}
@ -6600,14 +6610,14 @@ public class AST2TemplateTests extends AST2BaseTest {
// function<int> f = &foo;
// }
public void testSimpleFunctionTemplateAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPAliasTemplate function = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
ICPPFunction foo = (ICPPFunction) collector.getName(3).resolveBinding();
ICPPAliasTemplateInstance functionInt = (ICPPAliasTemplateInstance) collector.getName(5).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPAliasTemplate function = assertionHelper.assertNonProblem("using function = void (int)", "function", ICPPAliasTemplate.class);
ICPPFunction foo = assertionHelper.assertNonProblem("void foo(int) {", "foo", ICPPFunction.class);
ICPPAliasTemplateInstance functionInt = assertionHelper.assertNonProblem("function<int> f = &foo;", "function<int>", ICPPAliasTemplateInstance.class);
assertInstances(collector, function, 2);
assertInstances(collector, foo, 2);
@ -6620,14 +6630,14 @@ public class AST2TemplateTests extends AST2BaseTest {
// function<int> f = &foo;
// }
public void testSimpleFunctionReferenceTemplateAliasDeclaration() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPAliasTemplate function = (ICPPAliasTemplate) collector.getName(1).resolveBinding();
ICPPFunction foo = (ICPPFunction) collector.getName(3).resolveBinding();
ICPPAliasTemplateInstance functionInt = (ICPPAliasTemplateInstance) collector.getName(5).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit());
ICPPAliasTemplate function = assertionHelper.assertNonProblem("using function = void (&)(int)", "function", ICPPAliasTemplate.class);
ICPPFunction foo = assertionHelper.assertNonProblem("void foo(int) {", "foo", ICPPFunction.class);
ICPPAliasTemplateInstance functionInt = assertionHelper.assertNonProblem("function<int> f = &foo;", "function<int>", ICPPAliasTemplateInstance.class);
assertInstances(collector, function, 2);
assertInstances(collector, foo, 2);
@ -6645,14 +6655,13 @@ public class AST2TemplateTests extends AST2BaseTest {
// myA.t = S<int>();
// }
public void testTemplatedAliasTemplateParameter() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPField t = (ICPPField) collector.getName(3).resolveBinding();
ICPPSpecialization tRef = (ICPPSpecialization) collector.getName(17).resolveBinding();
ICPPClassSpecialization Sint = (ICPPClassSpecialization) collector.getName(18).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class);
ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S<int>();", "t", ICPPSpecialization.class);
ICPPClassSpecialization Sint = assertionHelper.assertNonProblem("myA.t = S<int>();", "S<int>", ICPPClassSpecialization.class);
assertEquals(t, tRef.getSpecializedBinding());
assertSameType(tRef.getTemplateParameterMap().getArgument(0).getTypeValue(), Sint);
@ -6669,17 +6678,16 @@ public class AST2TemplateTests extends AST2BaseTest {
// using namespace NS;
// Alias<int> intAlias;
public void testAliasDeclarationContext() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit ast = parseAndCheckBindings(code);
CPPNameCollector collector = new CPPNameCollector();
ast.accept(collector);
parseAndCheckBindings();
ICPPAliasTemplateInstance AliasInt = (ICPPAliasTemplateInstance) collector.getName(11).resolveBinding();
BindingAssertionHelper assertionHelper = getAssertionHelper();
ICPPAliasTemplateInstance AliasInt = assertionHelper.assertNonProblem("Alias<int> intAlias;", "Alias<int>", ICPPAliasTemplateInstance.class);
assertEquals("Alias<int>", AliasInt.getName());
assertEquals("NS", AliasInt.getQualifiedName()[0]);
assertEquals("Alias<int>", AliasInt.getQualifiedName()[1]);
ICPPNamespace namespaceNS = (ICPPNamespace) collector.getName(0).resolveBinding();
ICPPNamespace namespaceNS = assertionHelper.assertNonProblem("using namespace NS;", "NS", ICPPNamespace.class);
assertEquals(namespaceNS, AliasInt.getOwner());
assertTrue(AliasInt.getScope() instanceof ICPPTemplateScope);
@ -6726,7 +6734,165 @@ public class AST2TemplateTests extends AST2BaseTest {
// void test(E<A<int>>::type v) {
// f(v);
// }
public void testAliasTemplate_395026() throws Exception {
public void testAliasTemplate_395026_1() throws Exception {
parseAndCheckBindings();
}
// template<typename U>
// struct A {
// template<typename V>
// struct rebind {
// typedef A<V> other;
// };
// };
//
// template<typename T, typename U>
// struct B {
// typedef typename T::template rebind<U>::other type1;
// };
//
// template<typename T>
// struct C {
// template<typename U>
// using rebind2 = typename B<T, U>::type1;
// };
//
// template<typename T>
// struct D : C<T> {
// typedef int* type0;
// template<typename U>
// struct rebind {
// typedef typename C<T>::template rebind2<U> other;
// };
// };
//
// template<typename U>
// struct E {
// typedef typename D<A<U>>::template rebind<U>::other type2;
// typedef typename D<type2>::type0 type;
// type operator[](int n);
// };
//
// void f(int);
//
// void test() {
// E<int*> v;
// f(*v[0]);
// }
public void testAliasTemplate_395026_2() throws Exception {
parseAndCheckBindings();
}
// template<typename U>
// struct A {
// typedef U type1;
//
// template<typename V>
// struct rebind {
// typedef A<V> other;
// };
// };
//
// template<typename T, typename U>
// struct B {
// template<typename T2, typename U2>
// static constexpr bool test(typename T2::template rebind<U2>::other*) {
// return true;
// }
//
// template<typename, typename>
// static constexpr bool test(...) {
// return false;
// }
//
// static const bool value = test<T, U>(nullptr);
// };
//
// template<typename T, typename U, bool = B<T, U>::value>
// struct C;
//
// template<typename T, typename U>
// struct C<T, U, true> {
// typedef typename T::template rebind<U>::other type2;
// };
//
// template<typename T>
// struct D {
// typedef typename T::type1 type3;
//
// template<typename U>
// using rebind2 = typename C<T, U>::type2;
// };
//
// template<typename T>
// struct E : D<T> {
// typedef D<T> Base;
// typedef typename Base::type3& type4;
//
// template<typename U>
// struct rebind {
// typedef typename Base::template rebind2<U> other;
// };
// };
//
// template<typename U, typename T = A<U>>
// struct F {
// typedef typename E<T>::template rebind<U>::other type5;
// typedef typename E<type5>::type4 type6;
// type6 operator[](int n);
// };
//
// void f(int);
//
// void test() {
// F<int*> a;
// f(*a[0]);
// }
public void testConstexprFunction_395238_1() throws Exception {
parseAndCheckBindings();
}
// template<typename T>
// struct A {
// template<typename U>
// static constexpr U test(U v) {
// return v;
// }
//
// template<typename>
// static constexpr bool test(...) {
// return false;
// }
//
// static const bool value = test<T>(true);
// };
//
// template<typename T, bool = A<T>::value>
// struct B;
//
// template<typename T>
// struct B<T, true> {
// typedef T type;
// };
//
// B<bool>::type x;
// B<int*>::type y;
public void testConstexprFunction_395238_2() throws Exception {
BindingAssertionHelper ah = getAssertionHelper();
ITypedef td = ah.assertNonProblem("B<bool>::type", "type", ITypedef.class);
assertEquals("bool", ASTTypeUtil.getType(td.getType()));
ah.assertProblem("B<int*>::type", "type");
}
// struct S {
// typedef int a_type;
// };
// template <typename T, typename = typename T::a_type> int foo(T);
// template <typename T, typename = typename T::b_type> void foo(T);
// int main() {
// foo(S());
// }
public void testSFINAEInDefaultArgument() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -165,24 +165,31 @@ public class VariableReadWriteFlagsTest extends AST2BaseTest {
// };
//
// void test(int a, int b, int c) {
// A(&a, b);
// A x(&a, b);
// A(&a, b, c);
// A y(&a, b, c);
// A u = A(&a, b);
// A* v = new A(&a, b);
// A w(&a, b);
// A x = A(&a, b, c);
// A* y = new A(&a, b, c);
// A z(&a, b, c);
// };
public void testConstructorCall_393068() throws Exception {
AssertionHelper a = getCPPAssertionHelper();
// a.assertReadWriteFlags("A(&a, b)", "a", READ | WRITE);
// a.assertReadWriteFlags("A(&a, b)", "b", READ | WRITE);
// a.assertReadWriteFlags("x(&a, b)", "a", READ | WRITE);
// a.assertReadWriteFlags("x(&a, b)", "b", READ | WRITE);
// a.assertReadWriteFlags("x(&a, b)", "x", WRITE);
a.assertReadWriteFlags("A(&a, b, c)", "a", READ);
a.assertReadWriteFlags("A(&a, b, c)", "b", READ);
a.assertReadWriteFlags("A(&a, b, c)", "c", READ);
a.assertReadWriteFlags("y(&a, b, c)", "a", READ);
a.assertReadWriteFlags("y(&a, b, c)", "b", READ);
a.assertReadWriteFlags("y(&a, b, c)", "c", READ);
a.assertReadWriteFlags("= A(&a, b)", "a", READ | WRITE);
a.assertReadWriteFlags("= A(&a, b)", "b", READ | WRITE);
a.assertReadWriteFlags("new A(&a, b)", "a", READ | WRITE);
a.assertReadWriteFlags("new A(&a, b)", "b", READ | WRITE);
a.assertReadWriteFlags("w(&a, b)", "a", READ | WRITE);
a.assertReadWriteFlags("w(&a, b)", "b", READ | WRITE);
a.assertReadWriteFlags("w(&a, b)", "w", WRITE);
a.assertReadWriteFlags("= A(&a, b, c)", "a", READ);
a.assertReadWriteFlags("= A(&a, b, c)", "b", READ);
a.assertReadWriteFlags("= A(&a, b, c)", "c", READ);
a.assertReadWriteFlags("new A(&a, b, c)", "a", READ);
a.assertReadWriteFlags("new A(&a, b, c)", "b", READ);
a.assertReadWriteFlags("new A(&a, b, c)", "c", READ);
a.assertReadWriteFlags("z(&a, b, c)", "a", READ);
a.assertReadWriteFlags("z(&a, b, c)", "b", READ);
a.assertReadWriteFlags("z(&a, b, c)", "c", READ);
}
// struct A {

View file

@ -2061,4 +2061,118 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
public void testAliasTemplate() throws Exception {
checkBindings();
}
// template<typename U>
// struct A {
// typedef U type1;
//
// template<typename V>
// struct rebind {
// typedef A<V> other;
// };
// };
//
// template<typename T, typename U>
// struct B {
// template<typename T2, typename U2>
// static constexpr bool test(typename T2::template rebind<U2>::other*) {
// return true;
// }
//
// template<typename, typename>
// static constexpr bool test(...) {
// return false;
// }
//
// static const bool value = test<T, U>(nullptr);
// };
//
// template<typename T, typename U, bool = B<T, U>::value>
// struct C;
//
// template<typename T, typename U>
// struct C<T, U, true> {
// typedef typename T::template rebind<U>::other type2;
// };
//
// template<typename T1>
// struct D {
// typedef typename T1::type1 type3;
//
// template<typename U1>
// using rebind2 = typename C<T1, U1>::type2;
// };
//
// template<typename T>
// struct E : D<T> {
// typedef D<T> Base;
// typedef typename Base::type3& type4;
//
// template<typename U>
// struct rebind {
// typedef typename Base::template rebind2<U> other;
// };
// };
//
// template<typename U, typename T = A<U>>
// struct F {
// typedef typename E<T>::template rebind<U>::other type5;
// typedef typename E<type5>::type4 type6;
// type6 operator[](int n);
// };
//
// void f(int);
// void test() {
// F<int*> a;
// f(*a[0]);
// }
public void testConstexprFunction_395238_1() throws Exception {
checkBindings();
}
// template<typename T>
// struct A {
// template<typename U>
// static constexpr U test(U v) {
// return v;
// }
//
// template<typename>
// static constexpr bool test(...) {
// return false;
// }
//
// static const bool value = test<T>(true);
// };
//
// template<typename T, bool = A<T>::value>
// struct B;
//
// template<typename T>
// struct B<T, true> {
// typedef T type;
// };
// B<bool>::type x;
// B<int*>::type y;
public void testConstexprFunction_395238_2() throws Exception {
ITypedef td = getBindingFromASTName("type x", 4, ITypedef.class);
assertEquals("bool", ASTTypeUtil.getType(td.getType()));
getProblemFromASTName("type y", 4);
}
// template <class RandomAccessRange, class BinaryPredicate>
// void sort(const RandomAccessRange& rng, BinaryPredicate pred);
//
// struct S {};
// const S* s[5];
// template <typename BinaryPredicate>
// void test(BinaryPredicate bp) {
// sort(s, [&bp](const S* a, const S* b){ return bp(*a, *b); });
// }
public void testLambdaExpression_395884() throws Exception {
checkBindings();
}
}

View file

@ -49,7 +49,10 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
public class BaseTestCase extends TestCase {
protected static final int INDEXER_TIMEOUT_SEC = 10;
private static final String DEFAULT_INDEXER_TIMEOUT_SEC = "10";
private static final String INDEXER_TIMEOUT_PROPERTY = "indexer.timeout";
protected static final int INDEXER_TIMEOUT_SEC =
Integer.parseInt(System.getProperty(INDEXER_TIMEOUT_PROPERTY, DEFAULT_INDEXER_TIMEOUT_SEC));
private boolean fExpectFailure;
private int fBugNumber;
private int fExpectedLoggedNonOK;

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPQualifierType;
import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -310,10 +311,18 @@ public class ASTTypeUtil {
if (needSpace) result.append(SPACE);
result.append(Keywords.FLOAT);
break;
case eFloat128:
if (needSpace) result.append(SPACE);
result.append(GCCKeywords.__FLOAT128);
break;
case eInt:
if (needSpace) result.append(SPACE);
result.append(Keywords.INT);
break;
case eInt128:
if (needSpace) result.append(SPACE);
result.append(GCCKeywords.__INT128);
break;
case eVoid:
if (needSpace) result.append(SPACE);
result.append(Keywords.VOID);

View file

@ -48,28 +48,32 @@ public interface IBinding extends IAdaptable {
* Returns the binding that owns this binding, or <code>null</code> if there is no owner.
* <p>
* The owner is determined as follows:
* <br> {@link ICPPUsingDeclaration}: The owner depends on where the declaration is found, within a
* function or method, a class-type, a namespace or on global scope.
* <br> {@link ICPPUsingDeclaration}: The owner depends on where the declaration is found,
* within a function or method, a class-type, a namespace or on global scope.
* <br> {@link ICPPTemplateParameter}: The owner is the {@link ICPPTemplateDefinition}.
* <br> {@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they are scoped or not.
* <br> For all other bindings: The owner depends on where the binding can be defined (it could be
* declared else where).
* <br> {@link IEnumerator}: The owner is the {@link IEnumeration}, independent of whether they
* are scoped or not.
* <br> For all other bindings: The owner depends on where the binding can be defined (it could
* be declared elsewhere).
* <p> Possible owners are:
* <br> {@link IFunction}: for parameters, local types, variables, enumerators, labels and using declarations;
* <br> {@link ICPPClassType}: for class-, struct- and union-members, even if the composite type is anonymous;
* also for enumerators and using declarations;
* <br> {@link ICompositeType}: for struct- and union-members, even if the composite type is anonymous;
* also for anonymous structs or unions found within another struct;
* <br> {@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces and using declarations;
* <br> {@link IFunction}: for parameters, local types, variables, enumerators, labels and using
* declarations;
* <br> Closure represented by {@link ICPPClassType}: for lambda expression parameters;
* <br> {@link ICPPClassType}: for class-, struct- and union-members, even if the composite type
* is anonymous; also for enumerators and using declarations;
* <br> {@link ICompositeType}: for struct- and union-members, even if the composite type is
* anonymous; also for anonymous structs or unions found within another struct;
* <br> {@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces
* and using declarations;
* <br> {@link IEnumeration}: for enumerators.
* <br> <code>null</code>: for types, functions, variables, namespaces and using declarations;
* <br> {@code null}: for types, functions, variables, namespaces and using declarations;
* @since 5.1
*/
public IBinding getOwner();
/**
* Returns the parent scope for this binding. A binding may have declarations in multiple scopes,
* this method returns the scope where the binding would potentially be defined.
* Returns the parent scope for this binding. A binding may have declarations in multiple
* scopes, this method returns the scope where the binding would potentially be defined.
*/
public IScope getScope() throws DOMException;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2012 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
@ -8,6 +8,7 @@
* Contributors:
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
@ -38,6 +39,12 @@ public interface ICPPFunction extends IFunction, ICPPBinding {
*/
public boolean isExternC();
/**
* Returns whether this function is declared constexpr.
* @since 5.5
*/
public boolean isConstexpr();
/**
* Returns the exception specification for this function or <code>null</code> if there
* is no exception specification.

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.core.parser.util;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -42,9 +43,7 @@ public class ObjectMap extends ObjectTable<Object> {
@Override
final public void clear() {
super.clear();
for(int i = 0; i < valueTable.length; i++) {
valueTable[i] = null;
}
Arrays.fill(valueTable, null);
}
@Override

View file

@ -74,7 +74,8 @@ public class ASTInternal {
}
}
public static IASTNode getDeclaredInSourceFileOnly(IIndexFragment forFragment, IBinding binding, boolean requireDefinition, PDOMBinding nonLocal) {
public static IASTNode getDeclaredInSourceFileOnly(IIndexFragment forFragment, IBinding binding,
boolean requireDefinition, PDOMBinding glob) {
IASTNode[] decls;
IASTNode def;
if (binding instanceof ICPPInternalBinding) {
@ -110,9 +111,9 @@ public class ASTInternal {
if (result == null)
return null;
if (requireDefinition && nonLocal != null) {
if (requireDefinition && glob != null) {
try {
if (nonLocal.hasDeclaration())
if (glob.hasDeclaration())
return null;
} catch (CoreException e) {
}

View file

@ -417,8 +417,9 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
copy.fForContentAssist = fForContentAssist;
copy.fOriginatingTranslationUnit = fOriginatingTranslationUnit;
for (IASTDeclaration declaration : getDeclarations())
for (IASTDeclaration declaration : getDeclarations()) {
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
}
copy.setOffsetAndLength(this);
}

View file

@ -33,6 +33,7 @@ public abstract class ArithmeticConversion {
eComplex(IBasicType.IS_COMPLEX);
private final int fModifier;
private Domain(int modifier) {
fModifier= modifier;
}
@ -120,11 +121,13 @@ public abstract class ArithmeticConversion {
case eChar16:
case eChar32:
case eInt:
case eInt128:
case eWChar:
return true;
case eDouble:
case eFloat:
case eFloat128:
case eUnspecified:
case eVoid:
case eNullPtr:
@ -219,6 +222,7 @@ public abstract class ArithmeticConversion {
case eWChar:
case eChar16:
return createBasicType(Kind.eInt, domain.getModifier());
case eChar32:
// Assuming 32 bits
return createBasicType(Kind.eInt, domain.getModifier() | IBasicType.IS_UNSIGNED);
@ -228,10 +232,14 @@ public abstract class ArithmeticConversion {
return createBasicType(Kind.eInt, domain.getModifier());
return adjustDomain(bt, domain);
case eInt128:
return createBasicType(Kind.eInt128, domain.getModifier() | IBasicType.IS_UNSIGNED);
case eVoid:
case eUnspecified:
case eDouble:
case eFloat:
case eFloat128:
case eNullPtr:
assert false;
}
@ -271,6 +279,8 @@ public abstract class ArithmeticConversion {
}
private Rank getIntegerRank(IBasicType type) {
if (type.getKind() == Kind.eInt128)
return Rank.eLongLong;
assert type.getKind() == Kind.eInt;
if (type.isLongLong())
return Rank.eLongLong;
@ -282,7 +292,7 @@ public abstract class ArithmeticConversion {
private boolean isLongDouble(IType type) {
if (type instanceof IBasicType) {
final IBasicType bt= (IBasicType) type;
return bt.isLong() && bt.getKind() == Kind.eDouble;
return bt.isLong() && bt.getKind() == Kind.eDouble || bt.getKind() == Kind.eFloat128;
}
return false;
}

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -54,13 +55,13 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
@ -77,6 +78,20 @@ public class Value implements IValue {
public static final Value UNKNOWN= new Value("<unknown>".toCharArray(), null); //$NON-NLS-1$
public static final Value NOT_INITIALIZED= new Value("<__>".toCharArray(), null); //$NON-NLS-1$
private static final Number VALUE_CANNOT_BE_DETERMINED = new Number() {
@Override
public int intValue() { throw new UnsupportedOperationException(); }
@Override
public long longValue() { throw new UnsupportedOperationException(); }
@Override
public float floatValue() { throw new UnsupportedOperationException(); }
@Override
public double doubleValue() { throw new UnsupportedOperationException(); }
};
private static final char UNIQUE_CHAR = '_';
private final static IValue[] TYPICAL= {
@ -89,8 +104,6 @@ public class Value implements IValue {
new Value(new char[] {'6'}, null)};
private static class UnknownValueException extends Exception {}
private static UnknownValueException UNKNOWN_EX= new UnknownValueException();
private static int sUnique= 0;
// The following invariant always holds: (fFixedValue == null) != (fEvaluation == null)
@ -235,44 +248,40 @@ public class Value implements IValue {
}
public static IValue evaluateBinaryExpression(final int op, final long v1, final long v2) {
try {
return create(applyBinaryOperator(op, v1, v2));
} catch (UnknownValueException e) {
}
Number val = applyBinaryOperator(op, v1, v2);
if (val != null && val != VALUE_CANNOT_BE_DETERMINED)
return create(val.longValue());
return UNKNOWN;
}
public static IValue evaluateUnaryExpression(final int unaryOp, final long value) {
try {
return create(applyUnaryOperator(unaryOp, value));
} catch (UnknownValueException e) {
}
Number val = applyUnaryOperator(unaryOp, value);
if (val != null && val != VALUE_CANNOT_BE_DETERMINED)
return create(val.longValue());
return UNKNOWN;
}
public static IValue evaluateUnaryTypeIdExpression(int operator, IType type, IASTNode point) {
try {
return create(applyUnaryTypeIdOperator(operator, type, point));
} catch (UnknownValueException e) {
}
Number val = applyUnaryTypeIdOperator(operator, type, point);
if (val != null && val != VALUE_CANNOT_BE_DETERMINED)
return create(val.longValue());
return UNKNOWN;
}
public static IValue evaluateBinaryTypeIdExpression(IASTBinaryTypeIdExpression.Operator operator,
IType type1, IType type2, IASTNode point) {
try {
return create(applyBinaryTypeIdOperator(operator, type1, type2, point));
} catch (UnknownValueException e) {
}
Number val = applyBinaryTypeIdOperator(operator, type1, type2, point);
if (val != null && val != VALUE_CANNOT_BE_DETERMINED)
return create(val.longValue());
return UNKNOWN;
}
private static long applyUnaryTypeIdOperator(int operator, IType type, IASTNode point) throws UnknownValueException{
private static Number applyUnaryTypeIdOperator(int operator, IType type, IASTNode point) {
switch (operator) {
case op_sizeof:
return getSizeAndAlignment(type, point).size;
return getSize(type, point);
case op_alignof:
return getSizeAndAlignment(type, point).alignment;
return getAlignment(type, point);
case op_typeid:
break; // TODO(sprigogin): Implement
case op_has_nothrow_copy:
@ -318,25 +327,32 @@ public class Value implements IValue {
case op_typeof:
break; // TODO(sprigogin): Implement
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
public static long applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator,
IType type1, IType type2, IASTNode point) throws UnknownValueException {
public static Number applyBinaryTypeIdOperator(IASTBinaryTypeIdExpression.Operator operator,
IType type1, IType type2, IASTNode point) {
switch (operator) {
case __is_base_of:
if (type1 instanceof ICPPClassType && type1 instanceof ICPPClassType) {
return ClassTypeHelper.isSubclass((ICPPClassType) type2, (ICPPClassType) type1) ? 1 : 0;
}
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
private static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) throws UnknownValueException {
private static Number getAlignment(IType type, IASTNode point) {
SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(type, point);
if (sizeAndAlignment == null)
throw UNKNOWN_EX;
return sizeAndAlignment;
return VALUE_CANNOT_BE_DETERMINED;
return sizeAndAlignment.alignment;
}
private static Number getSize(IType type, IASTNode point) {
SizeAndAlignment sizeAndAlignment = SizeofCalculator.getSizeAndAlignment(type, point);
if (sizeAndAlignment == null)
return VALUE_CANNOT_BE_DETERMINED;
return sizeAndAlignment.size;
}
/**
@ -348,10 +364,7 @@ public class Value implements IValue {
public static int isTemplateParameter(IValue tval) {
ICPPEvaluation eval = tval.getEvaluation();
if (eval instanceof EvalBinding) {
IBinding binding = ((EvalBinding) eval).getBinding();
if (binding instanceof ICPPTemplateParameter) {
return ((ICPPTemplateParameter) binding).getParameterID();
}
return ((EvalBinding) eval).getTemplateParameterID();
}
return -1;
}
@ -380,17 +393,16 @@ public class Value implements IValue {
* Creates the value for an expression.
*/
public static IValue create(IASTExpression expr, int maxRecursionDepth) {
try {
Object obj= evaluate(expr, maxRecursionDepth);
if (obj instanceof Long)
return create(((Long) obj).longValue());
Number val= evaluate(expr, maxRecursionDepth);
if (val == VALUE_CANNOT_BE_DETERMINED)
return UNKNOWN;
if (val != null)
return create(val.longValue());
if (expr instanceof ICPPASTInitializerClause) {
ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation();
return new Value(null, evaluation);
}
} catch (UnknownValueException e) {
}
return UNKNOWN;
}
@ -413,15 +425,15 @@ public class Value implements IValue {
/**
* Computes the canonical representation of the value of the expression.
* Returns a {@code Long} for numerical values or {@code null}, otherwise.
* Returns a {@code Number} for numerical values or {@code null}, otherwise.
* @throws UnknownValueException
*/
private static Long evaluate(IASTExpression exp, int maxdepth) throws UnknownValueException {
private static Number evaluate(IASTExpression exp, int maxdepth) {
if (maxdepth < 0 || exp == null)
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
if (exp instanceof IASTArraySubscriptExpression) {
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
if (exp instanceof IASTBinaryExpression) {
return evaluateBinaryExpression((IASTBinaryExpression) exp, maxdepth);
@ -434,9 +446,9 @@ public class Value implements IValue {
}
if (exp instanceof IASTConditionalExpression) {
IASTConditionalExpression cexpr= (IASTConditionalExpression) exp;
Long v= evaluate(cexpr.getLogicalConditionExpression(), maxdepth);
if (v == null)
return null;
Number v= evaluate(cexpr.getLogicalConditionExpression(), maxdepth);
if (v == null || v == VALUE_CANNOT_BE_DETERMINED)
return v;
if (v.longValue() == 0) {
return evaluate(cexpr.getNegativeResultExpression(), maxdepth);
}
@ -461,7 +473,7 @@ public class Value implements IValue {
try {
return ExpressionEvaluator.getNumber(litEx.getValue());
} catch (EvalException e) {
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
case IASTLiteralExpression.lk_char_constant:
try {
@ -470,30 +482,39 @@ public class Value implements IValue {
return ExpressionEvaluator.getChar(image, 2);
return ExpressionEvaluator.getChar(image, 1);
} catch (EvalException e) {
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
}
}
if (exp instanceof IASTTypeIdExpression) {
IASTTypeIdExpression typeIdExp = (IASTTypeIdExpression) exp;
ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit();
final IType type = ast.createType(((IASTTypeIdExpression) exp).getTypeId());
final IType type = ast.createType(typeIdExp.getTypeId());
if (type instanceof ICPPUnknownType)
return null;
return applyUnaryTypeIdOperator(((IASTTypeIdExpression) exp).getOperator(), type, exp);
return applyUnaryTypeIdOperator(typeIdExp.getOperator(), type, exp);
}
if (exp instanceof IASTBinaryTypeIdExpression) {
IASTBinaryTypeIdExpression typeIdExp = (IASTBinaryTypeIdExpression) exp;
ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit();
IType t1= ast.createType(typeIdExp.getOperand1());
IType t2= ast.createType(typeIdExp.getOperand2());
if (CPPTemplates.isDependentType(t1) || CPPTemplates.isDependentType(t2))
return null;
return applyBinaryTypeIdOperator(typeIdExp.getOperator(), t1, t2, exp);
}
throw UNKNOWN_EX;
if (exp instanceof IASTFunctionCallExpression) {
return null; // The value will be obtained from the evaluation.
}
return VALUE_CANNOT_BE_DETERMINED;
}
/**
* Extract a value off a binding.
*/
private static Long evaluateBinding(IBinding b, int maxdepth) throws UnknownValueException {
private static Number evaluateBinding(IBinding b, int maxdepth) {
if (b instanceof IType) {
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
if (b instanceof ICPPTemplateNonTypeParameter) {
return null;
@ -515,11 +536,10 @@ public class Value implements IValue {
return value.numericalValue();
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
private static Long evaluateUnaryExpression(IASTUnaryExpression exp, int maxdepth)
throws UnknownValueException {
private static Number evaluateUnaryExpression(IASTUnaryExpression exp, int maxdepth) {
final int unaryOp= exp.getOperator();
if (unaryOp == IASTUnaryExpression.op_sizeof) {
@ -534,21 +554,21 @@ public class Value implements IValue {
if (info != null)
return info.size;
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
if (unaryOp == IASTUnaryExpression.op_amper || unaryOp == IASTUnaryExpression.op_star ||
unaryOp == IASTUnaryExpression.op_sizeofParameterPack) {
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
final Long value= evaluate(exp.getOperand(), maxdepth);
if (value == null)
return null;
return applyUnaryOperator(unaryOp, value);
final Number value= evaluate(exp.getOperand(), maxdepth);
if (value == null || value == VALUE_CANNOT_BE_DETERMINED)
return value;
return applyUnaryOperator(unaryOp, value.longValue());
}
private static long applyUnaryOperator(final int unaryOp, final long value) throws UnknownValueException {
private static Number applyUnaryOperator(final int unaryOp, final long value) {
switch (unaryOp) {
case IASTUnaryExpression.op_bracketedPrimary:
case IASTUnaryExpression.op_plus:
@ -569,11 +589,10 @@ public class Value implements IValue {
case IASTUnaryExpression.op_not:
return value == 0 ? 1 : 0;
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
private static Long evaluateBinaryExpression(IASTBinaryExpression exp, int maxdepth)
throws UnknownValueException {
private static Number evaluateBinaryExpression(IASTBinaryExpression exp, int maxdepth) {
final int op= exp.getOperator();
switch (op) {
case IASTBinaryExpression.op_equals:
@ -586,28 +605,27 @@ public class Value implements IValue {
break;
}
final Long o1= evaluate(exp.getOperand1(), maxdepth);
if (o1 == null)
return null;
final Long o2= evaluate(exp.getOperand2(), maxdepth);
if (o2 == null)
return null;
final Number o1= evaluate(exp.getOperand1(), maxdepth);
if (o1 == null || o1 == VALUE_CANNOT_BE_DETERMINED)
return o1;
final Number o2= evaluate(exp.getOperand2(), maxdepth);
if (o2 == null || o2 == VALUE_CANNOT_BE_DETERMINED)
return o2;
return applyBinaryOperator(op, o1, o2);
return applyBinaryOperator(op, o1.longValue(), o2.longValue());
}
private static long applyBinaryOperator(final int op, final long v1, final long v2)
throws UnknownValueException {
private static Number applyBinaryOperator(final int op, final long v1, final long v2) {
switch (op) {
case IASTBinaryExpression.op_multiply:
return v1 * v2;
case IASTBinaryExpression.op_divide:
if (v2 == 0)
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
return v1 / v2;
case IASTBinaryExpression.op_modulo:
if (v2 == 0)
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
return v1 % v2;
case IASTBinaryExpression.op_plus:
return v1 + v2;
@ -644,7 +662,7 @@ public class Value implements IValue {
case IASTBinaryExpression.op_min:
return Math.min(v1, v2);
}
throw UNKNOWN_EX;
return VALUE_CANNOT_BE_DETERMINED;
}
/**

View file

@ -51,11 +51,7 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC
@Override
public CASTIdExpression copy(CopyStyle style) {
CASTIdExpression copy = new CASTIdExpression(name == null ? null : name.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override

View file

@ -73,11 +73,7 @@ public class CPPASTAliasDeclaration extends ASTNode implements ICPPASTAliasDecla
CPPASTAliasDeclaration copy = new CPPASTAliasDeclaration(
aliasName == null ? null : aliasName.copy(style),
mappingTypeId == null ? null : mappingTypeId.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override

View file

@ -27,8 +27,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* Models a function definition without a try-block. If used for a constructor definition it may contain
* member initializers.
* Models a function definition without a try-block. If used for a constructor definition
* it may contain member initializers.
*/
public class CPPASTFunctionDefinition extends ASTNode
implements ICPPASTFunctionDefinition, IASTAmbiguityParent {
@ -68,16 +68,13 @@ public class CPPASTFunctionDefinition extends ASTNode
copy.setBody(bodyStatement == null ? null : bodyStatement.copy(style));
for (ICPPASTConstructorChainInitializer initializer : getMemberInitializers())
for (ICPPASTConstructorChainInitializer initializer : getMemberInitializers()) {
copy.addMemberInitializer(initializer == null ? null : initializer.copy(style));
}
copy.fDefaulted = fDefaulted;
copy.fDeleted = fDeleted;
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override

View file

@ -48,11 +48,7 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICP
@Override
public CPPASTIdExpression copy(CopyStyle style) {
CPPASTIdExpression copy = new CPPASTIdExpression(name == null ? null : name.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -94,7 +90,8 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICP
@Override
public int getRoleForName(IASTName n) {
if (name == n) return r_reference;
if (name == n)
return r_reference;
return r_unclear;
}

View file

@ -25,7 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
public class CPPASTImplicitName extends CPPASTName implements IASTImplicitName {
private boolean alternate;
private boolean isOperator;
private boolean isDefinition= false;
private boolean isDefinition;
public CPPASTImplicitName(char[] name, IASTNode parent) {
super(name);

View file

@ -263,7 +263,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
if (image.length > 1 && image[0] == 'L')
return Value.create(ExpressionEvaluator.getChar(image, 2));
return Value.create(ExpressionEvaluator.getChar(image, 1));
} catch (EvalException e1) {
} catch (EvalException e) {
return Value.UNKNOWN;
}
}
@ -271,7 +271,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
private IValue createIntValue() {
try {
return Value.create(ExpressionEvaluator.getNumber(getValue()));
} catch (EvalException e1) {
} catch (EvalException e) {
return Value.UNKNOWN;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 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
@ -9,6 +9,7 @@
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Mike Kucera (IBM)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
@ -46,7 +48,7 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression
private IASTInitializerClause[] placement;
private IASTTypeId typeId;
private IASTInitializer initializer;
private IASTImplicitName[] implicitNames = null;
private IASTImplicitName[] implicitNames;
private boolean isGlobal;
private boolean isNewTypeId;
@ -163,16 +165,36 @@ public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression
@Override
public IASTImplicitName[] getImplicitNames() {
if (implicitNames == null) {
CPPASTImplicitName operatorName = null;
ICPPFunction operatorFunction = CPPSemantics.findOverloadedOperator(this);
if (operatorFunction == null || operatorFunction instanceof CPPImplicitFunction) {
implicitNames = IASTImplicitName.EMPTY_NAME_ARRAY;
} else {
CPPASTImplicitName operatorName = new CPPASTImplicitName(operatorFunction.getNameCharArray(), this);
if (operatorFunction != null && !(operatorFunction instanceof CPPImplicitFunction)) {
operatorName = new CPPASTImplicitName(operatorFunction.getNameCharArray(), this);
operatorName.setOperator(true);
operatorName.setBinding(operatorFunction);
operatorName.setOffsetAndLength(getOffset(), 3);
}
CPPASTImplicitName constructorName = null;
ICPPConstructor constructor = CPPSemantics.findImplicitlyCalledConstructor(this);
if (constructor != null) {
constructorName = new CPPASTImplicitName(constructor.getNameCharArray(), this);
constructorName.setBinding(constructor);
constructorName.setOffsetAndLength((ASTNode) getTypeId());
}
if (operatorName != null) {
if (constructorName != null) {
implicitNames = new IASTImplicitName[] { operatorName, constructorName };
} else {
implicitNames = new IASTImplicitName[] { operatorName };
}
} else {
if (constructorName != null) {
implicitNames = new IASTImplicitName[] { constructorName };
} else {
implicitNames = IASTImplicitName.EMPTY_NAME_ARRAY;
}
}
}
return implicitNames;

View file

@ -8,6 +8,7 @@
*
* Contributors:
* Thomas Corbat (IFS) - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -28,7 +29,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
public class CPPAliasTemplate extends PlatformObject implements ICPPAliasTemplate {
public class CPPAliasTemplate extends PlatformObject
implements ICPPAliasTemplate, ICPPTemplateParameterOwner {
private final IASTName aliasName;
private final IType aliasedType;
private ICPPTemplateParameter[] templateParameters;
@ -128,4 +130,16 @@ public class CPPAliasTemplate extends PlatformObject implements ICPPAliasTemplat
public String toString() {
return ASTTypeUtil.getQualifiedName(this) + " -> " + ASTTypeUtil.getType(aliasedType, true); //$NON-NLS-1$
}
@Override
public IBinding resolveTemplateParameter(ICPPTemplateParameter templateParameter) {
int pos= templateParameter.getParameterPosition();
ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(aliasName).getTemplateParameters();
if (pos < params.length) {
final IASTName oName = CPPTemplates.getTemplateParameterName(params[pos]);
return oName.resolvePreBinding();
}
return templateParameter;
}
}

View file

@ -8,6 +8,7 @@
*
* Contributors:
* Thomas Corbat (IFS) - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -22,21 +23,22 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject;
public class CPPAliasTemplateInstance extends PlatformObject
implements ICPPAliasTemplateInstance, ISerializableType {
implements ICPPAliasTemplateInstance, ITypeContainer, ISerializableType {
private final char[] name;
private final IType aliasedType;
private final ICPPAliasTemplate aliasTemplate;
private IType aliasedType;
public CPPAliasTemplateInstance(char[] name, IType aliasedType, ICPPAliasTemplate aliasTemplate) {
public CPPAliasTemplateInstance(char[] name, ICPPAliasTemplate aliasTemplate, IType aliasedType) {
this.name = name;
this.aliasedType = aliasedType;
this.aliasTemplate = aliasTemplate;
this.aliasedType = aliasedType;
}
@Override
@ -59,6 +61,11 @@ public class CPPAliasTemplateInstance extends PlatformObject
return aliasedType;
}
@Override
public void setType(IType type) {
aliasedType = type;
}
@Override
public Object clone() {
try {
@ -115,7 +122,7 @@ public class CPPAliasTemplateInstance extends PlatformObject
char[] name = buffer.getCharArray();
IType unmarshalledAliasedTypeInstance = buffer.unmarshalType();
ICPPAliasTemplate unmarshalledAlias = (ICPPAliasTemplate)buffer.unmarshalBinding();
return new CPPAliasTemplateInstance(name, unmarshalledAliasedTypeInstance, unmarshalledAlias);
return new CPPAliasTemplateInstance(name, unmarshalledAlias, unmarshalledAliasedTypeInstance);
}
@Override

View file

@ -34,7 +34,7 @@ public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter
return result;
}
private IType type= null;
private IType type;
public CPPBuiltinParameter(IType type) {
this.type = type;

View file

@ -135,6 +135,11 @@ public class CPPClassSpecialization extends CPPSpecialization
public boolean isFinal() {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
}
private ICPPClassSpecializationScope specScope;

View file

@ -107,7 +107,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
ICPPParameter[] params = new ICPPParameter[parameterTypes.length];
for (int i = 0; i < params.length; i++) {
params[i]= new CPPParameter(parameterTypes[i], 0);
params[i]= new CPPParameter(parameterTypes[i], i);
}
m= new CPPImplicitMethod(scope, OverloadableOperator.PAREN.toCharArray(), ft, params) {
@Override

View file

@ -19,5 +19,4 @@ public class CPPConstructor extends CPPMethod implements ICPPConstructor {
public CPPConstructor(ICPPASTFunctionDeclarator declarator) {
super(declarator);
}
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -25,7 +26,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
* Represents a reference to a (member) function (instance), which cannot be resolved because
* an argument depends on a template parameter. A compiler would resolve it during instantiation.
*/
public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFunction {
public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFunction, ICPPComputableFunction {
private static final ICPPFunctionType FUNCTION_TYPE=
new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY);
@ -69,6 +70,11 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFuncti
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public IScope getFunctionScope() {
return asScope();
@ -128,4 +134,9 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFuncti
public IBinding getOwner() {
return fOwner;
}
@Override
public ICPPEvaluation getReturnExpression() {
return null;
}
}

View file

@ -18,15 +18,19 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -38,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
@ -52,6 +57,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.PlatformObject;
@ -230,17 +236,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
IASTName n = getASTName();
IScope scope = CPPVisitor.getContainingScope(n);
if (scope instanceof ICPPClassScope) {
ICPPASTDeclSpecifier declSpec = null;
if (definition != null) {
IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
} else {
IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent();
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
}
if (declSpec.isFriend()) {
ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
if (declSpec != null && declSpec.isFriend()) {
try {
while (scope instanceof ICPPClassScope) {
scope = scope.getParent();
@ -252,6 +249,19 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return scope;
}
private ICPPASTDeclSpecifier getDeclSpecifier() {
if (definition != null) {
IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
return (ICPPASTDeclSpecifier) def.getDeclSpecifier();
} else if (declarations != null && declarations.length != 0) {
IASTNode node = ASTQueries.findOutermostDeclarator(declarations[0]).getParent();
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node;
return (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
}
return null;
}
@Override
public ICPPFunctionType getType() {
if (type == null) {
@ -437,19 +447,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return false;
}
@Override
public boolean isDeleted() {
return isDeletedDefinition(getDefinition());
}
public static boolean isDeletedDefinition(IASTNode def) {
static ICPPASTFunctionDefinition getFunctionDefinition(IASTNode def) {
while (def != null && !(def instanceof IASTDeclaration)) {
def= def.getParent();
}
if (def instanceof ICPPASTFunctionDefinition) {
return ((ICPPASTFunctionDefinition) def).isDeleted();
return (ICPPASTFunctionDefinition) def;
}
return false;
return null;
}
@Override
@ -511,6 +516,26 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return hasStorageClass(this, IASTDeclSpecifier.sc_auto);
}
@Override
public boolean isConstexpr() {
ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
if (declSpec == null)
return false;
return declSpec.isConstexpr();
}
@Override
public boolean isDeleted() {
return isDeletedDefinition(getDefinition());
}
static boolean isDeletedDefinition(IASTNode def) {
ICPPASTFunctionDefinition functionDefinition = getFunctionDefinition(def);
if (functionDefinition != null)
return functionDefinition.isDeleted();
return false;
}
@Override
public boolean isRegister() {
return hasStorageClass(this, IASTDeclSpecifier.sc_register);
@ -608,4 +633,46 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
ICPPASTFunctionDeclarator dtor = getPreferredDtor();
return dtor != null && AttributeUtil.hasNoreturnAttribute(dtor);
}
@Override
public ICPPEvaluation getReturnExpression() {
if (!isConstexpr())
return null;
if (definition == null)
return EvalFixed.INCOMPLETE;
IASTNode node = ASTQueries.findOutermostDeclarator(definition).getParent();
return getReturnExpression((IASTFunctionDefinition) node);
}
static ICPPEvaluation getReturnExpression(IASTFunctionDefinition functionDefinition) {
IASTReturnStatement returnStatement = null;
IASTStatement body = functionDefinition.getBody();
if (body instanceof IASTReturnStatement) {
returnStatement = (IASTReturnStatement) body;
} else if (body instanceof IASTCompoundStatement) {
for (IASTStatement statement : ((IASTCompoundStatement) body).getStatements()) {
if (statement instanceof IASTReturnStatement) {
if (returnStatement != null)
return EvalFixed.INCOMPLETE;
returnStatement = (IASTReturnStatement) statement;
}
}
}
if (returnStatement == null)
return EvalFixed.INCOMPLETE; // constexpr constructors are not supported yet.
IASTInitializerClause returnExpression = returnStatement.getReturnArgument();
if (returnExpression instanceof ICPPASTInitializerClause)
return ((ICPPASTInitializerClause) returnExpression).getEvaluation();
return EvalFixed.INCOMPLETE;
}
public static ICPPEvaluation getReturnExpression(ICPPFunction function) {
if (function instanceof ICPPComputableFunction) {
return ((ICPPComputableFunction) function).getReturnExpression();
}
return null;
}
}

View file

@ -28,7 +28,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
public class CPPFunctionInstance extends CPPFunctionSpecialization implements ICPPTemplateInstance {
private final ICPPTemplateArgument[] fArguments;
public CPPFunctionInstance(ICPPFunction orig, IBinding owner, CPPTemplateParameterMap argMap, ICPPTemplateArgument[] args, ICPPFunctionType type, IType[] exceptionSpecs) {
public CPPFunctionInstance(ICPPFunction orig, IBinding owner, CPPTemplateParameterMap argMap,
ICPPTemplateArgument[] args, ICPPFunctionType type, IType[] exceptionSpecs) {
super(orig, owner, argMap, type, exceptionSpecs);
fArguments = args;
}

View file

@ -24,7 +24,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
@ -43,7 +45,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
private ICPPParameter[] fParams;
private final IType[] fExceptionSpecs;
public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpecs) {
public CPPFunctionSpecialization(ICPPFunction orig, IBinding owner, ICPPTemplateParameterMap argMap,
ICPPFunctionType type, IType[] exceptionSpecs) {
super(orig, owner, argMap);
fType= type;
fExceptionSpecs= exceptionSpecs;
@ -103,19 +106,6 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
return false;
}
@Override
public boolean isDeleted() {
IASTNode def = getDefinition();
if (def != null)
return CPPFunction.isDeletedDefinition(def);
IBinding f = getSpecializedBinding();
if (f instanceof ICPPFunction) {
return ((ICPPFunction) f).isDeleted();
}
return false;
}
@Override
public boolean isInline() {
if (getDefinition() != null) {
@ -168,6 +158,33 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
return CPPFunction.hasStorageClass(this, IASTDeclSpecifier.sc_auto);
}
@Override
public boolean isConstexpr() {
IASTNode def = getDefinition();
if (def != null) {
ICPPASTFunctionDefinition functionDefinition = CPPFunction.getFunctionDefinition(def);
return ((ICPPASTDeclSpecifier) functionDefinition.getDeclSpecifier()).isConstexpr();
}
IBinding f = getSpecializedBinding();
if (f instanceof ICPPFunction) {
return ((ICPPFunction) f).isConstexpr();
}
return false;
}
@Override
public boolean isDeleted() {
IASTNode def = getDefinition();
if (def != null)
return CPPFunction.isDeletedDefinition(def);
IBinding f = getSpecializedBinding();
if (f instanceof ICPPFunction) {
return ((ICPPFunction) f).isDeleted();
}
return false;
}
@Override
public boolean isRegister() {
ICPPFunction f = (ICPPFunction) getSpecializedBinding();
@ -314,4 +331,21 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
public IType[] getExceptionSpecification() {
return fExceptionSpecs;
}
@Override
public ICPPEvaluation getReturnExpression() {
if (!isConstexpr())
return null;
IASTNode def = getDefinition();
if (def != null) {
ICPPASTFunctionDefinition functionDefinition = CPPFunction.getFunctionDefinition(def);
return CPPFunction.getReturnExpression(functionDefinition);
}
IBinding f = getSpecializedBinding();
if (f instanceof ICPPComputableFunction) {
return ((ICPPComputableFunction) f).getReturnExpression();
}
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2012 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
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
@ -41,6 +42,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
/**
* Implementation of function templates
@ -317,13 +319,21 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
}
@Override
public boolean isDeleted() {
return CPPFunction.isDeletedDefinition(getDefinition());
public boolean isAuto() {
return hasStorageClass(IASTDeclSpecifier.sc_auto);
}
@Override
public boolean isAuto() {
return hasStorageClass(IASTDeclSpecifier.sc_auto);
public boolean isConstexpr() {
ICPPASTFunctionDefinition functionDefinition = CPPFunction.getFunctionDefinition(getDefinition());
if (functionDefinition == null)
return false;
return ((ICPPASTDeclSpecifier) functionDefinition.getDeclSpecifier()).isConstexpr();
}
@Override
public boolean isDeleted() {
return CPPFunction.isDeletedDefinition(getDefinition());
}
@Override
@ -394,4 +404,14 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
}
return null;
}
@Override
public ICPPEvaluation getReturnExpression() {
if (!isConstexpr())
return null;
ICPPASTFunctionDefinition functionDefinition = CPPFunction.getFunctionDefinition(getDefinition());
if (functionDefinition == null)
return EvalFixed.INCOMPLETE;
return CPPFunction.getReturnExpression(functionDefinition);
}
}

View file

@ -29,8 +29,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
*/
public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
implements ICPPFunctionTemplate, ICPPInternalTemplate {
private ObjectMap instances = null;
private ObjectMap instances;
public CPPFunctionTemplateSpecialization(ICPPFunction original, ICPPClassType owner, ICPPTemplateParameterMap argumentMap, ICPPFunctionType type, IType[] exceptionSpecs) {
super(original, owner, argumentMap, type, exceptionSpecs);

View file

@ -31,8 +31,8 @@ import org.eclipse.core.runtime.PlatformObject;
* Binding for a c++ function parameter
*/
public class CPPLambdaExpressionParameter extends PlatformObject implements ICPPParameter {
private IType fType = null;
private IASTName fDeclaration = null;
private IType fType;
private IASTName fDeclaration;
public CPPLambdaExpressionParameter(IASTName name) {
fDeclaration = name;
@ -77,14 +77,17 @@ public class CPPLambdaExpressionParameter extends PlatformObject implements ICPP
public boolean isStatic() {
return false;
}
@Override
public String[] getQualifiedName() {
return new String[] { getName() };
}
@Override
public char[][] getQualifiedNameCharArray() {
return new char[][] { getNameCharArray() };
}
@Override
public boolean isGloballyQualified() {
return false;

View file

@ -23,13 +23,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
*/
public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod {
public CPPMethodInstance(ICPPMethod orig, ICPPClassType owner, CPPTemplateParameterMap tpmap, ICPPTemplateArgument[] args, ICPPFunctionType type, IType[] exceptionSpecs) {
public CPPMethodInstance(ICPPMethod orig, ICPPClassType owner, CPPTemplateParameterMap tpmap,
ICPPTemplateArgument[] args, ICPPFunctionType type, IType[] exceptionSpecs) {
super(orig, owner, tpmap, args, type, exceptionSpecs);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/
@Override
public int getVisibility() {
return ((ICPPMethod) getTemplateDefinition()).getVisibility();
@ -40,17 +38,11 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
return (ICPPClassType) getOwner();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
@Override
public boolean isVirtual() {
return ((ICPPMethod) getTemplateDefinition()).isVirtual();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isPureVirtual()
*/
@Override
public boolean isPureVirtual() {
return ((ICPPMethod) getTemplateDefinition()).isPureVirtual();
@ -61,9 +53,6 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
return ((ICPPMethod) getTemplateDefinition()).isExplicit();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
*/
@Override
public boolean isDestructor() {
char[] name = getNameCharArray();

View file

@ -255,8 +255,8 @@ public abstract class CPPTemplateParameter extends PlatformObject
return current;
ICPPTemplateDefinition template= CPPTemplates.getContainingTemplate(getASTTemplateParameter());
if (template instanceof ICPPInternalTemplate) {
return ((ICPPInternalTemplate) template).resolveTemplateParameter(this);
if (template instanceof ICPPTemplateParameterOwner) {
return ((ICPPTemplateParameterOwner) template).resolveTemplateParameter(this);
}
// problem finding the containing template

View file

@ -28,7 +28,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
private IType fType;
public CPPTypedefSpecialization(IBinding specialized, ICPPClassType owner, ICPPTemplateParameterMap tpmap, IType type) {
public CPPTypedefSpecialization(IBinding specialized, ICPPClassType owner,
ICPPTemplateParameterMap tpmap, IType type) {
super(specialized, owner, tpmap);
fType= type;
}
@ -38,23 +39,17 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
return fType;
}
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
@Override
public Object clone() {
IType t = null;
try {
t = (IType) super.clone();
} catch (CloneNotSupportedException e) {
// not going to happen
// Not going to happen.
}
return t;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
@Override
public boolean isSameType(IType o) {
if (o == this)

View file

@ -33,6 +33,7 @@ public class CPPUnknownMemberClass extends CPPUnknownMember implements ICPPUnkno
public static CPPUnknownMemberClass createUnnamedInstance() {
return new CPPUnknownMemberClass(null, CharArrayUtils.EMPTY);
}
public CPPUnknownMemberClass(IType owner, char[] name) {
super(owner, name);
}

View file

@ -156,4 +156,9 @@ public class CPPUnknownMethod extends CPPUnknownMember implements ICPPMethod {
public boolean isFinal() {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2012 Google, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
/**
* Represents a function the return value of which may potentially be calculated at parsing time.
*/
public interface ICPPComputableFunction {
/**
* For a constexpr function returns the return statement expression. Otherwise returns
* {@code null}.
*/
public ICPPEvaluation getReturnExpression();
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -17,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPFunctionParameterMap;
/**
* Assists in evaluating expressions.
@ -70,6 +72,17 @@ public interface ICPPEvaluation extends ISerializableEvaluation {
ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point);
/**
* Computes the evaluation produced by substituting function parameters by their values.
*
* @param parameterMap maps function parameters to their values
* @param maxdepth allowed recursion depth
* @param point determines the scope for name lookups
* @return the computed evaluation
*/
ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap, int maxdepth,
IASTNode point);
/**
* Determines size of the template parameter pack.
*

View file

@ -15,12 +15,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
/**
* Caches instances per template, the template definitions need to implement this interface
*/
public interface ICPPInstanceCache {
/**
* Attempts to cache an instance with this template
*/

View file

@ -8,8 +8,8 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -17,8 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
/**
* Interface for ast-internal implementations of function bindings.
*/
public interface ICPPInternalFunction extends ICPPInternalBinding {
public interface ICPPInternalFunction extends ICPPInternalBinding, ICPPComputableFunction {
/**
* Called to resolve the parameter in the second phase.
*/

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2012 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
@ -10,14 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
/**
* Interface for templates from the ast.
* Interface for templates from the AST.
*/
public interface ICPPInternalTemplate extends ICPPInternalBinding, ICPPInstanceCache {
IBinding resolveTemplateParameter(ICPPTemplateParameter param);
public interface ICPPInternalTemplate
extends ICPPTemplateParameterOwner, ICPPInternalBinding, ICPPInstanceCache {
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2012 Google, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
/**
* Interface for templates from the AST.
*/
public interface ICPPTemplateParameterOwner {
IBinding resolveTemplateParameter(ICPPTemplateParameter param);
}

View file

@ -72,6 +72,11 @@ class AutoTypeResolver implements ICPPFunctionTemplate {
return false;
}
@Override
public boolean isConstexpr() {
return false;
}
@Override
public IType[] getExceptionSpecification() {
return null;

View file

@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2012 Google, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
/**
* Maps function parameter positions to values.
*/
public class CPPFunctionParameterMap {
public static final CPPFunctionParameterMap EMPTY = new CPPFunctionParameterMap(0);
private ObjectMap fMap;
/**
* Constructs an empty parameter map.
*/
public CPPFunctionParameterMap(int initialSize) {
fMap= new ObjectMap(initialSize);
}
public CPPFunctionParameterMap(CPPFunctionParameterMap other) {
fMap= (ObjectMap) other.fMap.clone();
}
/**
* Returns whether the map contains the given parameter
*/
public boolean contains(int parameterPosition) {
return fMap.containsKey(parameterPosition);
}
/**
* Adds the mapping.
*/
public void put(int parameterPosition, ICPPEvaluation value) {
fMap.put(parameterPosition, value);
}
/**
* Adds the mapping.
*/
public void put(int parameterPosition, ICPPEvaluation[] packExpansion) {
fMap.put(parameterPosition, packExpansion);
}
/**
* Returns the value for the given parameter.
*/
public ICPPEvaluation getArgument(int parameterPosition) {
final Object object = fMap.get(parameterPosition);
if (object instanceof ICPPEvaluation) {
return (ICPPEvaluation) object;
}
return null;
}
/**
* Returns the values for the given function parameter pack.
*/
public ICPPEvaluation[] getPackExpansion(int parameterPosition) {
final Object object = fMap.get(parameterPosition);
if (object instanceof ICPPEvaluation[]) {
return (ICPPEvaluation[]) object;
}
return null;
}
/**
* Returns the argument at the given position
*/
public ICPPEvaluation getArgument(int parameterPosition, int packOffset) {
final Object object = fMap.get(parameterPosition);
if (object instanceof ICPPEvaluation)
return (ICPPEvaluation) object;
if (object instanceof ICPPEvaluation[]) {
ICPPEvaluation[] args = (ICPPEvaluation[]) object;
if (packOffset < args.length && packOffset >= 0)
return args[packOffset];
}
return null;
}
/**
* Puts all mappings from the supplied map into this map.
*/
public void putAll(CPPFunctionParameterMap map) {
final ObjectMap otherMap= map.fMap;
for (int i = 0; i < otherMap.size(); i++) {
fMap.put(otherMap.keyAt(i), otherMap.getAt(i));
}
}
}

View file

@ -268,7 +268,7 @@ public class CPPSemantics {
lookup(data, null);
// Perform argument dependent lookup
if (data.checkAssociatedScopes() && !data.hasTypeOrMemberFunctionResult()) {
if (data.checkAssociatedScopes() && !data.hasTypeOrMemberFunctionOrVariableResult()) {
doKoenigLookup(data);
}
} catch (DOMException e) {
@ -3041,8 +3041,10 @@ public class CPPSemantics {
if (type == null)
return null;
ICPPEvaluation[] args = {new EvalFixed(type, LVALUE, Value.UNKNOWN),
((ICPPASTExpression) expr.getOperand()).getEvaluation()};
ICPPEvaluation[] args = {
new EvalFixed(type, LVALUE, Value.UNKNOWN),
((ICPPASTExpression) expr.getOperand()).getEvaluation()
};
return findOverloadedOperator(expr, args, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS);
}
@ -3095,9 +3097,10 @@ public class CPPSemantics {
IBinding binding = name.resolveBinding();
if (!(binding instanceof ICPPVariable))
return null;
IType type;
IType type = ((ICPPVariable) binding).getType();
try {
type = SemanticUtil.getNestedType(((ICPPVariable) binding).getType(), TDEF | CVTYPE);
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE);
if (!(type instanceof ICPPClassType))
return null;
if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem)
@ -3105,7 +3108,7 @@ public class CPPSemantics {
final ICPPClassType classType = (ICPPClassType) type;
if (initializer instanceof IASTEqualsInitializer) {
// Copy initialization
// Copy initialization.
IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer;
ICPPASTInitializerClause initClause = (ICPPASTInitializerClause) eqInit.getInitializerClause();
final ICPPEvaluation evaluation = initClause.getEvaluation();
@ -3126,7 +3129,7 @@ public class CPPSemantics {
}
}
} else if (initializer instanceof ICPPASTInitializerList) {
// List initialization
// List initialization.
ICPPEvaluation eval= ((ICPPASTInitializerList) initializer).getEvaluation();
if (eval instanceof EvalInitList) {
Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, name);
@ -3137,24 +3140,11 @@ public class CPPSemantics {
}
}
} else if (initializer instanceof ICPPASTConstructorInitializer) {
// Direct Initialization
final IASTInitializerClause[] arguments = ((ICPPASTConstructorInitializer) initializer).getArguments();
CPPASTName astName = new CPPASTName();
astName.setName(classType.getNameCharArray());
astName.setOffsetAndLength((ASTNode) name);
CPPASTIdExpression idExp = new CPPASTIdExpression(astName);
idExp.setParent(name.getParent());
idExp.setPropertyInParent(IASTFunctionCallExpression.FUNCTION_NAME);
LookupData data = new LookupData(astName);
data.setFunctionArguments(false, arguments);
data.qualified = true;
data.foundItems = ClassTypeHelper.getConstructors(classType, name);
binding = resolveAmbiguities(data);
if (binding instanceof ICPPConstructor)
return (ICPPConstructor) binding;
// Direct initialization.
return findImplicitlyCalledConstructor(classType,
(ICPPASTConstructorInitializer) initializer, name);
} else if (initializer == null) {
// Default initialization
// Default initialization.
ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name);
for (ICPPConstructor ctor : ctors) {
if (ctor.getRequiredArgumentCount() == 0)
@ -3167,6 +3157,43 @@ public class CPPSemantics {
return null;
}
public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) {
IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE);
if (!(type instanceof IPointerType))
return null;
type = ((IPointerType) type).getType();
IASTInitializer initializer = expr.getInitializer();
if (type instanceof ICPPClassType && initializer instanceof ICPPASTConstructorInitializer) {
return findImplicitlyCalledConstructor((ICPPClassType) type,
(ICPPASTConstructorInitializer) initializer, expr.getTypeId());
}
return null;
}
private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType classType,
ICPPASTConstructorInitializer initializer, IASTNode typeId) {
final IASTInitializerClause[] arguments = initializer.getArguments();
CPPASTName astName = new CPPASTName();
astName.setName(classType.getNameCharArray());
astName.setOffsetAndLength((ASTNode) typeId);
CPPASTIdExpression idExp = new CPPASTIdExpression(astName);
idExp.setParent(typeId.getParent());
idExp.setPropertyInParent(IASTFunctionCallExpression.FUNCTION_NAME);
LookupData data = new LookupData(astName);
data.setFunctionArguments(false, arguments);
data.qualified = true;
data.foundItems = ClassTypeHelper.getConstructors(classType, typeId);
IBinding binding;
try {
binding = resolveAmbiguities(data);
if (binding instanceof ICPPConstructor)
return (ICPPConstructor) binding;
} catch (DOMException e) {
}
return null;
}
public static ICPPFunction findImplicitlyCalledDestructor(ICPPASTDeleteExpression expr) {
IType t = getTypeOfPointer(expr.getOperand().getExpressionType());
if (!(t instanceof ICPPClassType))

View file

@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -534,8 +535,9 @@ public class CPPTemplates {
ICPPASTTemplateDeclaration templateDeclaration = templates[0];
IASTDeclaration decl = templateDeclaration.getDeclaration();
while (decl instanceof ICPPASTTemplateDeclaration)
while (decl instanceof ICPPASTTemplateDeclaration) {
decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration();
}
IASTName name = null;
if (decl instanceof IASTSimpleDeclaration) {
@ -557,6 +559,8 @@ public class CPPTemplates {
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
dtor= ASTQueries.findInnermostDeclarator(dtor);
name = dtor.getName();
} else if (decl instanceof ICPPASTAliasDeclaration) {
name = ((ICPPASTAliasDeclaration) decl).getAlias();
}
if (name == null)
return null;
@ -659,7 +663,7 @@ public class CPPTemplates {
IBinding owner = template.getOwner();
ICPPClassSpecialization within = getSpecializationContext(owner);
IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id);
return new CPPAliasTemplateInstance(id.toCharArray(), instantiatedType, aliasTemplate);
return new CPPAliasTemplateInstance(id.toCharArray(), aliasTemplate, instantiatedType);
}
// Class template.
@ -830,7 +834,7 @@ public class CPPTemplates {
} else if (decl instanceof ICPPAliasTemplate) {
ICPPAliasTemplate aliasTemplate = (ICPPAliasTemplate) decl;
IType type= instantiateType(aliasTemplate.getType(), tpMap, -1, getSpecializationContext(owner), point);
spec = new CPPAliasTemplateInstance(decl.getNameCharArray(), type, aliasTemplate);
spec = new CPPAliasTemplateInstance(decl.getNameCharArray(), aliasTemplate, type);
} else if (decl instanceof IEnumeration || decl instanceof IEnumerator) {
// TODO(sprigogin): Deal with a case when an enumerator value depends on a template parameter.
spec = decl;

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@ -68,7 +69,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
private int rwInCtorInitializer(IASTNode node, int indirection, ICPPASTConstructorInitializer parent) {
IASTNode grand= parent.getParent();
if (grand instanceof IASTDeclarator) {
if (grand instanceof IASTDeclarator || grand instanceof ICPPASTNewExpression) {
// Look for a constructor being called.
if (grand instanceof IASTImplicitNameOwner) {
IASTImplicitName[] names = ((IASTImplicitNameOwner) grand).getImplicitNames();
@ -87,7 +88,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
}
}
// Allow for initialization of primitive types.
if (parent.getArguments().length == 1) {
if (grand instanceof IASTDeclarator && parent.getArguments().length == 1) {
IBinding binding= ((IASTDeclarator) grand).getName().getBinding();
if (binding instanceof IVariable) {
IType type= ((IVariable) binding).getType();

View file

@ -238,6 +238,7 @@ public class CPPVisitor extends ASTQueries {
return new HashSet<IASTDeclSpecifier>();
}
};
public static IBinding createBinding(IASTName name) {
IASTNode parent = name.getParent();
IBinding binding = null;
@ -1978,7 +1979,13 @@ public class CPPVisitor extends ASTQueries {
return type;
}
private static IType createAutoType(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
private static IType createAutoType(final IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
Set<IASTDeclSpecifier> recursionProtectionSet = autoTypeDeclSpecs.get();
try {
if (!recursionProtectionSet.add(declSpec)) {
// Detected a self referring auto type, e.g.: auto x = x;
return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE);
}
if (declarator instanceof ICPPASTFunctionDeclarator) {
return createAutoFunctionType(declSpec, (ICPPASTFunctionDeclarator) declarator);
}
@ -2036,13 +2043,15 @@ public class CPPVisitor extends ASTQueries {
}
}
return createAutoType(autoInitClause, declSpec, declarator);
} finally {
recursionProtectionSet.remove(declSpec);
}
}
private static IType createAutoType(ICPPASTInitializerClause initClause, IASTDeclSpecifier declSpec,
IASTDeclarator declarator) {
// C++0x: 7.1.6.4
if (initClause == null || !autoTypeDeclSpecs.get().add(declSpec)) {
// Detected a self referring auto type, e.g.: auto x = x;
if (initClause == null) {
return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE);
}
@ -2050,7 +2059,6 @@ public class CPPVisitor extends ASTQueries {
IType initType = null;
ValueCategory valueCat= null;
ICPPClassTemplate initializer_list_template = null;
try {
if (initClause instanceof ICPPASTInitializerList) {
initializer_list_template = get_initializer_list(declSpec);
if (initializer_list_template == null) {
@ -2066,12 +2074,9 @@ public class CPPVisitor extends ASTQueries {
final ICPPEvaluation evaluation = initClause.getEvaluation();
initType= evaluation.getTypeOrFunctionSet(declarator);
valueCat= evaluation.getValueCategory(declarator);
if (initType == null) {
if (initType == null || initType instanceof ISemanticProblem) {
return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE);
}
} finally {
autoTypeDeclSpecs.get().remove(declSpec);
}
ICPPFunctionTemplate template = new AutoTypeResolver(type);
CPPTemplateParameterMap paramMap = new CPPTemplateParameterMap(1);
TemplateArgumentDeduction.deduceFromFunctionArgs(template, Collections.singletonList(initType),

View file

@ -347,6 +347,16 @@ public class EvalBinary extends CPPEvaluation {
return new EvalBinary(fOperator, arg1, arg2);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation arg1 = fArg1.computeForFunctionCall(parameterMap, maxdepth, point);
ICPPEvaluation arg2 = fArg2.computeForFunctionCall(parameterMap, maxdepth, point);
if (arg1 == fArg1 && arg2 == fArg2)
return this;
return new EvalBinary(fOperator, arg1, arg2);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return CPPTemplates.combinePackSize(fArg1.determinePackSize(tpMap), fArg2.determinePackSize(tpMap));

View file

@ -16,7 +16,6 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression.Operator;
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
@ -73,7 +72,7 @@ public class EvalBinaryTypeId extends CPPEvaluation {
case __is_base_of:
return CPPBasicType.BOOLEAN;
}
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}
@Override
@ -128,6 +127,12 @@ public class EvalBinaryTypeId extends CPPEvaluation {
return new EvalBinaryTypeId(fOperator, type1, type2);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
return this;
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return CPPTemplates.combinePackSize(CPPTemplates.determinePackSize(fType1, tpMap),

View file

@ -25,7 +25,9 @@ import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
@ -37,12 +39,28 @@ import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.core.runtime.CoreException;
public class EvalBinding extends CPPEvaluation {
private final IBinding fBinding;
/**
* The function owning the parameter if the binding is a function parameter, otherwise
* {@code null}. May be computed lazily and remains {@code null} until computed.
*/
private ICPPFunction fParameterOwner;
/**
* The position of the parameter in the parameter list if the binding is a function parameter,
* otherwise -1.
*/
private int fParameterPosition;
/**
* The binding represented by this evaluation. For a function parameter binding may be computed
* lazily to avoid infinite recursion during unmarshalling of the evaluation. If #fBinding is
* {@code null}, {@link #fParameterOwner} is guaranteed to be not {@code null} and vice versa.
*/
private IBinding fBinding;
private final boolean fFixedType;
private IType fType;
@ -52,15 +70,85 @@ public class EvalBinding extends CPPEvaluation {
private boolean fCheckedIsTypeDependent;
public EvalBinding(IBinding binding, IType type) {
fParameterPosition = -1;
fBinding= binding;
fType= type;
fFixedType= type != null;
}
public EvalBinding(ICPPFunction parameterOwner, int parameterPosition, IType type) {
fParameterOwner = parameterOwner;
fParameterPosition = parameterPosition;
fType= type;
fFixedType= type != null;
}
public IBinding getBinding() {
if (fBinding == null) {
// fParameterOwner is guaranteed to be not null.
ICPPParameter[] parameters = fParameterOwner.getParameters();
fBinding = parameters[fParameterPosition];
}
return fBinding;
}
/**
* @return if the binding is a function parameter, returns its position in the parameter list,
* otherwise returns -1
*/
public int getFunctionParameterPosition() {
if (fParameterPosition < 0) {
if (fBinding instanceof CPPParameter) {
fParameterPosition = ((CPPParameter) fBinding).getParameterPosition();
} else {
ICPPFunction parameterOwner = getParameterOwner();
if (parameterOwner != null) {
ICPPParameter[] parameters = fParameterOwner.getParameters();
fParameterPosition = findInArray(parameters, fBinding);
}
}
}
return fParameterPosition;
}
/**
* Finds a given object in an array.
*
* @param array the array to find the object in
* @param obj the object to find
* @return the index of the object in the array, or -1 if the object is not in the array
*/
private static int findInArray(Object[] array, Object obj) {
for (int i = 0; i < array.length; i++) {
if (obj == array[i])
return i;
}
return -1;
}
/**
* @return the function owning the parameter if the binding is a function parameter,
* otherwise {@code null}.
*/
public ICPPFunction getParameterOwner() {
if (fParameterOwner == null && fBinding instanceof ICPPParameter) {
IBinding owner = fBinding.getOwner();
if (owner instanceof ICPPFunction)
fParameterOwner = (ICPPFunction) owner;
}
return fParameterOwner;
}
/**
* @return if the binding is a template parameter, returns its ID, otherwise returns -1
*/
public int getTemplateParameterID() {
// No need to call getBinding method since fBinding cannot be null if the evaluation
// represents a template parameter.
return fBinding instanceof ICPPTemplateParameter ?
((ICPPTemplateParameter) fBinding).getParameterID() : -1;
}
public IType getFixedType() {
return fFixedType ? fType : null;
}
@ -88,19 +176,22 @@ public class EvalBinding extends CPPEvaluation {
IType t= null;
if (fFixedType) {
t = fType;
} else if (fBinding instanceof IEnumerator) {
t= ((IEnumerator) fBinding).getType();
} else if (fBinding instanceof ICPPTemplateNonTypeParameter) {
t= ((ICPPTemplateNonTypeParameter) fBinding).getType();
} else if (fBinding instanceof IVariable) {
t = ((IVariable) fBinding).getType();
} else if (fBinding instanceof ICPPUnknownBinding) {
} else {
IBinding binding = getBinding();
if (binding instanceof IEnumerator) {
t= ((IEnumerator) binding).getType();
} else if (binding instanceof ICPPTemplateNonTypeParameter) {
t= ((ICPPTemplateNonTypeParameter) binding).getType();
} else if (binding instanceof IVariable) {
t = ((IVariable) binding).getType();
} else if (binding instanceof ICPPUnknownBinding) {
return true;
} else if (fBinding instanceof IFunction) {
t= ((IFunction) fBinding).getType();
} else if (binding instanceof IFunction) {
t= ((IFunction) binding).getType();
} else {
return false;
}
}
return CPPTemplates.isDependentType(t);
}
@ -114,6 +205,7 @@ public class EvalBinding extends CPPEvaluation {
}
private boolean computeIsValueDependent() {
// No need to call getBinding() since a function parameter never has an initial value.
if (fBinding instanceof IEnumerator) {
return Value.isDependentValue(((IEnumerator) fBinding).getValue());
}
@ -141,23 +233,24 @@ public class EvalBinding extends CPPEvaluation {
}
private IType computeType(IASTNode point) {
if (fBinding instanceof IEnumerator) {
return ((IEnumerator) fBinding).getType();
IBinding binding = getBinding();
if (binding instanceof IEnumerator) {
return ((IEnumerator) binding).getType();
}
if (fBinding instanceof ICPPTemplateNonTypeParameter) {
IType type= ((ICPPTemplateNonTypeParameter) fBinding).getType();
if (binding instanceof ICPPTemplateNonTypeParameter) {
IType type= ((ICPPTemplateNonTypeParameter) binding).getType();
if (CPPTemplates.isDependentType(type))
return new TypeOfDependentExpression(this);
return prvalueType(type);
}
if (fBinding instanceof IVariable) {
final IType type = ((IVariable) fBinding).getType();
if (binding instanceof IVariable) {
final IType type = ((IVariable) binding).getType();
if (CPPTemplates.isDependentType(type))
return new TypeOfDependentExpression(this);
return SemanticUtil.mapToAST(glvalueType(type), point);
}
if (fBinding instanceof IFunction) {
final IFunctionType type = ((IFunction) fBinding).getType();
if (binding instanceof IFunction) {
final IFunctionType type = ((IFunction) binding).getType();
if (CPPTemplates.isDependentType(type))
return new TypeOfDependentExpression(this);
return SemanticUtil.mapToAST(type, point);
@ -171,6 +264,7 @@ public class EvalBinding extends CPPEvaluation {
return Value.create(this);
IValue value= null;
// No need to call getBinding() since a function parameter never has an initial value.
if (fBinding instanceof IInternalVariable) {
value= ((IInternalVariable) fBinding).getInitialValue(Value.MAX_RECURSION_DEPTH);
} else if (fBinding instanceof IVariable) {
@ -189,7 +283,8 @@ public class EvalBinding extends CPPEvaluation {
if (fBinding instanceof ICPPTemplateNonTypeParameter)
return ValueCategory.PRVALUE;
if (fBinding instanceof IVariable || fBinding instanceof IFunction) {
// fBinding can be null only when the evaluation represents a function parameter.
if (fBinding instanceof IFunction || fBinding instanceof IVariable || fBinding == null) {
return ValueCategory.LVALUE;
}
return ValueCategory.PRVALUE;
@ -197,22 +292,39 @@ public class EvalBinding extends CPPEvaluation {
@Override
public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException {
buffer.putByte(ITypeMarshalBuffer.EVAL_BINDING);
byte firstByte = ITypeMarshalBuffer.EVAL_BINDING;
ICPPFunction parameterOwner = getParameterOwner();
if (parameterOwner != null) {
// A function parameter cannot be marshalled directly. We are storing the owning
// function and the parameter position instead.
buffer.putByte((byte) (ITypeMarshalBuffer.EVAL_BINDING | ITypeMarshalBuffer.FLAG1));
buffer.marshalBinding(parameterOwner);
buffer.putShort((short) getFunctionParameterPosition());
} else {
buffer.putByte(firstByte);
buffer.marshalBinding(fBinding);
}
buffer.marshalType(fFixedType ? fType : null);
}
public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException {
if ((firstByte & ITypeMarshalBuffer.FLAG1) != 0) {
ICPPFunction parameterOwner= (ICPPFunction) buffer.unmarshalBinding();
int parameterPosition= buffer.getShort();
IType type= buffer.unmarshalType();
return new EvalBinding(parameterOwner, parameterPosition, type);
} else {
IBinding binding= buffer.unmarshalBinding();
IType type= buffer.unmarshalType();
return new EvalBinding(binding, type);
}
}
@Override
public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset,
ICPPClassSpecialization within, int maxdepth, IASTNode point) {
IBinding binding = fBinding;
if (fBinding instanceof IEnumerator) {
IBinding binding = getBinding();
if (binding instanceof IEnumerator) {
IEnumerator enumerator = (IEnumerator) binding;
IType originalType = enumerator.getType();
IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point);
@ -221,23 +333,23 @@ public class EvalBinding extends CPPEvaluation {
// TODO(sprigogin): Not sure if following condition is correct.
if (type != originalType || value != originalValue)
return new EvalFixed(type, ValueCategory.PRVALUE, value);
} else if (fBinding instanceof ICPPTemplateNonTypeParameter) {
ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateNonTypeParameter) fBinding);
} else if (binding instanceof ICPPTemplateNonTypeParameter) {
ICPPTemplateArgument argument = tpMap.getArgument((ICPPTemplateNonTypeParameter) binding);
if (argument != null && argument.isNonTypeValue()) {
return argument.getNonTypeEvaluation();
}
// TODO(sprigogin): Do we need something similar for pack expansion?
} else if (fBinding instanceof ICPPUnknownBinding) {
binding = resolveUnknown((ICPPUnknownBinding) fBinding, tpMap, packOffset, within, point);
} else if (fBinding instanceof ICPPMethod) {
IBinding owner = fBinding.getOwner();
} else if (binding instanceof ICPPUnknownBinding) {
binding = resolveUnknown((ICPPUnknownBinding) binding, tpMap, packOffset, within, point);
} else if (binding instanceof ICPPMethod) {
IBinding owner = binding.getOwner();
if (owner instanceof ICPPClassTemplate) {
owner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) owner),
tpMap, packOffset, within, point);
}
if (owner instanceof ICPPClassSpecialization) {
binding = CPPTemplates.createSpecialization((ICPPClassSpecialization) owner,
fBinding, point);
binding, point);
}
}
if (binding == fBinding)
@ -246,20 +358,32 @@ public class EvalBinding extends CPPEvaluation {
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
if (fBinding instanceof IEnumerator) {
return CPPTemplates.determinePackSize(((IEnumerator) fBinding).getValue(), tpMap);
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
int pos = getFunctionParameterPosition();
if (pos >= 0) {
ICPPEvaluation eval = parameterMap.getArgument(pos);
if (eval != null)
return eval;
}
if (fBinding instanceof ICPPTemplateNonTypeParameter) {
return CPPTemplates.determinePackSize((ICPPTemplateNonTypeParameter) fBinding, tpMap);
}
if (fBinding instanceof ICPPUnknownBinding) {
return CPPTemplates.determinePackSize((ICPPUnknownBinding) fBinding, tpMap);
return this;
}
IBinding binding = fBinding;
if (fBinding instanceof ICPPSpecialization) {
binding = ((ICPPSpecialization) fBinding).getSpecializedBinding();
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
IBinding binding = getBinding();
if (binding instanceof IEnumerator) {
return CPPTemplates.determinePackSize(((IEnumerator) binding).getValue(), tpMap);
}
if (binding instanceof ICPPTemplateNonTypeParameter) {
return CPPTemplates.determinePackSize((ICPPTemplateNonTypeParameter) binding, tpMap);
}
if (binding instanceof ICPPUnknownBinding) {
return CPPTemplates.determinePackSize((ICPPUnknownBinding) binding, tpMap);
}
if (binding instanceof ICPPSpecialization) {
binding = ((ICPPSpecialization) binding).getSpecializedBinding();
}
int r = CPPTemplates.PACK_SIZE_NOT_FOUND;
@ -275,6 +399,8 @@ public class EvalBinding extends CPPEvaluation {
@Override
public boolean referencesTemplateParameter() {
// No need to call getBinding method since fBinding cannot be null if the evaluation
// represents a template parameter.
return fBinding instanceof ICPPTemplateParameter;
}
}

View file

@ -189,6 +189,25 @@ public class EvalComma extends CPPEvaluation {
return new EvalComma(args);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation[] args = fArguments;
for (int i = 0; i < fArguments.length; i++) {
ICPPEvaluation arg = fArguments[i].computeForFunctionCall(parameterMap, maxdepth, point);
if (arg != fArguments[i]) {
if (args == fArguments) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
if (args == fArguments)
return this;
return new EvalComma(args);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = CPPTemplates.PACK_SIZE_NOT_FOUND;

View file

@ -94,6 +94,15 @@ public class EvalCompound extends CPPEvaluation {
return new EvalCompound(delegate);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation delegate = fDelegate.computeForFunctionCall(parameterMap, maxdepth, point);
if (delegate == fDelegate)
return this;
return new EvalCompound(delegate);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return fDelegate.determinePackSize(tpMap);

View file

@ -174,7 +174,7 @@ public class EvalConditional extends CPPEvaluation {
} else if (void2 && void3) {
fType= uqt2;
} else {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
return;
}
@ -204,10 +204,10 @@ public class EvalConditional extends CPPEvaluation {
if (cost2.converts() || cost3.converts()) {
if (cost2.converts()) {
if (cost3.converts() || cost2.isAmbiguousUDC()) {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
} else if (cost3.isAmbiguousUDC()) {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
return;
}
@ -222,7 +222,7 @@ public class EvalConditional extends CPPEvaluation {
fType= t3;
fValueCategory= vcat3;
} else {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
return;
}
@ -233,7 +233,7 @@ public class EvalConditional extends CPPEvaluation {
if (fOverload != null) {
fType= ExpressionTypes.typeFromFunctionCall(fOverload);
} else {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
return;
}
@ -248,7 +248,7 @@ public class EvalConditional extends CPPEvaluation {
if (fType == null) {
fType= Conversions.compositePointerType(t2, t3);
if (fType == null) {
fType= new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
fType= ProblemType.UNKNOWN_FOR_EXPRESSION;
}
}
}
@ -336,6 +336,18 @@ public class EvalConditional extends CPPEvaluation {
return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation condition = fCondition.computeForFunctionCall(parameterMap, maxdepth, point);
ICPPEvaluation positive = fPositive == null ?
null : fPositive.computeForFunctionCall(parameterMap, maxdepth, point);
ICPPEvaluation negative = fNegative.computeForFunctionCall(parameterMap, maxdepth, point);
if (condition == fCondition && positive == fPositive && negative == fNegative)
return this;
return new EvalConditional(condition, positive, negative, fPositiveThrows, fNegativeThrows);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = fCondition.determinePackSize(tpMap);

View file

@ -168,6 +168,18 @@ public class EvalFixed extends CPPEvaluation {
return new EvalFixed(type, fValueCategory, value);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation eval = fValue.getEvaluation();
if (eval == null)
return this;
eval = eval.computeForFunctionCall(parameterMap, maxdepth, point);
if (eval == fValue.getEvaluation())
return this;
return new EvalFixed(fType, fValueCategory, Value.create(eval));
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return CPPTemplates.determinePackSize(fValue, tpMap);

View file

@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType;
@ -22,14 +23,15 @@ import java.util.Arrays;
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
@ -119,11 +121,10 @@ public class EvalFunctionCall extends CPPEvaluation {
if (overload != null)
return ExpressionTypes.typeFromFunctionCall(overload);
final ICPPEvaluation arg0 = fArguments[0];
IType t= SemanticUtil.getNestedType(arg0.getTypeOrFunctionSet(point), TDEF | REF | CVTYPE);
if (t instanceof ICPPClassType) {
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}
if (t instanceof IPointerType) {
@ -136,13 +137,16 @@ public class EvalFunctionCall extends CPPEvaluation {
}
return t;
}
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}
@Override
public IValue getValue(IASTNode point) {
// TODO(sprigogin): Simulate execution of a function call if the value is not dependent.
return Value.create(this);
ICPPEvaluation eval = computeForFunctionCall(Value.MAX_RECURSION_DEPTH, point);
if (eval instanceof EvalFixed)
return ((EvalFixed) eval).getValue();
eval = new EvalFixed(getTypeOrFunctionSet(point), PRVALUE, eval.getValue(point));
return Value.create(eval);
}
@Override
@ -151,7 +155,6 @@ public class EvalFunctionCall extends CPPEvaluation {
if (overload != null)
return valueCategoryFromFunctionCall(overload);
IType t= fArguments[0].getTypeOrFunctionSet(point);
if (t instanceof IPointerType) {
t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE);
@ -204,6 +207,70 @@ public class EvalFunctionCall extends CPPEvaluation {
return new EvalFunctionCall(args);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
if (maxdepth == 0)
return EvalFixed.INCOMPLETE;
ICPPEvaluation[] args = fArguments;
for (int i = 0; i < fArguments.length; i++) {
ICPPEvaluation arg = fArguments[i].computeForFunctionCall(parameterMap, maxdepth, point);
if (arg != fArguments[i]) {
if (args == fArguments) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
EvalFunctionCall eval = this;
if (args != fArguments)
eval = new EvalFunctionCall(args);
return eval.computeForFunctionCall(maxdepth - 1, point);
}
private ICPPEvaluation computeForFunctionCall(int maxdepth, IASTNode point) {
if (isValueDependent())
return this;
ICPPFunction function = getOverload(point);
if (function == null) {
if (fArguments[0] instanceof EvalBinding) {
IBinding binding = ((EvalBinding) fArguments[0]).getBinding();
if (binding instanceof ICPPFunction)
function = (ICPPFunction) binding;
}
}
if (function == null)
return this;
ICPPEvaluation eval = CPPFunction.getReturnExpression(function);
if (eval == null)
return EvalFixed.INCOMPLETE;
CPPFunctionParameterMap parameterMap = buildParameterMap(function);
return eval.computeForFunctionCall(parameterMap, maxdepth, point);
}
private CPPFunctionParameterMap buildParameterMap(ICPPFunction function) {
ICPPParameter[] parameters = function.getParameters();
CPPFunctionParameterMap map = new CPPFunctionParameterMap(parameters.length);
int j = 1;
for (int i = 0; i < parameters.length; i++) {
ICPPParameter param = parameters[i];
if (param.isParameterPack()) {
// The parameter pack consumes all remaining arguments.
j = fArguments.length;
} else {
if (j < fArguments.length) {
map.put(i, fArguments[j++]);
} else if (param.hasDefaultValue()) {
IValue value = param.getInitialValue();
map.put(i, value.getEvaluation());
}
}
}
return map;
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = CPPTemplates.PACK_SIZE_NOT_FOUND;

View file

@ -170,6 +170,12 @@ public class EvalFunctionSet extends CPPEvaluation {
return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
return this;
}
/**
* Attempts to resolve the function using the parameters of a function call.
*

View file

@ -309,6 +309,17 @@ public class EvalID extends CPPEvaluation {
return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
if (fFieldOwner == null)
return this;
ICPPEvaluation fieldOwner = fFieldOwner.computeForFunctionCall(parameterMap, maxdepth, point);
if (fieldOwner == fFieldOwner)
return this;
return new EvalID(fieldOwner, fNameOwner, fName, fAddressOf, fQualified, fTemplateArgs);
}
private ICPPEvaluation resolveName(ICPPClassType nameOwner, ICPPTemplateArgument[] templateArgs,
IASTNode point) {
LookupData data = new LookupData(fName, templateArgs, point);

View file

@ -121,6 +121,25 @@ public class EvalInitList extends CPPEvaluation {
return new EvalInitList(clauses);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation[] clauses = fClauses;
for (int i = 0; i < fClauses.length; i++) {
ICPPEvaluation clause = fClauses[i].computeForFunctionCall(parameterMap, maxdepth, point);
if (clause != fClauses[i]) {
if (clauses == fClauses) {
clauses = new ICPPEvaluation[fClauses.length];
System.arraycopy(fClauses, 0, clauses, 0, fClauses.length);
}
clauses[i] = clause;
}
}
if (clauses == fClauses)
return this;
return new EvalInitList(clauses);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = CPPTemplates.PACK_SIZE_NOT_FOUND;

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
@ -177,7 +176,8 @@ public class EvalMemberAccess extends CPPEvaluation {
*/
ICPPEvaluation[] args= { new EvalFixed(type, LVALUE, Value.UNKNOWN) };
ICPPFunction op= CPPSemantics.findOverloadedOperator(point, args, classType, OverloadableOperator.ARROW, LookupMode.NO_GLOBALS);
ICPPFunction op= CPPSemantics.findOverloadedOperator(point, args, classType,
OverloadableOperator.ARROW, LookupMode.NO_GLOBALS);
if (op == null)
break;
@ -196,7 +196,7 @@ public class EvalMemberAccess extends CPPEvaluation {
if (CPPTemplates.isDependentType(type))
return returnUnnamed ? CPPUnknownMemberClass.createUnnamedInstance() : null;
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}
@Override
@ -334,6 +334,12 @@ public class EvalMemberAccess extends CPPEvaluation {
return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
return this;
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return CPPTemplates.determinePackSize(fOwnerType, tpMap);

View file

@ -165,6 +165,27 @@ public class EvalTypeId extends CPPEvaluation {
return new EvalTypeId(type, args);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation[] args = fArguments;
if (fArguments != null) {
for (int i = 0; i < fArguments.length; i++) {
ICPPEvaluation arg = fArguments[i].computeForFunctionCall(parameterMap, maxdepth, point);
if (arg != fArguments[i]) {
if (args == fArguments) {
args = new ICPPEvaluation[fArguments.length];
System.arraycopy(fArguments, 0, args, 0, fArguments.length);
}
args[i] = arg;
}
}
}
if (args == fArguments)
return this;
return new EvalTypeId(fInputType, args);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = CPPTemplates.determinePackSize(fInputType, tpMap);

View file

@ -217,7 +217,7 @@ public class EvalUnary extends CPPEvaluation {
if (type instanceof ISemanticProblem) {
return type;
}
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
return ProblemType.UNKNOWN_FOR_EXPRESSION;
case op_noexcept:
case op_not:
return CPPBasicType.BOOLEAN;
@ -324,6 +324,16 @@ public class EvalUnary extends CPPEvaluation {
return new EvalUnary(fOperator, argument, aoqn);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
ICPPEvaluation argument = fArgument.computeForFunctionCall(parameterMap, maxdepth, point);
if (argument == fArgument)
return this;
return new EvalUnary(fOperator, argument, fAddressOfQualifiedNameBinding);
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return fArgument.determinePackSize(tpMap);

View file

@ -190,6 +190,12 @@ public class EvalUnaryTypeID extends CPPEvaluation {
return new EvalUnaryTypeID(fOperator, type);
}
@Override
public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap,
int maxdepth, IASTNode point) {
return this;
}
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
return CPPTemplates.determinePackSize(fOrigType, tpMap);

View file

@ -44,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IScope.ScopeLookupData;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -336,12 +337,12 @@ public class LookupData extends ScopeLookupData {
return false;
}
public boolean hasTypeOrMemberFunctionResult() {
public boolean hasTypeOrMemberFunctionOrVariableResult() {
if (foundItems == null)
return false;
if (foundItems instanceof Object[]) {
for (Object item : (Object[]) foundItems) {
if (item instanceof ICPPMethod || item instanceof IType) {
if (item instanceof ICPPMethod || item instanceof IType || item instanceof IVariable) {
return true;
}
}

View file

@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IValue;
@ -636,8 +637,16 @@ public class TemplateArgumentDeduction {
if (deducedArg != null) {
deducedArg= CPPTemplates.instantiateArgument(deducedArg, tpMap, -1, null, point);
if (deducedArg != null) {
if (deducedArg instanceof CPPTemplateTypeArgument) {
CPPTemplateTypeArgument deducedTypeArg = (CPPTemplateTypeArgument) deducedArg;
if (!(deducedTypeArg.getTypeValue() instanceof ISemanticProblem)) {
tpMap.put(tpar, deducedArg);
}
} else {
// TODO: Check for problems in non-type or template template parameters?
tpMap.put(tpar, deducedArg);
}
}
}
}
if (deducedArg == null)

View file

@ -8,6 +8,7 @@
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -255,6 +256,16 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
}
if (eval instanceof EvalBinding) {
EvalBinding e= (EvalBinding) eval;
ICPPFunction parameterOwner = e.getParameterOwner();
if (parameterOwner != null) {
IType b = e.getFixedType();
IBinding a2 = getCompositeBinding((IIndexFragmentBinding) parameterOwner);
IType b2 = getCompositeType(b);
if (parameterOwner != a2 || b != b2) {
int parameterPosition = e.getFunctionParameterPosition();
e= new EvalBinding((ICPPFunction) a2, parameterPosition, b2);
}
} else {
IBinding a = e.getBinding();
IType b = e.getFixedType();
@ -262,6 +273,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
IType b2 = getCompositeType(b);
if (a != a2 || b != b2)
e= new EvalBinding(a2, b2);
}
return e;
}
if (eval instanceof EvalComma) {

View file

@ -27,8 +27,8 @@ abstract class CompositeCPPBinding extends CompositeIndexBinding implements ICPP
public String[] getQualifiedName() {
try {
return ((ICPPBinding) rbinding).getQualifiedName();
} catch(DOMException de) {
CCorePlugin.log(de);
} catch (DOMException e) {
CCorePlugin.log(e);
return new String[0];
}
}

View file

@ -18,10 +18,13 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction, ICPPComputableFunction {
public CompositeCPPFunction(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
@ -42,6 +45,11 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
return ((ICPPFunction) rbinding).isMutable();
}
@Override
public boolean isConstexpr() {
return ((ICPPFunction) rbinding).isConstexpr();
}
@Override
public IScope getFunctionScope() {
return null;
@ -129,4 +137,9 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction {
}
return result;
}
@Override
public ICPPEvaluation getReturnExpression() {
return CPPFunction.getReturnExpression((ICPPFunction) rbinding);
}
}

View file

@ -73,9 +73,9 @@ public class ExpressionEvaluator {
if (LA() == IToken.tQUESTION) {
consume();
long r2 = expression();
if (LA() == IToken.tCOLON)
if (LA() == IToken.tCOLON) {
consume();
else {
} else {
throw new EvalException(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION, null);
}
long r3 = conditionalExpression();
@ -139,12 +139,13 @@ public class ExpressionEvaluator {
for (int t = LA(); t == IToken.tEQUAL || t == IToken.tNOTEQUAL; t = LA()) {
consume();
long r2 = relationalExpression();
if (t == IToken.tEQUAL)
if (t == IToken.tEQUAL) {
r1 = (r1 == r2) ? 1 : 0;
else
} else {
// t == tNOTEQUAL
r1 = (r1 != r2) ? 1 : 0;
}
}
return r1;
}
@ -179,12 +180,13 @@ public class ExpressionEvaluator {
for (int t = LA(); t == IToken.tSHIFTL || t == IToken.tSHIFTR; t = LA()) {
consume();
long r2 = additiveExpression();
if (t == IToken.tSHIFTL)
if (t == IToken.tSHIFTL) {
r1 = r1 << r2;
else
} else {
// t == tSHIFTR
r1 = r1 >> r2;
}
}
return r1;
}
@ -193,12 +195,13 @@ public class ExpressionEvaluator {
for (int t = LA(); t == IToken.tPLUS || t == IToken.tMINUS; t = LA()) {
consume();
long r2 = multiplicativeExpression();
if (t == IToken.tPLUS)
if (t == IToken.tPLUS) {
r1 = r1 + r2;
else
} else {
// t == tMINUS
r1 = r1 - r2;
}
}
return r1;
}
@ -207,13 +210,14 @@ public class ExpressionEvaluator {
for (int t = LA(); t == IToken.tSTAR || t == IToken.tDIV || t == IToken.tMOD; t = LA()) {
consume();
long r2 = unaryExpression();
if (t == IToken.tSTAR)
if (t == IToken.tSTAR) {
r1 = r1 * r2;
else if (r2 != 0) {
if (t == IToken.tDIV)
} else if (r2 != 0) {
if (t == IToken.tDIV) {
r1 = r1 / r2;
else
} else {
r1 = r1 % r2; //tMOD
}
} else {
throw new EvalException(IProblem.SCANNER_DIVIDE_BY_ZERO, null);
}

View file

@ -227,10 +227,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* 135.0 - Changed marshalling of EvalUnary, bug 391001.
* 136.0 - Extended CPPTemplateTypeArgument to include the original type, bug 392278.
* 137.0 - Fixed serialization of very large types and template arguments, bug 392278.
* 138.0 - Constexpr functions, bug 395238.
*/
private static final int MIN_SUPPORTED_VERSION= version(137, 0);
private static final int MAX_SUPPORTED_VERSION= version(137, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(137, 0);
private static final int MIN_SUPPORTED_VERSION= version(138, 0);
private static final int MAX_SUPPORTED_VERSION= version(138, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(138, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

@ -304,8 +304,9 @@ abstract public class PDOMWriter {
} catch (AssertionError e) {
th= e;
} finally {
// Because the caller holds a read-lock, the result cache of the index is never cleared.
// ==> Before releasing the lock for the last time in this ast, we clear the result cache.
// Because the caller holds a read-lock, the result cache of the index is never
// cleared. Before releasing the lock for the last time in this AST, we clear
// the result cache.
if (i == data.fSelectedFiles.length - 1) {
data.fIndex.clearResultCache();
}

View file

@ -78,6 +78,7 @@ public class Database {
public static final int PTR_SIZE = 4; // size of a pointer in the database in bytes
public static final int TYPE_SIZE = 2 + PTR_SIZE; // size of a type in the database in bytes
public static final int VALUE_SIZE = TYPE_SIZE; // size of a value in the database in bytes
public static final int EVALUATION_SIZE = TYPE_SIZE; // size of an evaluation in the database in bytes
public static final int ARGUMENT_SIZE = TYPE_SIZE; // size of a template argument in the database in bytes
public static final long MAX_DB_SIZE= ((long) 1 << (Integer.SIZE + BLOCK_SIZE_DELTA_BITS));

View file

@ -26,8 +26,8 @@ import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
@ -80,7 +80,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
} else if (binding == null) {
putByte(NULL_TYPE);
} else {
PDOMBinding pb= fLinkage.addTypeBinding(binding);
PDOMNode pb= fLinkage.addTypeBinding(binding);
if (pb == null) {
putByte(UNSTORABLE_TYPE);
} else {

View file

@ -115,7 +115,7 @@ public class FindBinding {
public PDOMBinding getResult() {
return fResult;
}
// IPDOMVisitor
@Override
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof PDOMBinding) {
@ -127,7 +127,7 @@ public class FindBinding {
}
return false; /* do not visit children of node */
}
// IPDOMVisitor
@Override
public void leave(IPDOMNode node) throws CoreException {
}

View file

@ -20,7 +20,6 @@ import org.eclipse.core.runtime.CoreException;
* @author Bryan Wilkinson
*/
public interface IPDOMOverloader {
/**
* @return the signature hash for this PDOM element, which will be unique
* for all sibling IPDOMOverloaders with the same name.

View file

@ -423,7 +423,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return map;
}
public abstract PDOMBinding addTypeBinding(IBinding type) throws CoreException;
public abstract PDOMBinding addTypeBinding(IBinding binding) throws CoreException;
public abstract IType unmarshalType(ITypeMarshalBuffer buffer) throws CoreException;
public abstract IBinding unmarshalBinding(ITypeMarshalBuffer buffer) throws CoreException;
public abstract ISerializableEvaluation unmarshalEvaluation(ITypeMarshalBuffer typeMarshalBuffer) throws CoreException;
@ -633,9 +633,41 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
public IValue loadValue(long offset) throws CoreException {
TypeMarshalBuffer buffer = loadBuffer(offset, Database.VALUE_SIZE);
if (buffer == null)
return null;
return buffer.unmarshalValue();
}
public void storeEvaluation(long offset, ISerializableEvaluation eval) throws CoreException {
final Database db= getDB();
deleteEvaluation(db, offset);
storeEvaluation(db, offset, eval);
}
private void storeEvaluation(Database db, long offset, ISerializableEvaluation eval) throws CoreException {
if (eval != null) {
TypeMarshalBuffer bc= new TypeMarshalBuffer(this);
bc.marshalEvaluation(eval, true);
storeBuffer(db, offset, bc, Database.EVALUATION_SIZE);
}
}
private void deleteEvaluation(Database db, long offset) throws CoreException {
deleteSerializedData(db, offset, Database.EVALUATION_SIZE);
}
public ISerializableEvaluation loadEvaluation(long offset) throws CoreException {
TypeMarshalBuffer buffer = loadBuffer(offset, Database.EVALUATION_SIZE);
if (buffer == null)
return null;
return buffer.unmarshalEvaluation();
}
private TypeMarshalBuffer loadBuffer(long offset, int size) throws CoreException {
final Database db= getDB();
final byte firstByte= db.getByte(offset);
byte[] data= null;
byte[] data;
switch (firstByte) {
case TypeMarshalBuffer.INDIRECT_TYPE:
data = loadLinkedSerializedData(db, offset + 1);
@ -643,11 +675,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
case TypeMarshalBuffer.NULL_TYPE:
return null;
default:
data= new byte[Database.VALUE_SIZE];
data= new byte[size];
db.getBytes(offset, data);
break;
}
return new TypeMarshalBuffer(this, data).unmarshalValue();
return new TypeMarshalBuffer(this, data);
}
public IIndexScope[] getInlineNamespaces() {

View file

@ -211,7 +211,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
try {
Database db = linkage.getDB();
long bindingRec = db.getRecPtr(record + BINDING_REC_OFFSET);
PDOMBinding binding = linkage.getBinding(bindingRec);
IPDOMBinding binding = linkage.getBinding(bindingRec);
return binding != null ? binding.getNameCharArray() : null;
} catch (CoreException e) {
CCorePlugin.log(e);

View file

@ -80,7 +80,9 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
@Override
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof IFunction) {
if (!(newBinding instanceof IFunction))
return;
IFunction func= (IFunction) newBinding;
IFunctionType newType;
IParameter[] newParams;
@ -97,7 +99,6 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
}
getDB().putByte(record + ANNOTATIONS, newAnnotation);
}
}
private void setType(PDOMLinkage linkage, IFunctionType ft) throws CoreException {
linkage.storeType(record + FUNCTION_TYPE, ft);
@ -109,7 +110,7 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
db.putInt(record + NUM_PARAMS, params.length);
db.putRecPtr(record + FIRST_PARAM, 0);
PDOMCParameter next= null;
for (int i= params.length-1; i >= 0; --i) {
for (int i= params.length; --i >= 0;) {
next= new PDOMCParameter(linkage, this, params[i], next);
}
db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord());
@ -134,8 +135,8 @@ class PDOMCFunction extends PDOMBinding implements IFunction {
public IFunctionType getType() {
try {
return (IFunctionType) getLinkage().loadType(record + FUNCTION_TYPE);
} catch(CoreException ce) {
CCorePlugin.log(ce);
} catch (CoreException e) {
CCorePlugin.log(e);
return new ProblemFunctionType(ISemanticProblem.TYPE_NOT_PERSISTED);
}
}

View file

@ -31,7 +31,6 @@ import org.eclipse.core.runtime.CoreException;
* Binding for a function parameter in the index.
*/
final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding {
private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE;
private static final int FLAG_OFFSET = NEXT_PARAM + Database.PTR_SIZE;
@SuppressWarnings("hiding")
@ -138,7 +137,6 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
return getNodeType();
}
@Override
public void delete(PDOMLinkage linkage) throws CoreException {
PDOMCParameter p= this;
@ -193,7 +191,6 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
return defValue;
}
@Override
public boolean isExtern() {
return false;

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@ -34,12 +35,13 @@ public class CPPFindBinding extends FindBinding {
public CPPBindingBTreeComparator(PDOMLinkage linkage) {
super(linkage);
}
@Override
public int compare(long record1, long record2) throws CoreException {
int cmp = super.compare(record1, record2);
if (cmp == 0) {
PDOMBinding binding1 = linkage.getBinding(record1);
PDOMBinding binding2 = linkage.getBinding(record2);
IPDOMBinding binding1 = linkage.getBinding(record1);
IPDOMBinding binding2 = linkage.getBinding(record2);
if (binding1 instanceof IPDOMOverloader && binding2 instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader) binding1).getSignatureHash();
int ty2 = ((IPDOMOverloader) binding2).getSignatureHash();
@ -66,7 +68,7 @@ public class CPPFindBinding extends FindBinding {
int c1 = PDOMNode.getNodeType(fLinkage.getDB(), record);
int c2= fConstant;
if (c1 == c2) {
PDOMBinding binding = fLinkage.getBinding(record);
IPDOMBinding binding = fLinkage.getBinding(record);
if (binding instanceof IPDOMOverloader) {
c1 = ((IPDOMOverloader) binding).getSignatureHash();
c2= fSigHash;

View file

@ -8,6 +8,7 @@
*
* Contributors:
* Thomas Corbat (IFS) - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -15,7 +16,10 @@ 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.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
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.PDOMNode;
@ -24,39 +28,38 @@ import org.eclipse.core.runtime.CoreException;
/**
* PDOM binding for alias template.
*/
class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate {
class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate, IPDOMCPPTemplateParameterOwner {
private static final int ALIASED_TYPE_SIZE = Database.TYPE_SIZE;
private static final int TEMPLATE_PARAMS_SIZE = PDOMCPPTemplateTemplateParameter.RECORD_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + ALIASED_TYPE_SIZE + TEMPLATE_PARAMS_SIZE;
private static final int ALIASED_TYPE_OFFSET = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int TEMPLATE_PARAMS_OFFSET = ALIASED_TYPE_OFFSET + ALIASED_TYPE_SIZE;
private static final int ALIASED_TYPE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int TEMPLATE_PARAMS = ALIASED_TYPE + ALIASED_TYPE_SIZE;
private volatile IPDOMCPPTemplateParameter[] parameters;
public PDOMCPPAliasTemplate(PDOMCPPLinkage linkage, PDOMNode parent,
ICPPAliasTemplate templateAlias) throws CoreException, DOMException {
super(linkage, parent, templateAlias.getNameCharArray());
setTemplateParameters(linkage, templateAlias.getTemplateParameters());
setType(linkage, templateAlias.getType());
public PDOMCPPAliasTemplate(PDOMCPPLinkage linkage, PDOMNode parent, ICPPAliasTemplate template)
throws CoreException, DOMException {
super(linkage, parent, template.getNameCharArray());
final ICPPTemplateParameter[] origParams= template.getTemplateParameters();
parameters = PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
final Database db = getDB();
long rec= PDOMTemplateParameterArray.putArray(db, parameters);
db.putRecPtr(record + TEMPLATE_PARAMS, rec);
linkage.new ConfigureAliasTemplate(template, this);
}
public PDOMCPPAliasTemplate(PDOMCPPLinkage linkage, long record) {
super(linkage, record);
}
private void setTemplateParameters(PDOMCPPLinkage linkage,
final ICPPTemplateParameter[] origParams) throws CoreException, DOMException {
parameters = PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
final Database db = getDB();
long rec= PDOMTemplateParameterArray.putArray(db, parameters);
db.putRecPtr(record + TEMPLATE_PARAMS_OFFSET, rec);
linkage.new ConfigureTemplateParameters(origParams, parameters);
public void initData(IType aliasedType) {
try {
getLinkage().storeType(record + ALIASED_TYPE, aliasedType);
} catch (CoreException e) {
CCorePlugin.log(e);
}
private void setType(PDOMCPPLinkage linkage, IType aliasedType) throws CoreException {
linkage.storeType(record + ALIASED_TYPE_OFFSET, aliasedType);
}
@Override
@ -74,11 +77,11 @@ class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate {
}
@Override
public ICPPTemplateParameter[] getTemplateParameters() {
public IPDOMCPPTemplateParameter[] getTemplateParameters() {
if (parameters == null) {
try {
Database db = getDB();
long rec= db.getRecPtr(record + TEMPLATE_PARAMS_OFFSET);
long rec= db.getRecPtr(record + TEMPLATE_PARAMS);
if (rec == 0) {
parameters= IPDOMCPPTemplateParameter.EMPTY_ARRAY;
} else {
@ -95,7 +98,7 @@ class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate {
@Override
public IType getType() {
try {
return getLinkage().loadType(record + ALIASED_TYPE_OFFSET);
return getLinkage().loadType(record + ALIASED_TYPE);
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
@ -115,4 +118,27 @@ class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate {
}
return null;
}
@Override
public ICPPTemplateParameter adaptTemplateParameter(ICPPTemplateParameter param) {
// Template parameters are identified by their position in the parameter list.
int pos = param.getParameterPosition();
ICPPTemplateParameter[] pars = getTemplateParameters();
if (pars == null || pos >= pars.length)
return null;
ICPPTemplateParameter result= pars[pos];
if (param instanceof ICPPTemplateTypeParameter) {
if (result instanceof ICPPTemplateTypeParameter)
return result;
} else if (param instanceof ICPPTemplateNonTypeParameter) {
if (result instanceof ICPPTemplateNonTypeParameter)
return result;
} else if (param instanceof ICPPTemplateTemplateParameter) {
if (result instanceof ICPPTemplateTemplateParameter)
return result;
}
return null;
}
}

View file

@ -46,7 +46,7 @@ public abstract class PDOMCPPBinding extends PDOMBinding implements ICPPBinding
@Override
public final boolean isGloballyQualified() throws DOMException {
// local stuff is not stored in the index.
// Local stuff is not stored in the index.
return true;
}
}

View file

@ -32,7 +32,6 @@ import org.eclipse.core.runtime.CoreException;
* Result of instantiating a class template.
*/
class PDOMCPPClassInstance extends PDOMCPPClassSpecialization implements ICPPTemplateInstance {
private static final int ARGUMENTS = PDOMCPPClassSpecialization.RECORD_SIZE + 0;
/**

View file

@ -64,8 +64,9 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType
super(linkage, parent, template);
final Database db = getDB();
final ICPPTemplateParameter[] origParams= template.getTemplateParameters();
final IPDOMCPPTemplateParameter[] params = PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
ICPPTemplateParameter[] origParams= template.getTemplateParameters();
IPDOMCPPTemplateParameter[] params =
PDOMTemplateParameterArray.createPDOMTemplateParameters(linkage, this, origParams);
long rec= PDOMTemplateParameterArray.putArray(db, params);
db.putRecPtr(record + PARAMETERS, rec);
db.putShort(record + RELEVANT_PARAMETERS, (short) params.length);
@ -247,8 +248,9 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType
// exclude other kinds of class templates
if (type instanceof ICPPClassTemplatePartialSpecialization ||
type instanceof ICPPTemplateTemplateParameter ||
type instanceof ICPPClassSpecialization)
type instanceof ICPPClassSpecialization) {
return false;
}
ICPPClassType ctype= (ICPPClassType) type;
if (ctype.getKey() != getKey())

View file

@ -40,7 +40,6 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPClassTemplatePartialSpecialization extends PDOMCPPClassTemplate
implements IPDOMPartialSpecialization, ICPPSpecialization, IPDOMOverloader {
private static final int ARGUMENTS = PDOMCPPClassTemplate.RECORD_SIZE + 0;
private static final int SIGNATURE_HASH = PDOMCPPClassTemplate.RECORD_SIZE + 4;
private static final int PRIMARY = PDOMCPPClassTemplate.RECORD_SIZE + 8;

View file

@ -31,7 +31,6 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPClassTemplatePartialSpecializationSpecialization extends PDOMCPPClassTemplateSpecialization
implements IPDOMPartialSpecialization, ICPPClassTemplatePartialSpecializationSpecialization {
private static final int PRIMARY_TEMPLATE = PDOMCPPClassTemplateSpecialization.RECORD_SIZE;
private static final int ARGUMENTS = PDOMCPPClassTemplateSpecialization.RECORD_SIZE+4;
private static final int NEXT_PARTIAL = PDOMCPPClassTemplateSpecialization.RECORD_SIZE+8;
@ -48,7 +47,6 @@ class PDOMCPPClassTemplatePartialSpecializationSpecialization extends PDOMCPPCla
getDB().putRecPtr(record + PRIMARY_TEMPLATE, primary.getRecord());
linkage.new ConfigurePartialSpecialization(this, partial);
}
public PDOMCPPClassTemplatePartialSpecializationSpecialization(PDOMLinkage linkage, long bindingRecord) {

View file

@ -40,7 +40,6 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization
implements ICPPClassTemplate, ICPPInstanceCache {
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPClassSpecialization.RECORD_SIZE;

View file

@ -20,7 +20,7 @@ import org.eclipse.core.runtime.CoreException;
class PDOMCPPConstructor extends PDOMCPPMethod implements ICPPConstructor {
public PDOMCPPConstructor(PDOMLinkage linkage, PDOMNode parent, ICPPConstructor method)
public PDOMCPPConstructor(PDOMCPPLinkage linkage, PDOMNode parent, ICPPConstructor method)
throws CoreException, DOMException {
super(linkage, parent, method);
}

View file

@ -24,6 +24,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -37,25 +40,24 @@ import org.eclipse.core.runtime.CoreException;
/**
* Binding for c++ functions in the index.
*/
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader {
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader, ICPPComputableFunction {
private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9;
private static final short ANNOT_IS_CONSTEXPR = 10;
/**
* Offset of total number of function parameters (relative to the
* beginning of the record).
* Offset of total number of function parameters (relative to the beginning of the record).
*/
private static final int NUM_PARAMS = PDOMCPPBinding.RECORD_SIZE;
/**
* Offset of pointer to the first parameter of this function (relative to
* the beginning of the record).
* Offset of pointer to the first parameter of this function (relative to the beginning of the record).
*/
private static final int FIRST_PARAM = NUM_PARAMS + 4;
/**
* Offset of pointer to the function type record of this function (relative to
* the beginning of the record).
* Offset of pointer to the function type record of this function (relative to the beginning of the
* record).
*/
protected static final int FUNCTION_TYPE = FIRST_PARAM + Database.PTR_SIZE;
@ -74,27 +76,31 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
*/
private static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short
private static final int REQUIRED_ARG_COUNT = ANNOTATION + 2;
/** Offset of the number of the required arguments. */
private static final int REQUIRED_ARG_COUNT = ANNOTATION + 2; // short
/** Offset of the return expression for constexpr functions. */
private static final int RETURN_EXPRESSION = REQUIRED_ARG_COUNT + 2; // Database.EVALUATION_SIZE
/**
* The size in bytes of a PDOMCPPFunction record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = REQUIRED_ARG_COUNT + 4;
protected static final int RECORD_SIZE = RETURN_EXPRESSION + Database.EVALUATION_SIZE;
private short fAnnotation = -1;
private int fRequiredArgCount = -1;
private ICPPFunctionType fType; // No need for volatile, all fields of ICPPFunctionTypes are final.
public PDOMCPPFunction(PDOMLinkage linkage, PDOMNode parent, ICPPFunction function, boolean setTypes) throws CoreException, DOMException {
public PDOMCPPFunction(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction function,
boolean setTypes) throws CoreException, DOMException {
super(linkage, parent, function.getNameCharArray());
Database db = getDB();
Integer sigHash = IndexCPPSignatureUtil.getSignatureHash(function);
getDB().putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0);
db.putShort(record + ANNOTATION, getAnnotation(function));
db.putInt(record + REQUIRED_ARG_COUNT, function.getRequiredArgumentCount());
db.putShort(record + REQUIRED_ARG_COUNT, (short) function.getRequiredArgumentCount());
if (setTypes) {
initData(function.getType(), function.getParameters(), extractExceptionSpec(function));
linkage.new ConfigureFunction(function, this);
}
}
@ -106,14 +112,19 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
if (function.isDeleted()) {
annot |= (1 << ANNOT_IS_DELETED);
}
if (function.isConstexpr()) {
annot |= (1 << ANNOT_IS_CONSTEXPR);
}
return (short) annot;
}
public void initData(ICPPFunctionType ftype, ICPPParameter[] params, IType[] exceptionSpec) {
public void initData(ICPPFunctionType ftype, ICPPParameter[] params, IType[] exceptionSpec,
ICPPEvaluation returnExpression) {
try {
setType(ftype);
setParameters(params);
storeExceptionSpec(exceptionSpec);
getLinkage().storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
} catch (CoreException e) {
CCorePlugin.log(e);
}
@ -121,7 +132,9 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
@Override
public void update(final PDOMLinkage linkage, IBinding newBinding) throws CoreException {
if (newBinding instanceof ICPPFunction) {
if (!(newBinding instanceof ICPPFunction))
return;
ICPPFunction func = (ICPPFunction) newBinding;
ICPPFunctionType newType;
ICPPParameter[] newParams;
@ -163,7 +176,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
final Database db = getDB();
db.putShort(record + ANNOTATION, newAnnotation);
fAnnotation = newAnnotation;
db.putInt(record + REQUIRED_ARG_COUNT, requiredCount);
db.putShort(record + REQUIRED_ARG_COUNT, (short) requiredCount);
fRequiredArgCount = requiredCount;
long oldRec = db.getRecPtr(record + EXCEPTION_SPEC);
@ -171,7 +184,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
if (oldRec != 0) {
PDOMCPPTypeList.clearTypes(this, oldRec);
}
}
linkage.storeEvaluation(record + RETURN_EXPRESSION, CPPFunction.getReturnExpression(func));
}
private void storeExceptionSpec(IType[] exceptionSpec) throws CoreException {
@ -244,7 +257,7 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
public int getRequiredArgumentCount() {
if (fRequiredArgCount == -1) {
try {
fRequiredArgCount= getDB().getInt(record + REQUIRED_ARG_COUNT);
fRequiredArgCount = getDB().getShort(record + REQUIRED_ARG_COUNT);
} catch (CoreException e) {
fRequiredArgCount = 0;
}
@ -322,6 +335,11 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
return false;
}
@Override
public boolean isConstexpr() {
return getBit(getAnnotation(), ANNOT_IS_CONSTEXPR);
}
@Override
public boolean isDeleted() {
return getBit(getAnnotation(), ANNOT_IS_DELETED);
@ -376,8 +394,8 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
int mySM = a.getSignatureHash();
int otherSM = bb.getSignatureHash();
return mySM == otherSM ? 0 : mySM < otherSM ? -1 : 1;
} catch(CoreException ce) {
CCorePlugin.log(ce);
} catch (CoreException e) {
CCorePlugin.log(e);
}
} else {
assert false;
@ -395,4 +413,17 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
return null;
}
}
@Override
public ICPPEvaluation getReturnExpression() {
if (!isConstexpr())
return null;
try {
return (ICPPEvaluation) getLinkage().loadEvaluation(record + RETURN_EXPRESSION);
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
}

View file

@ -23,6 +23,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
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.PDOMBinding;
@ -34,7 +37,8 @@ import org.eclipse.core.runtime.CoreException;
/**
* Binding for function specialization in the index.
*/
class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICPPFunction {
class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
implements ICPPFunction, ICPPComputableFunction {
/**
* Offset of total number of function parameters (relative to the beginning of the record).
*/
@ -59,24 +63,29 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
/**
* Offset of annotation information (relative to the beginning of the record).
*/
protected static final int ANNOTATION_OFFSET = EXCEPTION_SPEC + Database.PTR_SIZE; // short
protected static final int ANNOTATION = EXCEPTION_SPEC + Database.PTR_SIZE; // short
private static final int REQUIRED_ARG_COUNT_OFFSET= ANNOTATION_OFFSET + 2;
/** Offset of the number of the required arguments. */
private static final int REQUIRED_ARG_COUNT = ANNOTATION + 2; // short
/** Offset of the return expression for constexpr functions. */
private static final int RETURN_EXPRESSION = REQUIRED_ARG_COUNT + 2; // Database.EVALUATION_SIZE
/**
* The size in bytes of a PDOMCPPFunction record in the database.
* The size in bytes of a PDOMCPPFunctionSpecialization record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = REQUIRED_ARG_COUNT_OFFSET + 4;
protected static final int RECORD_SIZE = RETURN_EXPRESSION + Database.EVALUATION_SIZE;
private static final short ANNOT_PARAMETER_PACK = 8;
private static final short ANNOT_IS_DELETED = 9;
private static final short ANNOT_IS_CONSTEXPR = 10;
private ICPPFunctionType fType; // No need for volatile, all fields of ICPPFunctionTypes are final.
private short fAnnotation= -1;
private int fRequiredArgCount= -1;
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction astFunction, PDOMBinding specialized) throws CoreException {
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
PDOMBinding specialized) throws CoreException {
super(linkage, parent, (ICPPSpecialization) astFunction, specialized);
Database db = getDB();
@ -98,7 +107,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
db.putRecPtr(record + FIRST_PARAM, 0);
PDOMCPPParameter origPar= null;
PDOMCPPParameterSpecialization next= null;
for (int i= length-1; i >= 0; --i) {
for (int i= length; --i >= 0;) {
// There may be fewer or less original parameters, because of parameter packs.
if (i < origAstParams.length - 1) {
// Normal case
@ -112,8 +121,12 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
db.putRecPtr(record + FIRST_PARAM, next == null ? 0 : next.getRecord());
}
fAnnotation = getAnnotation(astFunction);
db.putShort(record + ANNOTATION_OFFSET, fAnnotation);
db.putInt(record + REQUIRED_ARG_COUNT_OFFSET, astFunction.getRequiredArgumentCount());
db.putShort(record + ANNOTATION, fAnnotation);
db.putShort(record + REQUIRED_ARG_COUNT , (short) astFunction.getRequiredArgumentCount());
ICPPEvaluation returnExpression = CPPFunction.getReturnExpression(astFunction);
if (returnExpression != null) {
linkage.storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
}
long typelist= 0;
if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) {
// Don't store the exception specification, it is computed on demand.
@ -131,6 +144,9 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
if (astFunction.isDeleted()) {
annot |= (1 << ANNOT_IS_DELETED);
}
if (astFunction.isConstexpr()) {
annot |= (1 << ANNOT_IS_CONSTEXPR);
}
return (short) annot;
}
@ -156,7 +172,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
private short readAnnotation() {
if (fAnnotation == -1) {
try {
fAnnotation= getDB().getShort(record + ANNOTATION_OFFSET);
fAnnotation= getDB().getShort(record + ANNOTATION);
} catch (CoreException e) {
fAnnotation= 0;
}
@ -205,8 +221,8 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
if (fType == null) {
try {
fType= (ICPPFunctionType) getLinkage().loadType(record + FUNCTION_TYPE);
} catch(CoreException ce) {
CCorePlugin.log(ce);
} catch (CoreException e) {
CCorePlugin.log(e);
fType= new ProblemFunctionType(ISemanticProblem.TYPE_NOT_PERSISTED);
}
}
@ -219,6 +235,11 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
return false;
}
@Override
public boolean isConstexpr() {
return getBit(readAnnotation(), ANNOT_IS_CONSTEXPR);
}
@Override
public boolean isExtern() {
return getBit(readAnnotation(), PDOMCAnnotation.EXTERN_OFFSET);
@ -254,7 +275,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
public int getRequiredArgumentCount() {
if (fRequiredArgCount == -1) {
try {
fRequiredArgCount= getDB().getInt(record + REQUIRED_ARG_COUNT_OFFSET);
fRequiredArgCount= getDB().getShort(record + REQUIRED_ARG_COUNT );
} catch (CoreException e) {
fRequiredArgCount= 0;
}
@ -300,4 +321,17 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
return null;
}
}
@Override
public ICPPEvaluation getReturnExpression() {
if (!isConstexpr())
return null;
try {
return (ICPPEvaluation) getLinkage().loadEvaluation(record + RETURN_EXPRESSION);
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
}

View file

@ -35,7 +35,6 @@ import org.eclipse.core.runtime.CoreException;
*/
class PDOMCPPFunctionTemplate extends PDOMCPPFunction
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, IPDOMCPPTemplateParameterOwner {
private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE;
@SuppressWarnings("hiding")

View file

@ -42,6 +42,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
@ -61,8 +63,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
@ -79,21 +79,23 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplateInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameterPackType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplateInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownMember;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinary;
@ -219,6 +221,29 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
class ConfigureFunction implements Runnable {
private final PDOMCPPFunction fFunction;
private final ICPPFunctionType fOriginalFunctionType;
private final ICPPParameter[] fOriginalParameters;
private final IType[] fOriginalExceptionSpec;
private final ICPPEvaluation fReturnExpression;
public ConfigureFunction(ICPPFunction original, PDOMCPPFunction function) throws DOMException {
fFunction = function;
fOriginalFunctionType= original.getType();
fOriginalParameters= original.getParameters();
fOriginalExceptionSpec= function.extractExceptionSpec(original);
fReturnExpression= CPPFunction.getReturnExpression(original);
postProcesses.add(this);
}
@Override
public void run() {
fFunction.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec,
fReturnExpression);
}
}
class ConfigureFunctionTemplate implements Runnable {
private final PDOMCPPFunctionTemplate fTemplate;
private final IPDOMCPPTemplateParameter[] fTemplateParameters;
@ -226,6 +251,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
private final ICPPFunctionType fOriginalFunctionType;
private final ICPPParameter[] fOriginalParameters;
private final IType[] fOriginalExceptionSpec;
private final ICPPEvaluation fReturnExpression;
public ConfigureFunctionTemplate(ICPPFunctionTemplate original, PDOMCPPFunctionTemplate template) throws DOMException {
fTemplate = template;
@ -234,6 +260,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
fOriginalFunctionType= original.getType();
fOriginalParameters= original.getParameters();
fOriginalExceptionSpec= template.extractExceptionSpec(original);
fReturnExpression= CPPFunction.getReturnExpression(original);
postProcesses.add(this);
}
@ -244,7 +271,33 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (tp != null)
tp.configure(fOriginalTemplateParameters[i]);
}
fTemplate.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec);
fTemplate.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec,
fReturnExpression);
}
}
class ConfigureAliasTemplate implements Runnable {
private final PDOMCPPAliasTemplate fTemplate;
private final IPDOMCPPTemplateParameter[] fTemplateParameters;
private final ICPPTemplateParameter[] fOriginalTemplateParameters;
private final IType fOriginalAliasedType;
public ConfigureAliasTemplate(ICPPAliasTemplate original, PDOMCPPAliasTemplate 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);
}
}
@ -270,7 +323,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
/**
* Adds or returns existing binding for the given one. If <code>fromName</code> is not <code>null</code>
* Adds or returns existing binding for the given one. If {@code fromName} is not {@code null},
* then an existing binding is updated with the properties of the name.
*/
private PDOMBinding addBinding(IBinding inputBinding, IASTName fromName) throws CoreException {
@ -624,8 +677,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return adaptBinding(null, inputBinding, includeLocal ? FILE_LOCAL_REC_DUMMY : null);
}
private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding, long[] fileLocalRecHolder)
throws CoreException {
private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding,
long[] fileLocalRecHolder) throws CoreException {
if (cannotAdapt(inputBinding)) {
return null;
}
@ -635,7 +688,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return result;
}
// assign names to anonymous types.
// Assign names to anonymous types.
IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
if (binding == null) {
return null;
@ -1022,8 +1075,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
@Override
public PDOMBinding addTypeBinding(IBinding type) throws CoreException {
return addBinding(type, null);
public PDOMBinding addTypeBinding(IBinding binding) throws CoreException {
return addBinding(binding, null);
}
@Override

Some files were not shown because too many files have changed in this diff Show more