diff --git a/build/org.eclipse.cdt.autotools.core/ChangeLog b/build/org.eclipse.cdt.autotools.core/ChangeLog index 4db2797dc08..70f4ce00a68 100644 --- a/build/org.eclipse.cdt.autotools.core/ChangeLog +++ b/build/org.eclipse.cdt.autotools.core/ChangeLog @@ -1,3 +1,23 @@ +2012-07-23 Jeff Johnston + + * src/org/eclipse/cdt/autotools/core/AutotoolsOptionConstants.java: New file. + * src/org/eclipse/cdt/internal/autotools/core/configure/IConfigureOption.java: Use IAutotoolsOption values for type constants. + * src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfiguration.java: Use AutotoolsOptionConstants + for names of configuration options. + +2012-07-20 Jeff Johnston + + * src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java (getAutotoolCfgOptions): New publicly accessible + method for retrieving Autotool configuration options for a given build configuration. + (updateAutotoolCfgOptions): New publicly accessible method for updating Autotool configuration options for + a given build configuration. + * src/org/eclipse/cdt/internal/autotools/core/configure/ConfigureMessages.properties: Add new messages for + errors caused by user reading and updating configuration options. + * src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java: Add synchronization to + all public methods. + (updateAutotoolCfgOptions): New method to allow external users to update configuration options. + (getAutotoolsCfgOptions): New method to get configuration options for a given configuration id. + 2012-04-20 Jeff Johnston * META-INF/MANIFEST.MF: Bump up version to 1.1.0. diff --git a/build/org.eclipse.cdt.autotools.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.autotools.core/META-INF/MANIFEST.MF index 2cb9762176a..df33f30ac5f 100644 --- a/build/org.eclipse.cdt.autotools.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.autotools.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name.0 Bundle-SymbolicName: org.eclipse.cdt.autotools.core;singleton:=true -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.eclipse.cdt.autotools.core.AutotoolsPlugin Bundle-Localization: plugin Require-Bundle: org.eclipse.ui;bundle-version="3.4.0", diff --git a/build/org.eclipse.cdt.autotools.core/plugin.properties b/build/org.eclipse.cdt.autotools.core/plugin.properties index 9ad19876275..6a3682f1b7c 100644 --- a/build/org.eclipse.cdt.autotools.core/plugin.properties +++ b/build/org.eclipse.cdt.autotools.core/plugin.properties @@ -1,5 +1,5 @@ ################################################################################# -# Copyright (c) 2006, 2008, 2009 Red Hat, Inc. +# Copyright (c) 2006, 2012 Red Hat, Inc. # 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 @@ -7,10 +7,11 @@ # # Contributors: # Red Hat Incorporated - initial API and implementation +# IBM Corporation ################################################################################# ConvertWizard.description=Convert to C/C++ Autotools Project NewCProject.description=GNU C Autotools Project -NewCProjectV2.description=GNU C Autootols Project V2 +NewCProjectV2.description=GNU C Autotools Project V2 NewCCProject.description=GNU C++ Autotools Project NewCWizard.name=GNU C Autotools Project NewCWizardV2.name=GNU C Autotools Project V2 @@ -177,4 +178,6 @@ ConfigureScript.name=Configure Script AutogenScript.name=Autogen Script AutotoolsProblemMarker.name=Configure Problem -AutotoolsErrorParser.name=Autotools Error Parser \ No newline at end of file +AutotoolsErrorParser.name=Autotools Error Parser + +AutoconfErrorParser.name=Autoconf Error Parser \ No newline at end of file diff --git a/build/org.eclipse.cdt.autotools.core/plugin.xml b/build/org.eclipse.cdt.autotools.core/plugin.xml index 35dcb05e86a..030b63f3ad3 100644 --- a/build/org.eclipse.cdt.autotools.core/plugin.xml +++ b/build/org.eclipse.cdt.autotools.core/plugin.xml @@ -562,7 +562,7 @@ + name="%AutoconfErrorParser.name"> diff --git a/build/org.eclipse.cdt.autotools.core/pom.xml b/build/org.eclipse.cdt.autotools.core/pom.xml index c9156c0cbc9..353efd8038f 100644 --- a/build/org.eclipse.cdt.autotools.core/pom.xml +++ b/build/org.eclipse.cdt.autotools.core/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT org.eclipse.cdt.autotools.core eclipse-plugin diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsOptionConstants.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsOptionConstants.java new file mode 100644 index 00000000000..43658956a40 --- /dev/null +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsOptionConstants.java @@ -0,0 +1,51 @@ +package org.eclipse.cdt.autotools.core; + +/** + * @since 1.2 + */ +public class AutotoolsOptionConstants { + // IAutotoolOption Names + public final static String TOOL_CONFIGURE = "configure"; // $NON-NLS-1$ + public final static String CATEGORY_GENERAL = "general"; // $NON-NLS-1$ + public final static String OPT_CONFIGDIR = "configdir"; // $NON-NLS-1$ + public final static String OPT_CACHE_FILE = "cache-file"; // $NON-NLS-1$ + public final static String OPT_HELP = "help"; // $NON-NLS-1$ + public final static String OPT_NO_CREATE = "no-create"; // $NON-NLS-1$ + public final static String OPT_QUIET = "quiet"; // $NON-NLS-1$ + public final static String OPT_VERSION = "version"; // $NON-NLS-1$ + public final static String CATEGORY_PLATFORM = "platform"; // $NON-NLS-1$ + public final static String OPT_HOST = "host"; // $NON-NLS-1$ + public final static String OPT_BUILD = "build"; // $NON-NLS-1$ + public final static String OPT_TARGET = "target"; // $NON-NLS-1$ + public final static String CATEGORY_DIRECTORIES = "directories"; // $NON-NLS-1$ + public final static String OPT_PREFIX = "prefix"; // $NON-NLS-1$ + public final static String OPT_EXEC_PREFIX = "exec-prefix"; // $NON-NLS-1$ + public final static String OPT_LIBDIR = "libdir"; // $NON-NLS-1$ + public final static String OPT_BINDIR = "bindir"; // $NON-NLS-1$ + public final static String OPT_SBINDIR = "sbindir"; // $NON-NLS-1$ + public final static String OPT_INCLUDEDIR = "includedir"; // $NON-NLS-1$ + public final static String OPT_DATADIR = "datadir"; // $NON-NLS-1$ + public final static String OPT_SYSCONFDIR = "sysconfdir"; // $NON-NLS-1$ + public final static String OPT_INFODIR = "infodir"; // $NON-NLS-1$ + public final static String OPT_MANDIR = "mandir"; // $NON-NLS-1$ + public final static String OPT_SRCDIR = "srcdir"; // $NON-NLS-1$ + public final static String OPT_LOCALSTATEDIR = "localstatedir"; // $NON-NLS-1$ + public final static String OPT_SHAREDSTATEDIR = "sharedstatedir"; // $NON-NLS-1$ + public final static String OPT_LIBEXECDIR = "libexecdir"; // $NON-NLS-1$ + public final static String OPT_OLDINCLUDEDIR = "oldincludedir"; // $NON-NLS-1$ + public final static String CATEGORY_FILENAMES = "filenames"; // $NON-NLS-1$ + public final static String OPT_PROGRAM_PREFIX = "program-prefix"; // $NON-NLS-1$ + public final static String OPT_PROGRAM_SUFFIX = "program-suffix"; // $NON-NLS-1$ + public final static String OPT_PROGRAM_TRANSFORM_NAME = "program-transform-name"; // $NON-NLS-1$ + public final static String CATEGORY_FEATURES = "features"; // $NON-NLS-1$ + public final static String OPT_ENABLE_MAINTAINER_MODE = "enable-maintainer-mode"; // $NON-NLS-1$ + public final static String FLAG_CFLAGS = "CFLAGS"; // $NON-NLS-1$ + public final static String OPT_CFLAGS_DEBUG = "cflags-debug"; // $NON-NLS-1$ + public final static String OPT_CFLAGS_GPROF = "cflags-gprof"; // $NON-NLS-1$ + public final static String OPT_CFLAGS_GCOV = "cflags-gcov"; // $NON-NLS-1$ + public final static String OPT_USER = "user"; // $NON-NLS-1$ + public final static String TOOL_AUTOGEN = "autogen"; // $NON-NLS-1$ + public final static String CATEGORY_OPTIONS = "options"; // $NON-NLS-1$ + public final static String OPT_AUTOGENOPTS = "autogenOpts"; // $NON-NLS-1$ + +} diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java index 9793b03959b..862d445f278 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java @@ -12,9 +12,11 @@ package org.eclipse.cdt.autotools.core; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; +import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfigurationManager; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; @@ -290,4 +292,34 @@ public class AutotoolsPlugin extends AbstractUIPlugin { } return null; } + + /** + * Return set of Autotool configuration options for a given build configuration id. + * + * @param project existing autotools project + * @param cfgId configuration id + * @return a copy of Autotools configurations for the given configuration id + * @throws CoreException if project is not valid Autotools project or cfgId does not exist + * @since 1.2 + */ + public Map getAutotoolCfgOptions(IProject project, + String cfgId) throws CoreException { + return AutotoolsConfigurationManager.getInstance().getAutotoolsCfgOptions(project, cfgId); + } + + /** + * Update Autotool configuration options for a specified build configuration + * + * @param project existing autotools project + * @param cfgId configuation id + * @param options set of updated Autotool configuration options + * @throws CoreException if project is not valid Autotools project or cfgId does not exist + * + * @since 1.2 + */ + public void updateAutotoolCfgOptions(IProject project, String cfgId, + Map options) throws CoreException { + AutotoolsConfigurationManager.getInstance().updateAutotoolCfgOptions(project, cfgId, options); + + } } diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/IAutotoolsOption.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/IAutotoolsOption.java new file mode 100644 index 00000000000..18788775fb1 --- /dev/null +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/IAutotoolsOption.java @@ -0,0 +1,22 @@ +package org.eclipse.cdt.autotools.core; + +import org.eclipse.core.runtime.CoreException; + + +/** + * @since 1.2 + */ +public interface IAutotoolsOption { + public final static int CATEGORY = 0; + public final static int BIN = 1; + public final static int STRING = 2; + public final static int INTERNAL = 3; + public final static int MULTIARG = 4; + public final static int TOOL = 5; + public final static int FLAG = 6; + public final static int FLAGVALUE = 7; + public int getType(); + public boolean canUpdate(); + public void setValue(String value) throws CoreException; + public String getValue(); +} diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfiguration.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfiguration.java index 03b728d8993..40dfb2f30f7 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfiguration.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfiguration.java @@ -16,6 +16,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.eclipse.cdt.autotools.core.AutotoolsOptionConstants; + public class AutotoolsConfiguration implements IAConfiguration { @@ -67,48 +69,48 @@ public class AutotoolsConfiguration implements IAConfiguration { // All options following a category are children of that category // in a tree view, up to the next category. private static Option[] configOpts = new Option[] { - new Option("configure", IConfigureOption.TOOL), // $NON-NLS-1$ - new Option("general", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("configdir", IConfigureOption.INTERNAL), // $NON-NLS-1$ - new Option("cache-file", "cache_file", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("help", IConfigureOption.BIN), // $NON-NLS-1$ - new Option("no-create", "no_create", IConfigureOption.BIN), // $NON-NLS-1$ - new Option("quiet", IConfigureOption.BIN), // $NON-NLS-1$ - new Option("version", IConfigureOption.BIN), // $NON-NLS-1$ - new Option("platform", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("host", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("build", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("target", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("directories", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("prefix", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("exec-prefix", "exec_prefix", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("libdir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("bindir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("sbindir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("includedir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("datadir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("sysconfdir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("infodir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("mandir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("srcdir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("localstatedir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("sharedstatedir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("libexecdir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("oldincludedir", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("filenames", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("program-prefix", "program_prefix", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("program-suffix", "program_suffix", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("program-transform-name", "program_transform_name", IConfigureOption.STRING), // $NON-NLS-1$ - new Option("features", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("enable-maintainer-mode", "enable_maintainer_mode", IConfigureOption.BIN), // $NON-NLS-1$ - new Option("CFLAGS", IConfigureOption.FLAG), // $NON-NLS-1$ - new Option("cflags-debug", "cflags_debug", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ - new Option("cflags-gprof", "cflags_gprof", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ - new Option("cflags-gcov", "cflags_gcov", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ - new Option("user", IConfigureOption.MULTIARG), // $NON-NLS-1$ - new Option("autogen", "autogen", "autogen.sh", IConfigureOption.TOOL), // $NON-NLS-1$ - new Option("options", IConfigureOption.CATEGORY), // $NON-NLS-1$ - new Option("autogenOpts", IConfigureOption.MULTIARG), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.TOOL_CONFIGURE, IConfigureOption.TOOL), + new Option(AutotoolsOptionConstants.CATEGORY_GENERAL, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_CONFIGDIR, IConfigureOption.INTERNAL), + new Option(AutotoolsOptionConstants.OPT_CACHE_FILE, "cache_file", IConfigureOption.STRING), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.OPT_HELP, IConfigureOption.BIN), + new Option(AutotoolsOptionConstants.OPT_NO_CREATE, "no_create", IConfigureOption.BIN), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.OPT_QUIET, IConfigureOption.BIN), + new Option(AutotoolsOptionConstants.OPT_VERSION, IConfigureOption.BIN), + new Option(AutotoolsOptionConstants.CATEGORY_PLATFORM, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_HOST, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_BUILD, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_TARGET, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.CATEGORY_DIRECTORIES, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_PREFIX, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_EXEC_PREFIX, "exec_prefix", IConfigureOption.STRING), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.OPT_LIBDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_BINDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_SBINDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_INCLUDEDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_DATADIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_SYSCONFDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_INFODIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_MANDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_SRCDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_LOCALSTATEDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_SHAREDSTATEDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_LIBEXECDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.OPT_OLDINCLUDEDIR, IConfigureOption.STRING), + new Option(AutotoolsOptionConstants.CATEGORY_FILENAMES, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_PROGRAM_PREFIX, "program_prefix", IConfigureOption.STRING), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.OPT_PROGRAM_SUFFIX, "program_suffix", IConfigureOption.STRING), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME, "program_transform_name", IConfigureOption.STRING), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.CATEGORY_FEATURES, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE, "enable_maintainer_mode", IConfigureOption.BIN), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.FLAG_CFLAGS, IConfigureOption.FLAG), + new Option(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG, "cflags_debug", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ + new Option(AutotoolsOptionConstants.OPT_CFLAGS_GPROF, "cflags_gprof", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ + new Option(AutotoolsOptionConstants.OPT_CFLAGS_GCOV, "cflags_gcov", IConfigureOption.FLAGVALUE), // $NON-NLS-1$ // $NON-NLS-2$ + new Option(AutotoolsOptionConstants.OPT_USER, IConfigureOption.MULTIARG), + new Option(AutotoolsOptionConstants.TOOL_AUTOGEN, "autogen", "autogen.sh", IConfigureOption.TOOL), // $NON-NLS-1$ + new Option(AutotoolsOptionConstants.CATEGORY_OPTIONS, IConfigureOption.CATEGORY), + new Option(AutotoolsOptionConstants.OPT_AUTOGENOPTS, IConfigureOption.MULTIARG), }; private static Option[] toolList; diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java index 2eac3af257a..1c1e526b787 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java @@ -20,12 +20,16 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; import org.eclipse.cdt.autotools.core.AutotoolsPlugin; +import org.eclipse.cdt.autotools.core.IAutotoolsOption; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; @@ -45,7 +49,10 @@ import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -58,8 +65,18 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { public final static String CFG_FILE_NAME = ".autotools"; //$NON-NLS-1$ private final static String CFG_CANT_SAVE = "Configure.Error.NoProjectToSave"; //$NON-NLS-1$ - + /** + * @since 1.2 + */ + public static final String INVALID_AUTOTOOLS_PROJECT = "CfgOptions.Invalid.Project"; //$NON-NLS-1$ + /** + * @since 1.2 + */ + + public static final String INVALID_AUTOTOOLS_CONFIG_ID = "CfgOptions.Invalid.Config"; //$NON-NLS-1$ + private static AutotoolsConfigurationManager instance; + private static Random rand = new Random(); private boolean isSyncing; @@ -79,21 +96,21 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { return instance; } - public IAConfiguration createDefaultConfiguration(IProject project, String id) { + public synchronized IAConfiguration createDefaultConfiguration(IProject project, String id) { IAConfiguration cfg = new AutotoolsConfiguration(id); return cfg; } - public IAConfiguration findCfg(IProject p, String id) { + public synchronized IAConfiguration findCfg(IProject p, String id) { Map cfgs = getConfigurations(p); return cfgs.get(id); } - public IAConfiguration getConfiguration(IProject p, String cfgId) { + public synchronized IAConfiguration getConfiguration(IProject p, String cfgId) { return getConfiguration(p, cfgId, true); } - public IAConfiguration getConfiguration(IProject p, String cfgId, boolean persist) { + public synchronized IAConfiguration getConfiguration(IProject p, String cfgId, boolean persist) { IAConfiguration cfg = findCfg(p, cfgId); if (cfg == null) { cfg = createDefaultConfiguration(p, cfgId); @@ -109,14 +126,14 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { } - public boolean isConfigurationAlreadySaved(IProject project, ICConfigurationDescription cfgd) { + public synchronized boolean isConfigurationAlreadySaved(IProject project, ICConfigurationDescription cfgd) { Map cfgs = getSavedConfigs(project); if (cfgs != null) return cfgs.get(cfgd.getId()) != null; return false; } - public void addConfiguration(IProject project, IAConfiguration cfg) { + public synchronized void addConfiguration(IProject project, IAConfiguration cfg) { String projectName = project.getName(); Map cfgs = getSavedConfigs(project); if (cfgs == null) { @@ -127,11 +144,11 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { saveConfigs(project); } - public boolean isSyncing() { + public synchronized boolean isSyncing() { return isSyncing; } - private void setSyncing(boolean value) { + private synchronized void setSyncing(boolean value) { isSyncing = value; } @@ -144,7 +161,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { * @param project to synchronize configurations for * */ - public void syncConfigurations(IProject project) { + public synchronized void syncConfigurations(IProject project) { setSyncing(true); clearTmpConfigurations(project); ICProjectDescription pd = CoreModel.getDefault().getProjectDescription(project); @@ -160,13 +177,13 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { replaceProjectConfigurations(project, newCfgList); } - public void replaceProjectConfigurations(IProject project, Map cfgs) { + public synchronized void replaceProjectConfigurations(IProject project, Map cfgs) { String projectName = project.getName(); configs.put(projectName, cfgs); saveConfigs(project); } - public void replaceProjectConfigurations(IProject project, Map cfgs, ICConfigurationDescription[] cfgds) { + public synchronized void replaceProjectConfigurations(IProject project, Map cfgs, ICConfigurationDescription[] cfgds) { String projectName = project.getName(); configs.put(projectName, cfgs); saveConfigs(project, cfgds); @@ -201,7 +218,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { else if (nameNode != null) { String cfgName = nameNode.getNodeValue(); ICConfigurationDescription cfgd = - CoreModel.getDefault().getProjectDescription(project).getConfigurationByName(cfgName); + CoreModel.getDefault().getProjectDescription(project).getConfigurationByName(cfgName); if (cfgd != null) cfgId = cfgd.getId(); else @@ -258,7 +275,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { return list; } - public IAConfiguration getTmpConfiguration(IProject p, ICConfigurationDescription cfgd) { + public synchronized IAConfiguration getTmpConfiguration(IProject p, ICConfigurationDescription cfgd) { Map list = getTmpConfigs(p); IAConfiguration acfg = list.get(cfgd.getId()); if (acfg != null) { @@ -278,7 +295,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { * @param cfgd the configuration descriptor for the clone * @return true if the configuration is already saved, false otherwise */ - public boolean cloneCfg(IProject p, String oldId, ICConfigurationDescription cfgd) { + public synchronized boolean cloneCfg(IProject p, String oldId, ICConfigurationDescription cfgd) { if (isConfigurationAlreadySaved(p, cfgd)) return true; Map tmpList = getTmpConfigs(p); @@ -316,13 +333,15 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { return tmpList; } - public void clearTmpConfigurations(IProject p) { + public synchronized void clearTmpConfigurations(IProject p) { tmpConfigs.remove(p.getName()); } - public void saveConfigs(IProject project) { - ICConfigurationDescription[] cfgds = CoreModel.getDefault().getProjectDescription(project).getConfigurations(); - saveConfigs(project, cfgds); + public synchronized void saveConfigs(IProject project) { + synchronized (project) { + ICConfigurationDescription[] cfgds = CoreModel.getDefault().getProjectDescription(project).getConfigurations(); + saveConfigs(project, cfgds); + } } private void syncNameField(ICConfigurationDescription cfgd) { @@ -417,7 +436,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { // with any changes currently that have been made to them. If a configuration has been renamed, but this // has not yet been confirmed by the end-user, then only the changes to the configuration are made. The // name currently remains the same in the output file. - public void applyConfigs(String projectName, ICConfigurationDescription[] cfgds) { + public synchronized void applyConfigs(String projectName, ICConfigurationDescription[] cfgds) { try { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource res = (IProject)root.findMember(projectName, false); @@ -489,7 +508,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { } } - public Map getConfigurations(IProject project) { + public synchronized Map getConfigurations(IProject project) { Map list = getSavedConfigs(project); if (list == null) { list = new HashMap(); @@ -498,7 +517,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { return list; } - public void resourceChanged(IResourceChangeEvent event) { + public synchronized void resourceChanged(IResourceChangeEvent event) { IResource res = event.getResource(); if (!(res instanceof IProject)) return; @@ -527,4 +546,134 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { } } + private class AutotoolsOption implements IAutotoolsOption { + + private IConfigureOption option; + private final static String UNMODIFIABLE_CONFIG_OPTION = "CfgOptions.Unmodifiable.Option"; //$NON-NLS-1$ + + + public AutotoolsOption(IConfigureOption option) { + this.option = option; + } + + @Override + public int getType() { + return option.getType(); + } + + @Override + public boolean canUpdate() { + int type = getType(); + switch (type) { + case STRING: + case BIN: + case TOOL: + case FLAGVALUE: + case MULTIARG: + case INTERNAL: + return true; + } + return false; + } + + @Override + public void setValue(String value) throws CoreException { + if (!canUpdate()) { + throw new CoreException(new Status(IStatus.ERROR, AutotoolsPlugin.PLUGIN_ID, + ConfigureMessages.getString(UNMODIFIABLE_CONFIG_OPTION))); + } + synchronized (option) { + option.setValue(value); + } + } + + @Override + public String getValue() { + synchronized (option) { + return option.getValue(); + } + } + + } + + private String createDummyId() { + for (;;) { + String id = "TEMP_" + rand.nextInt(); + if (tmpConfigs.get(id) == null) + return id; + } + } + + /** + * @since 1.2 + */ + public synchronized Map getAutotoolsCfgOptions(IProject project, + String cfgId) throws CoreException { + + // Verify project is valid Autotools project + if (project == null || !project.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)) { + throw new CoreException(new Status(IStatus.ERROR, AutotoolsPlugin.PLUGIN_ID, + ConfigureMessages.getString(INVALID_AUTOTOOLS_PROJECT))); + } + + // Verify configuration id is valid + ICConfigurationDescription cfgd = + CoreModel.getDefault().getProjectDescription(project).getConfigurationById(cfgId); + IConfiguration icfg = ManagedBuildManager.getConfigurationForDescription(cfgd); + if (icfg == null) { + throw new CoreException(new Status(IStatus.ERROR, AutotoolsPlugin.PLUGIN_ID, + ConfigureMessages.getString(INVALID_AUTOTOOLS_CONFIG_ID))); + } + + IAConfiguration cfg = getConfiguration(project, cfgId); + HashMap options = new HashMap(); + + // Get set of configuration options and convert to set of IAutotoolOptions + Map cfgOptions = cfg.getOptions(); + IAConfiguration dummyCfg = createDefaultConfiguration(project, createDummyId()); + for (Iterator> i = cfgOptions.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Entry) i.next(); + String name = entry.getKey(); + IAutotoolsOption configOption = + new AutotoolsOption(entry.getValue().copy((AutotoolsConfiguration)dummyCfg)); + options.put(name, configOption); + } + + return options; + } + + /** + * @since 1.2 + */ + public synchronized void updateAutotoolCfgOptions(IProject project, String cfgId, + Map options) throws CoreException { + + // Verify project is valid Autotools project + if (project == null || !project.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)) { + throw new CoreException(new Status(IStatus.ERROR, AutotoolsPlugin.PLUGIN_ID, + ConfigureMessages.getString(INVALID_AUTOTOOLS_PROJECT))); + } + + // Verify configuration id is valid + IAConfiguration cfg = findCfg(project, cfgId); + if (cfg == null) { + throw new CoreException(new Status(IStatus.ERROR, AutotoolsPlugin.PLUGIN_ID, + ConfigureMessages.getString(INVALID_AUTOTOOLS_CONFIG_ID))); + } + + // Get set of configuration options and convert to set of IAutotoolOptions + for (Iterator> i = options.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Entry) i.next(); + String name = entry.getKey(); + IAutotoolsOption option = entry.getValue(); + IConfigureOption cfgOption = cfg.getOption(name); + if (cfgOption != null) { + cfgOption.setValue(option.getValue()); + } + } + + // Save changes + saveConfigs(project); + } + } diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/ConfigureMessages.properties b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/ConfigureMessages.properties index 0823b6ca45a..c317733fc4d 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/ConfigureMessages.properties +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/ConfigureMessages.properties @@ -98,4 +98,8 @@ Tool.command=Command Tool.allopts=All Options Configure.Error.AlreadyExists="A configuration named {0} already exists" -Configure.Error.NoProjectToSave="Project: {0} does not exist at time of saving configuration" \ No newline at end of file +Configure.Error.NoProjectToSave="Project: {0} does not exist at time of saving configuration" + +CfgOptions.Invalid.Project=Specified project is not a valid existing Autotools project +CfgOptions.Invalid.Config=Specified configuration id does not correspond to an existing configuration +CfgOptions.Unmodifiable.Option=Attempting to modify an unmodifiable Autotools configure option diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/IConfigureOption.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/IConfigureOption.java index 51437fbcd30..07b709094df 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/IConfigureOption.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/IConfigureOption.java @@ -12,16 +12,18 @@ package org.eclipse.cdt.internal.autotools.core.configure; import java.util.ArrayList; +import org.eclipse.cdt.autotools.core.IAutotoolsOption; + public interface IConfigureOption { - public final static int CATEGORY = 0; - public final static int BIN = 1; - public final static int STRING = 2; - public final static int INTERNAL = 3; - public final static int MULTIARG = 4; - public final static int TOOL = 5; - public final static int FLAG = 6; - public final static int FLAGVALUE = 7; + public final static int CATEGORY = IAutotoolsOption.CATEGORY; + public final static int BIN = IAutotoolsOption.BIN; + public final static int STRING = IAutotoolsOption.STRING; + public final static int INTERNAL = IAutotoolsOption.INTERNAL; + public final static int MULTIARG = IAutotoolsOption.MULTIARG; + public final static int TOOL = IAutotoolsOption.TOOL; + public final static int FLAG = IAutotoolsOption.FLAG; + public final static int FLAGVALUE = IAutotoolsOption.FLAGVALUE; public String getName(); public String getParameter(); public ArrayList getParameters(); diff --git a/build/org.eclipse.cdt.autotools.tests/ChangeLog b/build/org.eclipse.cdt.autotools.tests/ChangeLog index 985943a50f9..c853034259a 100644 --- a/build/org.eclipse.cdt.autotools.tests/ChangeLog +++ b/build/org.eclipse.cdt.autotools.tests/ChangeLog @@ -1,3 +1,12 @@ +2012-07-23 Jeff Johnston + + * src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java (suite): Add new UpdateConfigureTest. + * src/org/eclipse/cdt/autotools/tests/UpdateConfigureTest.java: New test. + * src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest0.java (testAutotoolsProject0): Fix nature id being tested. + * src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest1.java (testAutotoolsProject1): Ditto. + * src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest2.java (testAutotoolsProject2): Ditto. + * src/org/eclipse/cdt/autotools/tests/AutotoolsProjectNatureTest.java (testAutotoolsProjectNature): Ditto. + 2012-03-30 Jeff Johnston * src/org/eclipse/cdt/autotools/tests/ProjectTools.java diff --git a/build/org.eclipse.cdt.autotools.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.autotools.tests/META-INF/MANIFEST.MF index 91c7c412972..b773b8a270e 100644 --- a/build/org.eclipse.cdt.autotools.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.autotools.tests/META-INF/MANIFEST.MF @@ -23,3 +23,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.autotools.ui;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.eclipse.cdt.autotools.tests, + org.eclipse.cdt.autotools.tests.autoconf, + org.eclipse.cdt.autotools.tests.editors diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java index 1cbf1dd069d..f75d1b51066 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AllAutotoolsTests.java @@ -26,6 +26,7 @@ public class AllAutotoolsTests { suite.addTestSuite(AutotoolsProjectNatureTest.class); suite.addTestSuite(AutotoolsProjectTest1.class); suite.addTestSuite(AutotoolsProjectTest2.class); + suite.addTestSuite(UpdateConfigureTest.class); suite.addTest(AutoconfTests.suite()); suite.addTest(EditorTests.suite()); //$JUnit-END$ diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectNatureTest.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectNatureTest.java index d8e25ededfc..d0ec2951166 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectNatureTest.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectNatureTest.java @@ -12,8 +12,8 @@ package org.eclipse.cdt.autotools.tests; import junit.framework.TestCase; -import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; import org.eclipse.core.resources.IProject; +import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; public class AutotoolsProjectNatureTest extends TestCase { @@ -31,7 +31,7 @@ public class AutotoolsProjectNatureTest extends TestCase { if(testProject == null) { fail("Unable to create test project"); } - assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID)); + assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)); testProject.delete(true, false, ProjectTools.getMonitor()); } } diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest0.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest0.java index 993b60f734f..5bc88672d14 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest0.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest0.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.autotools.tests; import junit.framework.TestCase; -import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; +import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; @@ -47,7 +47,7 @@ public class AutotoolsProjectTest0 extends TestCase { public void testAutotoolsProject0() throws Exception { Path p = new Path("zip/project1.zip"); ProjectTools.addSourceContainerWithImport(testProject, null, p, null, true); - assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID)); + assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)); org.eclipse.core.runtime.Path x = new org.eclipse.core.runtime.Path("ChangeLog"); assertTrue(testProject.exists(x)); x = new org.eclipse.core.runtime.Path("configure"); diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest1.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest1.java index d3bcd1d54ab..000e572f8d9 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest1.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest1.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.autotools.tests; import junit.framework.TestCase; -import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; +import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; @@ -49,7 +49,7 @@ public class AutotoolsProjectTest1 extends TestCase { public void testAutotoolsProject1() throws Exception { Path p = new Path("zip/project1.zip"); ProjectTools.addSourceContainerWithImport(testProject, "src", p, null, true); - assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID)); + assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)); org.eclipse.core.runtime.Path x = new org.eclipse.core.runtime.Path("src/ChangeLog"); assertTrue(testProject.exists(x)); x = new org.eclipse.core.runtime.Path("src/configure"); diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest2.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest2.java index cf2b836ddd3..f5cec9b1a12 100644 --- a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest2.java +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/AutotoolsProjectTest2.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.autotools.tests; import junit.framework.TestCase; -import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; +import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; @@ -51,7 +51,7 @@ public class AutotoolsProjectTest2 extends TestCase { public void testAutotoolsProject2() throws Exception { Path p = new Path("zip/project2.zip"); ProjectTools.addSourceContainerWithImport(testProject, "src", p, null); - assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID)); + assertTrue(testProject.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)); org.eclipse.core.runtime.Path x = new org.eclipse.core.runtime.Path("src/ChangeLog"); assertTrue(testProject.exists(x)); x = new org.eclipse.core.runtime.Path("src/configure"); diff --git a/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/UpdateConfigureTest.java b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/UpdateConfigureTest.java new file mode 100644 index 00000000000..9e3fa4aad41 --- /dev/null +++ b/build/org.eclipse.cdt.autotools.tests/src/org/eclipse/cdt/autotools/tests/UpdateConfigureTest.java @@ -0,0 +1,484 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Red Hat 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: + * Red Hat Incorporated - initial API and implementation + * Marc-Andre Laperle - Fix failing test on Windows + *******************************************************************************/ +package org.eclipse.cdt.autotools.tests; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.TestCase; + +import org.eclipse.cdt.autotools.core.AutotoolsOptionConstants; +import org.eclipse.cdt.autotools.core.AutotoolsPlugin; +import org.eclipse.cdt.autotools.core.IAutotoolsOption; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +// This test verifies an autogen.sh project that builds configure, but +// does not run it. +public class UpdateConfigureTest extends TestCase { + + private IProject testProject; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + if (!ProjectTools.setup()) + fail("could not perform basic project workspace setup"); + testProject = ProjectTools.createProject("testProject2"); + if (testProject == null) { + fail("Unable to create test project"); + } + testProject.open(new NullProgressMonitor()); + } + + /** + * Test getting and updating configuration options for an Autotools Project. The top-level + * contains autogen.sh which will build configure, but not run it. + * @throws Exception + */ + public void testGetAndUpdateConfigureOptions() throws Exception { + Path p = new Path("zip/project2.zip"); + ProjectTools.addSourceContainerWithImport(testProject, "src", p, null); + assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID)); + ProjectTools.setConfigDir(testProject, "src"); + ProjectTools.markExecutable(testProject, "src/autogen.sh"); + assertTrue(ProjectTools.build()); + ICConfigurationDescription cfgDes = CoreModel.getDefault().getProjectDescription(testProject).getActiveConfiguration(); + IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes); + assertTrue(cfg.getName().equals("Build (GNU)")); + Map opts = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId()); + IAutotoolsOption configdir = opts.get(AutotoolsOptionConstants.OPT_CONFIGDIR); + assertEquals(configdir.getType(), IAutotoolsOption.INTERNAL); + assertTrue(configdir.getValue().equals("src")); + assertTrue(configdir.canUpdate()); + // Verify we cannot update any of the categories or flags + IAutotoolsOption k = opts.get(AutotoolsOptionConstants.CATEGORY_DIRECTORIES); + assertFalse(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.CATEGORY); + + k = opts.get(AutotoolsOptionConstants.CATEGORY_FEATURES); + assertFalse(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.CATEGORY); + + k = opts.get(AutotoolsOptionConstants.CATEGORY_FILENAMES); + assertFalse(k.canUpdate()); + + k = opts.get(AutotoolsOptionConstants.CATEGORY_GENERAL); + assertEquals(k.getType(), IAutotoolsOption.CATEGORY); + assertFalse(k.canUpdate()); + + k = opts.get(AutotoolsOptionConstants.CATEGORY_OPTIONS); + assertEquals(k.getType(), IAutotoolsOption.CATEGORY); + assertFalse(k.canUpdate()); + + k = opts.get(AutotoolsOptionConstants.CATEGORY_PLATFORM); + assertFalse(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.CATEGORY); + + k = opts.get(AutotoolsOptionConstants.FLAG_CFLAGS); + assertFalse(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.FLAG); + + // Tools are ok to update + k = opts.get(AutotoolsOptionConstants.TOOL_AUTOGEN); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.TOOL); + assertEquals(k.getValue(), "autogen.sh"); //$NON-NLS-1$ + k.setValue("autogen2.sh"); //$NON-NLS-1$ + + k = opts.get(AutotoolsOptionConstants.TOOL_CONFIGURE); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.TOOL); + assertEquals(k.getValue(), "configure"); //$NON-NLS-1$ + k.setValue("config"); //$NON-NLS-1$ + + // Flag values are ok to update + k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + // Check other options + k = opts.get(AutotoolsOptionConstants.OPT_AUTOGENOPTS); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.MULTIARG); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("some opts"); + + k = opts.get(AutotoolsOptionConstants.OPT_BINDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/bin"); + + k = opts.get(AutotoolsOptionConstants.OPT_BUILD); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("linux"); + + k = opts.get(AutotoolsOptionConstants.OPT_CACHE_FILE); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("config.status"); + + k = opts.get(AutotoolsOptionConstants.OPT_DATADIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/data"); + + k = opts.get(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.BIN); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_EXEC_PREFIX); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/exec"); + + k = opts.get(AutotoolsOptionConstants.OPT_HELP); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.BIN); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_HOST); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("linux"); + + k = opts.get(AutotoolsOptionConstants.OPT_INCLUDEDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/include"); + + k = opts.get(AutotoolsOptionConstants.OPT_INFODIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/info"); + + k = opts.get(AutotoolsOptionConstants.OPT_LIBDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/lib"); + + k = opts.get(AutotoolsOptionConstants.OPT_LIBEXECDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/libexec"); + + k = opts.get(AutotoolsOptionConstants.OPT_LOCALSTATEDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/localstate"); + + k = opts.get(AutotoolsOptionConstants.OPT_MANDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/man"); + + k = opts.get(AutotoolsOptionConstants.OPT_NO_CREATE); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.BIN); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_OLDINCLUDEDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/oldinclude"); + + k = opts.get(AutotoolsOptionConstants.OPT_PREFIX); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("prefix"); + + k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_PREFIX); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("program_prefix"); + + k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_SUFFIX); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("program_suffix"); + + k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("program_transform_name"); + + k = opts.get(AutotoolsOptionConstants.OPT_QUIET); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.BIN); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + k = opts.get(AutotoolsOptionConstants.OPT_SBINDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/sbin"); + + k = opts.get(AutotoolsOptionConstants.OPT_SHAREDSTATEDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/sharedstate"); + + k = opts.get(AutotoolsOptionConstants.OPT_SRCDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("src"); + + k = opts.get(AutotoolsOptionConstants.OPT_SYSCONFDIR); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("/usr/sysconf"); + + k = opts.get(AutotoolsOptionConstants.OPT_TARGET); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.STRING); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("target"); + + + k = opts.get(AutotoolsOptionConstants.OPT_USER); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.MULTIARG); + assertEquals(k.getValue(), ""); //$NON-NLS-1$ + k.setValue("user opts"); + + k = opts.get(AutotoolsOptionConstants.OPT_VERSION); + assertTrue(k.canUpdate()); + assertEquals(k.getType(), IAutotoolsOption.BIN); + assertEquals(k.getValue(), "false"); //$NON-NLS-1$ + k.setValue("true"); + + // Verify last option changed has changed in our copy, but not + // in the actual options + assertEquals(k.getValue(), "true"); + Map opts2 = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId()); + IAutotoolsOption k2 = opts2.get(AutotoolsOptionConstants.OPT_VERSION); + assertEquals(k2.getValue(), "false"); + + // Now update the options we changed + AutotoolsPlugin.getDefault().updateAutotoolCfgOptions(testProject, cfg.getId(), opts); + opts2 = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId()); + + // Verify new option values + k = opts2.get(AutotoolsOptionConstants.TOOL_AUTOGEN); + assertEquals(k.getValue(), "autogen2.sh"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.TOOL_CONFIGURE); + assertEquals(k.getValue(), "config"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_AUTOGENOPTS); + assertEquals(k.getValue(), "some opts"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_BINDIR); + assertEquals(k.getValue(), "/usr/bin"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_BUILD); + assertEquals(k.getValue(), "linux"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_CACHE_FILE); + assertEquals(k.getValue(), "config.status"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_DATADIR); + assertEquals(k.getValue(), "/usr/data"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_EXEC_PREFIX); + assertEquals(k.getValue(), "/usr/exec"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_HELP); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_HOST); + assertEquals(k.getValue(), "linux"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_INCLUDEDIR); + assertEquals(k.getValue(), "/usr/include"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_INFODIR); + assertEquals(k.getValue(), "/usr/info"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_LIBDIR); + assertEquals(k.getValue(), "/usr/lib"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_LIBEXECDIR); + assertEquals(k.getValue(), "/usr/libexec"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_LOCALSTATEDIR); + assertEquals(k.getValue(), "/usr/localstate"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_MANDIR); + assertEquals(k.getValue(), "/usr/man"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_NO_CREATE); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_OLDINCLUDEDIR); + assertEquals(k.getValue(), "/usr/oldinclude"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_PREFIX); + assertEquals(k.getValue(), "prefix"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_PREFIX); + assertEquals(k.getValue(), "program_prefix"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_SUFFIX); + assertEquals(k.getValue(), "program_suffix"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME); + assertEquals(k.getValue(), "program_transform_name"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_QUIET); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_SBINDIR); + assertEquals(k.getValue(), "/usr/sbin"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_SHAREDSTATEDIR); + assertEquals(k.getValue(), "/usr/sharedstate"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_SRCDIR); + assertEquals(k.getValue(), "src"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_SYSCONFDIR); + assertEquals(k.getValue(), "/usr/sysconf"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_TARGET); + assertEquals(k.getValue(), "target"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_USER); + assertEquals(k.getValue(), "user opts"); //$NON-NLS-1$ + + k = opts2.get(AutotoolsOptionConstants.OPT_VERSION); + assertEquals(k.getValue(), "true"); //$NON-NLS-1$ + + // Verify one updated option in the .autotools file for the project + try { + IPath fileLocation = testProject.getLocation().append(".autotools"); //$NON-NLS-1$ + File dirFile = fileLocation.toFile(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + assertTrue(dirFile.exists()); + Document d = db.parse(dirFile); + Element e = d.getDocumentElement(); + // Get the stored configuration data + NodeList cfgs = e.getElementsByTagName("configuration"); // $NON-NLS-1$ + for (int x = 0; x < cfgs.getLength(); ++x) { + Node n = cfgs.item(x); + NodeList l = n.getChildNodes(); + for (int y = 0; y < l.getLength(); ++y) { + Node child = l.item(y); + if (child.getNodeName().equals("option")) { // $NON-NLS-1$ + NamedNodeMap optionAttrs = child.getAttributes(); + Node id = optionAttrs.getNamedItem("id"); // $NON-NLS-1$ + Node value = optionAttrs.getNamedItem("value"); // $NON-NLS-1$ + // Verify the bindir option is updated + if (id.equals(AutotoolsOptionConstants.OPT_BINDIR)) + assertEquals(value, "/usr/bin"); //$NON-NLS-1$ + } + } + } + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + protected void tearDown() throws Exception { + testProject.refreshLocal(IResource.DEPTH_INFINITE, null); + try { + testProject.delete(true, true, null); + } catch (Exception e) { + //FIXME: Why does a ResourceException occur when deleting the project?? + } + super.tearDown(); + } + +} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/wizards/AutotoolsWizardMessages.properties b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/wizards/AutotoolsWizardMessages.properties index 00732afa9db..a530bc7309b 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/wizards/AutotoolsWizardMessages.properties +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/wizards/AutotoolsWizardMessages.properties @@ -118,7 +118,7 @@ BuildSettingsBlock.label.macros.group=Build Macros usage BuildSettingsBlock.label.macros.expand=Expand Build Environment Macros BuildSettingsBlock.label.internal.builder.group=Internal Builder BuildSettingsBlock.label.internal.builder.enable=Enable Internal Builder -BuildSettingsBlock.label.internal.builder.ignore.err=Ignore build errorors +BuildSettingsBlock.label.internal.builder.ignore.err=Ignore build errors BuildSettingsBlock.label.internal.builder.experimental.note=NOTE: This is experimental functionality diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java index a5895442b59..8db35da4fa5 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCScannerInfoConsoleParserTests.java @@ -96,7 +96,10 @@ public class GCCScannerInfoConsoleParserTests extends BaseBOPConsoleParserTests assertTrue(sumIncludes.contains("//server6/include")); //$NON-NLS-1$ assertTrue(sumIncludes.contains("/multiline/dir")); //$NON-NLS-1$ assertTrue(sumIncludes.contains("multiline2")); //$NON-NLS-1$ + // Fails consistently + if (System.getProperty("cdt.skip.known.test.failures") == null) { assertTrue(sumIncludes.contains("multiline3")); //$NON-NLS-1$ + } assertTrue(sumIncludes.size() == 26); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.properties b/build/org.eclipse.cdt.managedbuilder.core/plugin.properties index 2f46bf52441..46b890e8956 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2010 IBM Corporation and others. +# Copyright (c) 2003, 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 @@ -75,4 +75,8 @@ extension-point.name = Managed Build Tools 2.0 (Deprecated) extension-point.name.0 = Managed Build Definitions extension-point.name.1 = Managed Build Project Converter extension-point.name.2 = Build Properties -extension-point.name.3 = ToolChain Modification Info \ No newline at end of file +extension-point.name.3 = ToolChain Modification Info + +GCCBuildOutputParser.name = CDT GCC Build Output Parser +GCCBuildinCompilerSettings.name = CDT GCC Builtin Compiler Settings +ManagedBuildSettingEntries.name = CDT Managed Build Setting Entries \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml index f6e4a4f0359..3ebf0596d34 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.core/plugin.xml @@ -603,12 +603,12 @@ + name="%ManagedBuildSettingEntries.name"> @@ -632,7 +632,7 @@ diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF index bb3ca0af83c..a5188816f4c 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/META-INF/MANIFEST.MF @@ -16,3 +16,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.resources Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.eclipse.cdt.managedbuilder.ui.tests, + org.eclipse.cdt.managedbuilder.ui.tests.suite, + org.eclipse.cdt.managedbuilder.ui.tests.testplugin, + org.eclipse.cdt.managedbuilder.ui.tests.util, + org.eclipse.cdt.managedbuilder.ui.tests.wizardPages diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java index 0461da5b940..4e68e5b7360 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java @@ -188,7 +188,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { * Checks whether specified type (class or typedef to the class) is an abstract class. * If it is, reports violations on each pure virtual method */ - private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) { + private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode) { IType unwindedType = CxxAstUtils.unwindTypedef(typeToCheck); if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) { return; @@ -196,7 +196,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { ICPPClassType classType = (ICPPClassType) unwindedType; ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType); if (pureVirtualMethods == null) { - pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType); + pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType, problemNode); pureVirtualMethodsCache.put(classType, pureVirtualMethods); } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java index 2b7ba944fcf..a22cc9c15ba 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java @@ -46,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; @@ -84,7 +85,7 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { Set fieldsInConstructor = constructorsStack.push(new HashSet()); // Add all class fields - for (IField field : constructor.getClassOwner().getDeclaredFields()) { + for (IField field : ClassTypeHelper.getDeclaredFields(constructor.getClassOwner(), declaration)) { if (isSimpleType(field.getType()) && !field.isStatic()) { fieldsInConstructor.add(field); } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java index db7235a7307..bb780c1912f 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NonVirtualDestructor.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; /** @@ -46,8 +47,8 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { ast.accept(new OnEachClass()); } - private static ICPPMethod getDestructor(ICPPClassType classType) { - for (ICPPMethod method : classType.getDeclaredMethods()) { + private static ICPPMethod getDestructor(ICPPClassType classType, IASTNode point) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { if (method.isDestructor()) { return method; } @@ -55,18 +56,18 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return null; } - private static boolean hasVirtualDestructor(ICPPClassType classType) { + private static boolean hasVirtualDestructor(ICPPClassType classType, IASTNode point) { checkedClassTypes.add(classType); - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, point); if (destructor != null && destructor.isVirtual()) { return true; } - ICPPBase[] bases = classType.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType) { ICPPClassType cppClassType = (ICPPClassType) baseClass; - if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType)) { + if (!checkedClassTypes.contains(cppClassType) && hasVirtualDestructor(cppClassType, point)) { return true; } } @@ -89,13 +90,13 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { return PROCESS_SKIP; } ICPPClassType classType = (ICPPClassType) binding; - boolean hasVirtualDestructor = hasVirtualDestructor(classType); + boolean hasVirtualDestructor = hasVirtualDestructor(classType, className); checkedClassTypes.clear(); if (hasVirtualDestructor) { return PROCESS_SKIP; } ICPPMethod virtualMethod = null; - for (ICPPMethod method : classType.getAllDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getAllDeclaredMethods(classType, className)) { if (!method.isDestructor() && method.isVirtual()) { virtualMethod = method; } @@ -103,7 +104,7 @@ public class NonVirtualDestructor extends AbstractIndexAstChecker { if (virtualMethod == null) { return PROCESS_SKIP; } - ICPPMethod destructor = getDestructor(classType); + ICPPMethod destructor = getDestructor(classType, className); if (destructor != null && destructor.getVisibility() != ICPPASTVisibilityLabel.v_public && classType.getFriends().length == 0) { diff --git a/core/org.eclipse.cdt.alltests/.classpath b/core/org.eclipse.cdt.alltests/.classpath new file mode 100644 index 00000000000..64c5e31b7a2 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/core/org.eclipse.cdt.alltests/.project b/core/org.eclipse.cdt.alltests/.project new file mode 100644 index 00000000000..94cab3b7457 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.alltests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/core/org.eclipse.cdt.alltests/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.alltests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..f88f26df757 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,65 @@ +#Fri Apr 25 15:24:03 EDT 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/core/org.eclipse.cdt.alltests/CDT Master Test Suite.launch b/core/org.eclipse.cdt.alltests/CDT Master Test Suite.launch new file mode 100644 index 00000000000..32c27f27b51 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/CDT Master Test Suite.launch @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.alltests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.alltests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..5d733b29c91 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.cdt.alltests +Bundle-Version: 8.1.0.qualifier +Require-Bundle: org.eclipse.core.runtime, + org.junit, + org.eclipse.cdt.core.tests, + org.eclipse.cdt.core, + org.eclipse.core.resources, + org.eclipse.cdt.autotools.tests, + org.eclipse.cdt.core.tests, + org.eclipse.cdt.ui.tests, + org.eclipse.cdt.codan.core.test, + org.eclipse.cdt.core.lrparser.tests, + org.eclipse.cdt.make.core.tests, + org.eclipse.cdt.managedbuilder.core.tests, + org.eclipse.cdt.managedbuilder.ui.tests, + org.eclipse.cdt.testsrunner.test, + org.eclipse.cdt.core.parser.upc.tests, + org.eclipse.cdt.errorparsers.xlc.tests, + org.eclipse.cdt.core.lrparser.xlc.tests, + org.eclipse.cdt.debug.ui.tests +Bundle-Vendor: %Bundle-Vendor.0 +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/core/org.eclipse.cdt.alltests/README.txt b/core/org.eclipse.cdt.alltests/README.txt new file mode 100644 index 00000000000..2a8897a04ff --- /dev/null +++ b/core/org.eclipse.cdt.alltests/README.txt @@ -0,0 +1,7 @@ +This plugin is a convenience for developers wanting to run all the junit3 tests +in CDT from within the IDE with a single click. It contains a container test +class and a launch configuration. If you're interested in running only a subset +of the tests, simply comment out lines in AllTests.java. + +Keep in mind some of the tests require a toolchain to be in PATH. So Windows +developers will need to have MinGW or Cygwin installed. \ No newline at end of file diff --git a/core/org.eclipse.cdt.alltests/about.html b/core/org.eclipse.cdt.alltests/about.html new file mode 100644 index 00000000000..9b669c2fd0c --- /dev/null +++ b/core/org.eclipse.cdt.alltests/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

February 8, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/core/org.eclipse.cdt.alltests/build.properties b/core/org.eclipse.cdt.alltests/build.properties new file mode 100644 index 00000000000..417826ea2a9 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/build.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2007, 2009 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties +src.includes = about.html diff --git a/core/org.eclipse.cdt.alltests/plugin.properties b/core/org.eclipse.cdt.alltests/plugin.properties new file mode 100644 index 00000000000..098506f8aea --- /dev/null +++ b/core/org.eclipse.cdt.alltests/plugin.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 Freescale Semiconductor Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Freescale Semiconductor - initial API and implementation +############################################################################### +# properties file for org.eclipse.cdt.core.parser.c99.tests +Bundle-Vendor.0 = Eclipse CDT +Bundle-Name.0 = CDT Master Test Suite diff --git a/core/org.eclipse.cdt.alltests/pom.xml b/core/org.eclipse.cdt.alltests/pom.xml new file mode 100644 index 00000000000..509c72ed7d3 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.2.0-SNAPSHOT + ../../pom.xml + + + 5.1.0-SNAPSHOT + org.eclipse.cdt.core.parser.upc.tests + eclipse-test-plugin + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + false + -Xms256m -Xmx512m -XX:MaxPermSize=256M + + **/UPCParserTestSuite.* + + true + + + + + diff --git a/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java new file mode 100644 index 00000000000..9ad243b9256 --- /dev/null +++ b/core/org.eclipse.cdt.alltests/src/org/eclipse/cdt/alltests/AllTests.java @@ -0,0 +1,39 @@ +package org.eclipse.cdt.alltests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Container for all the junit3 tests in CDT + * + * Keep in mind that some of these tests require that a GNU toolchain be in + * PATH. (I.e., on Windows, make sure you have MinGW or Cygwin) + */ +public class AllTests extends TestSuite { + public static Test suite() throws Exception { + final AllTests suite = new AllTests(); + suite.addTest(org.eclipse.cdt.autotools.tests.AllAutotoolsTests.suite()); // Works with MinGW but not Cygwin +// // There are intermittent failures in these tests. No pattern to failures. Seems like indexer is interrupted + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ + suite.addTest(org.eclipse.cdt.codan.core.test.AutomatedIntegrationSuite.suite()); + suite.addTest(org.eclipse.cdt.core.lrparser.tests.LRParserTestSuite.suite()); + suite.addTest(org.eclipse.cdt.core.parser.xlc.tests.suite.XlcTestSuite.suite()); + } + + suite.addTest(org.eclipse.cdt.core.parser.upc.tests.UPCParserTestSuite.suite()); + suite.addTest(org.eclipse.cdt.core.suite.AutomatedIntegrationSuite.suite()); + + // These tests fail intermittently due to gdb not shutting down and thus + // not being able to delete the project (exe locked) + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ + suite.addTest(org.eclipse.cdt.debug.core.tests.AllDebugTests.suite()); + } + suite.addTest(org.eclipse.cdt.errorparsers.xlc.tests.AllXlcErrorParserTests.suite()); + suite.addTest(org.eclipse.cdt.make.core.tests.AutomatedIntegrationSuite.suite()); + suite.addTest(org.eclipse.cdt.managedbuilder.tests.suite.AllManagedBuildTests.suite()); + suite.addTest(org.eclipse.cdt.managedbuilder.ui.tests.suite.AllManagedBuildUITests.suite()); + suite.addTest(org.eclipse.cdt.testsrunner.test.TestsRunnerSuite.suite()); + suite.addTest(org.eclipse.cdt.ui.tests.AutomatedSuite.suite()); + return suite; + } +} diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java index 894a16ef159..67927625397 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java @@ -937,6 +937,12 @@ public class ErrorParserFileMatchingTest extends TestCase { // Skip the test if Cygwin is not available. return; } + + // Consistently fails, and, yes, I do have Cygwin in my PATH + if (System.getProperty("cdt.skip.known.test.failures") != null) { //$NON-NLS-1$ + return; + } + assertTrue("usrIncludeWindowsPath=["+usrIncludeWindowsPath+"]", usrIncludeWindowsPath.charAt(1)==IPath.DEVICE_SEPARATOR); diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/resources/tests/RefreshScopeTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/resources/tests/RefreshScopeTests.java index 4bc8323db72..bbfc50bcb57 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/resources/tests/RefreshScopeTests.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/resources/tests/RefreshScopeTests.java @@ -53,6 +53,7 @@ import org.eclipse.core.runtime.IProgressMonitor; public class RefreshScopeTests extends TestCase { private IProject fProject; + private IProject fGeneralProject; private IFolder fFolder1; private IFolder fFolder2; private IFolder fFolder3; @@ -73,6 +74,20 @@ public class RefreshScopeTests extends TestCase { public void run(IProgressMonitor monitor) throws CoreException { ICProject cProject = CProjectHelper.createNewStileCProject("testRefreshScope", IPDOMManager.ID_NO_INDEXER, false); fProject = cProject.getProject(); + + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + fGeneralProject = root.getProject("testRefreshScopeGeneral"); + assertNotNull(fGeneralProject); + + if (!fGeneralProject.exists()) { + fGeneralProject.create(null); + } else { + fGeneralProject.refreshLocal(IResource.DEPTH_INFINITE, null); + } + + if (!fGeneralProject.isOpen()) { + fGeneralProject.open(null); + } } }, null); @@ -662,6 +677,21 @@ public class RefreshScopeTests extends TestCase { } + public void testNullProjectDescription_bug387428() { + final String CFG_NAME="empty_config"; + + CProjectDescriptionManager descriptionManager = CProjectDescriptionManager.getInstance(); + ICProjectDescription projectDescription = descriptionManager.getProjectDescription(fGeneralProject, false); + assertNull(projectDescription); + + RefreshScopeManager manager = RefreshScopeManager.getInstance(); + manager.clearAllData(); + + List empty_config_resources = manager.getResourcesToRefresh(fGeneralProject, CFG_NAME); + assertEquals(1,empty_config_resources.size()); + assertEquals(true,empty_config_resources.contains(fGeneralProject)); + } + public static Test suite() { return new TestSuite(RefreshScopeTests.class); } diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java index de54edc6425..72ee4c50cfe 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsScannerInfoProviderTests.java @@ -458,6 +458,10 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { // "relative" should make no difference for VALUE_WORKSPACE_PATH IPath incWorkspaceRelativePath_3 = incWorkspace_3.getFullPath().makeRelative(); IPath incWorkspaceLocation_3 = incWorkspace_3.getLocation(); + // not having "RESOLVED" should make no difference for well formed path + IFolder incWorkspace_4 = ResourceHelper.createFolder(project, "include_4"); + IPath incWorkspacePathNoResolved_4 = incWorkspace_4.getFullPath(); + IPath incWorkspaceLocation_4 = incWorkspace_4.getLocation(); // folder defined by absolute path on the filesystem IPath incFilesystem = ResourceHelper.createWorkspaceFolder("includeFilesystem"); @@ -465,12 +469,14 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { CIncludePathEntry incWorkspaceEntry_1 = new CIncludePathEntry(incWorkspace_1, 0); CIncludePathEntry incWorkspaceEntry_2 = new CIncludePathEntry(incWorkspacePath_2, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); CIncludePathEntry incWorkspaceEntry_3 = new CIncludePathEntry(incWorkspaceRelativePath_3, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); + CIncludePathEntry incWorkspaceEntry_4 = new CIncludePathEntry(incWorkspacePathNoResolved_4, ICSettingEntry.VALUE_WORKSPACE_PATH); CIncludePathEntry incFilesystemEntry = new CIncludePathEntry(incFilesystem, 0); List entries = new ArrayList(); entries.add(incWorkspaceEntry_1); entries.add(incWorkspaceEntry_2); entries.add(incWorkspaceEntry_3); + entries.add(incWorkspaceEntry_4); entries.add(incFilesystemEntry); // add provider to the configuration @@ -490,8 +496,9 @@ public class LanguageSettingsScannerInfoProviderTests extends BaseTestCase { assertEquals(incWorkspaceLocation_1, new Path(actualIncludePaths[0])); assertEquals(incWorkspaceLocation_2, new Path(actualIncludePaths[1])); assertEquals(incWorkspaceLocation_3, new Path(actualIncludePaths[2])); - assertEquals(incFilesystem, new Path(actualIncludePaths[3])); - assertEquals(4, actualIncludePaths.length); + assertEquals(incWorkspaceLocation_4, new Path(actualIncludePaths[3])); + assertEquals(incFilesystem, new Path(actualIncludePaths[4])); + assertEquals(5, actualIncludePaths.length); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 8f172f0f911..3cdbabd1573 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -141,12 +140,6 @@ public class AST2BaseTest extends BaseTestCase { return parse(code, lang, useGNUExtensions, true); } - /** - * @param string - * @param c - * @return - * @throws ParserException - */ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { return parse(code, lang, useGNUExtensions, expectNoProblems, false); @@ -221,9 +214,6 @@ public class AST2BaseTest extends BaseTestCase { return scanner; } - /** - * @param string - */ protected void validateSimplePostfixInitializerExpressionC(String code) throws ParserException { ICASTTypeIdInitializerExpression e = (ICASTTypeIdInitializerExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -231,10 +221,6 @@ public class AST2BaseTest extends BaseTestCase { assertNotNull(e.getInitializer()); } - /** - * @param string - * @throws ParserException - */ protected void validateSimpleUnaryTypeIdExpression(String code, int op) throws ParserException { IASTCastExpression e = (IASTCastExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -244,11 +230,6 @@ public class AST2BaseTest extends BaseTestCase { assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ } - /** - * @param code - * @param op - * @throws ParserException - */ protected void validateSimpleTypeIdExpressionC(String code, int op) throws ParserException { IASTTypeIdExpression e = (IASTTypeIdExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -256,11 +237,6 @@ public class AST2BaseTest extends BaseTestCase { assertNotNull(e.getTypeId()); } - /** - * @param string - * @param op_prefixIncr - * @throws ParserException - */ protected void validateSimpleUnaryExpressionC(String code, int operator) throws ParserException { IASTUnaryExpression e = (IASTUnaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -269,10 +245,6 @@ public class AST2BaseTest extends BaseTestCase { assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ } - /** - * @param code - * @throws ParserException - */ protected void validateConditionalExpressionC(String code) throws ParserException { IASTConditionalExpression e = (IASTConditionalExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -284,10 +256,6 @@ public class AST2BaseTest extends BaseTestCase { assertEquals(x.getName().toString(), x2.getName().toString()); } - /** - * @param operand - * @throws ParserException - */ protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException { IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); @@ -322,24 +290,29 @@ public class AST2BaseTest extends BaseTestCase { { shouldVisitNames = true; } - public List nameList = new ArrayList(); + public List nameList = new ArrayList(); + @Override public int visit(IASTName name) { nameList.add(name); return PROCESS_CONTINUE; } + public IASTName getName(int idx) { if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get(idx); + return nameList.get(idx); } - public int size() { return nameList.size(); } + + public int size() { + return nameList.size(); + } } protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception { int count = 0; - if (binding == null) assertTrue(false); + assertNotNull(binding); for (int i = 0; i < collector.size(); i++) { if (collector.getName(i).resolveBinding() == binding) @@ -354,17 +327,22 @@ public class AST2BaseTest extends BaseTestCase { shouldVisitNames = true; } public List nameList = new ArrayList(); + @Override public int visit(IASTName name) { nameList.add(name); return PROCESS_CONTINUE; } + public IASTName getName(int idx) { if (idx < 0 || idx >= nameList.size()) return null; return nameList.get(idx); } - public int size() { return nameList.size(); } + + public int size() { + return nameList.size(); + } public void dump() { for (int i= 0; i < size(); i++) { @@ -434,9 +412,10 @@ public class AST2BaseTest extends BaseTestCase { { shouldVisitNames = true; } - public int numProblemBindings=0; - public int numNullBindings=0; - public List nameList = new ArrayList(); + public int numProblemBindings; + public int numNullBindings; + public List nameList = new ArrayList(); + @Override public int visit(IASTName name) { nameList.add(name); @@ -447,21 +426,26 @@ public class AST2BaseTest extends BaseTestCase { numNullBindings++; return PROCESS_CONTINUE; } + public IASTName getName(int idx) { if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get(idx); + return nameList.get(idx); } - public int size() { return nameList.size(); } + + public int size() { + return nameList.size(); + } } static protected class CPPNameResolver extends ASTVisitor { { shouldVisitNames = true; } - public int numProblemBindings=0; - public int numNullBindings=0; - public List nameList = new ArrayList(); + public int numProblemBindings; + public int numNullBindings; + public List nameList = new ArrayList(); + @Override public int visit(IASTName name) { nameList.add(name); @@ -472,12 +456,16 @@ public class AST2BaseTest extends BaseTestCase { numNullBindings++; return PROCESS_CONTINUE; } + public IASTName getName(int idx) { if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get(idx); + return nameList.get(idx); } - public int size() { return nameList.size(); } + + public int size() { + return nameList.size(); + } } protected String getAboveComment() throws IOException { @@ -575,7 +563,7 @@ public class AST2BaseTest extends BaseTestCase { if (implicits.length > 1) { boolean found = false; for (IASTImplicitName n : implicits) { - if (((ASTNode) n).getOffset() == ((ASTNode)name).getOffset()) { + if (((ASTNode) n).getOffset() == ((ASTNode) name).getOffset()) { assertFalse(found); found = true; } @@ -662,8 +650,8 @@ public class AST2BaseTest extends BaseTestCase { } } } - } catch(IllegalAccessException iae) { - throw new RuntimeException(iae); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); } return "Unknown problem ID"; } @@ -736,18 +724,14 @@ public class AST2BaseTest extends BaseTestCase { } final protected void assertNoProblemBindings(CNameCollector col) { - Iterator i = col.nameList.iterator(); - while (i.hasNext()) { - IASTName n = (IASTName) i.next(); + for (IASTName n : col.nameList) { assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding); } } final protected void assertProblemBindings(CNameCollector col, int count) { - Iterator i = col.nameList.iterator(); int sum = 0; - while (i.hasNext()) { - IASTName n = (IASTName) i.next(); + for (IASTName n : col.nameList) { if (n.getBinding() instanceof IProblemBinding) ++sum; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index c64e96b3069..ef4f48076d4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 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: * Devin Steffler (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -859,6 +860,12 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, 0); } + // const char* strchr(const char* s, int c); + // bool b = noexcept (strchr("abc", 'b')); + public void test5_3_7() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + // struct A {}; // struct I1 : A {}; // struct I2 : A {}; @@ -5747,7 +5754,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { // g(0); // The N member of C is not a non-type // h(0); // The TT member of D is not a template // } - public void _test14_8_2s8d() throws Exception { + public void test14_8_2s8d() throws Exception { final String content= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(content, true); bh.assertProblem("f", 0); @@ -6386,6 +6393,21 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, 0); } + // template + // void f(T p); + // + // template + // void g(T p) noexcept; + // + // template + // void fg(T a) noexcept (noexcept(f(a)) && noexcept(g(a))) { + // f(a); + // g(a); + // } + public void test15_4s1c() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, true, 0); + } + // struct B { // virtual void f() throw (int, double); // virtual void g(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 9f663484c0d..7465d5db67b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -11,6 +11,7 @@ * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -6252,20 +6253,20 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m5, m2)); assertTrue(ClassTypeHelper.isOverrider(m4, m2)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m1); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m4); + ors= ClassTypeHelper.findOverridden(m4, null); assertEquals(2, ors.length); assertSame(ors[0], m2); assertSame(ors[1], m1); - ors= ClassTypeHelper.findOverridden(m5); + ors= ClassTypeHelper.findOverridden(m5, null); assertEquals(1, ors.length); assertSame(ors[0], m1); } @@ -8732,14 +8733,14 @@ public class AST2CPPTests extends AST2BaseTest { assertFalse(ClassTypeHelper.isOverrider(m3, m0)); assertFalse(ClassTypeHelper.isOverrider(m3, m1)); - ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0); + ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m1); + ors= ClassTypeHelper.findOverridden(m1, null); assertEquals(0, ors.length); - ors= ClassTypeHelper.findOverridden(m2); + ors= ClassTypeHelper.findOverridden(m2, null); assertEquals(1, ors.length); assertSame(ors[0], m0); - ors= ClassTypeHelper.findOverridden(m3); + ors= ClassTypeHelper.findOverridden(m3, null); assertEquals(0, ors.length); } @@ -9288,7 +9289,7 @@ public class AST2CPPTests extends AST2BaseTest { // auto f2 (); // missing late return type. public void testBug332114a() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b= bh.assertNonProblem("f2", 0); // Must not throw a NPE IndexCPPSignatureUtil.getSignature(b); @@ -9546,7 +9547,7 @@ public class AST2CPPTests extends AST2BaseTest { public void testRecursiveClassInheritance_Bug357256() throws Exception { BindingAssertionHelper bh= getAssertionHelper(); ICPPClassType c= bh.assertNonProblem("A", 1); - assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length); + assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c, null).length); } // template struct CT1 {}; @@ -9713,7 +9714,7 @@ public class AST2CPPTests extends AST2BaseTest { // g( nullptr ); // error // } public void testNullptr_327298b() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertProblem("checkNullPtr(1)", 12); bh.assertProblem("checklvalue(nullptr)", 11); bh.assertProblem("g( nullptr )", 1); @@ -9727,7 +9728,7 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testNullptr_327298c() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IFunction f= bh.assertNonProblem("f( nullptr )", 1); assertEquals("void (char *)", ASTTypeUtil.getType(f.getType())); f= bh.assertNonProblem("f( 0 )", 1); @@ -9736,10 +9737,35 @@ public class AST2CPPTests extends AST2BaseTest { // void foo(struct S s); public void testParameterForwardDeclaration_379511() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType struct= bh.assertNonProblem("S", 1, ICPPClassType.class); IName[] declarations= bh.getTranslationUnit().getDeclarations(struct); assertEquals(1, declarations.length); assertEquals(bh.findName("S", 1), declarations[0]); } + + // struct F {}; + // struct S { + // friend F; + // }; + public void testFriendClass() throws Exception { + parseAndCheckBindings(); + } + + // struct F {}; + // typedef F T; + // struct S { + // friend T; + // }; + public void testFriendTypedef() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct T { + // friend P; + // }; + public void testFriendTemplateParameter() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java index 7d1cc7b638a..8aca7558fa4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java @@ -73,31 +73,20 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { return tu.getNodeSelector(null).findNode(offset, length); } - /** - * @param string - * @param c - * @return - * @throws ParserException - */ - protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; - if( lang == ParserLanguage.CPP ) - { + if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (useGNUExtensions) config = new GPPParserExtensionConfiguration(); else config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, - config ); - } - else - { + parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); + } else { ICParserExtensionConfiguration config = null; if (useGNUExtensions) @@ -105,56 +94,45 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { else config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, - NULL_LOG, config ); + parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); } IASTTranslationUnit tu = parser2.parse(); - if( parser2.encounteredError() && expectNoProblems ) - throw new ParserException( "FAILURE"); //$NON-NLS-1$ + if (parser2.encounteredError() && expectNoProblems) + throw new ParserException("FAILURE"); //$NON-NLS-1$ - if( lang == ParserLanguage.C && expectNoProblems ) - { - assertEquals( CVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); + if (lang == ParserLanguage.C && expectNoProblems) { + assertEquals(CVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); + } else if (lang == ParserLanguage.CPP && expectNoProblems) { + assertEquals(CPPVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); } - else if ( lang == ParserLanguage.CPP && expectNoProblems ) - { - assertEquals( CPPVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); - } - if( expectNoProblems ) - assertEquals( 0, tu.getPreprocessorProblems().length ); - + if (expectNoProblems) + assertEquals(0, tu.getPreprocessorProblems().length); return tu; } - protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException { - - IASTTranslationUnit tu=null; + protected IASTTranslationUnit parse(IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { + IASTTranslationUnit tu= null; try { tu = CDOM.getInstance().getASTService().getTranslationUnit(file); } catch (UnsupportedDialectException e) { assertFalse(true); // shouldn't happen } - if( lang == ParserLanguage.C && expectNoProblems ) - { - assertEquals( CVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); + if (lang == ParserLanguage.C && expectNoProblems) { + assertEquals(CVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); + } else if (lang == ParserLanguage.CPP && expectNoProblems) { + assertEquals(CPPVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); } - else if ( lang == ParserLanguage.CPP && expectNoProblems ) - { - assertEquals( CPPVisitor.getProblems(tu).length, 0 ); - assertEquals( tu.getPreprocessorProblems().length, 0 ); - } - if( expectNoProblems ) - assertEquals( 0, tu.getPreprocessorProblems().length ); - + if (expectNoProblems) + assertEquals(0, tu.getPreprocessorProblems().length); return tu; } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 6a650ca9ad2..a35448d8d20 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; +import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType; @@ -81,13 +82,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; +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.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class AST2TemplateTests extends AST2BaseTest { @@ -107,11 +109,11 @@ public class AST2TemplateTests extends AST2BaseTest { } private IASTTranslationUnit parseAndCheckBindings(final String code) throws Exception { - return parseAndCheckBindings(code, ParserLanguage.CPP); + return parseAndCheckBindings(code, CPP); } public void testBasicClassTemplate() throws Exception { - IASTTranslationUnit tu = parse("template class A{ T t; };", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("template class A{ T t; };", CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -143,7 +145,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.t1; a.t2; // } public void testBasicTemplateInstance_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -194,7 +196,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.f((int*)0); // } public void testBasicTemplateInstance_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -226,7 +228,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(0); // } public void testBasicTemplateFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -255,7 +257,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class U > pair(const pair &); // }; public void testStackOverflow() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -276,7 +278,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T > class A< T* > {}; // template < class T > class A< T** > {}; public void testBasicClassPartialSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -302,7 +304,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T > typename A::TYPE foo(T); // template < class T > typename A::TYPE foo(T); public void testStackOverflow_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -337,7 +339,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template < class T > void A::f() { } public void testTemplateMemberDef() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -352,7 +354,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(1); // } public void testTemplateFunctionImplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -371,7 +373,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(p); //calls f(const T *) , 3 is more specialized than 1 or 2 // } public void test_14_5_5_2s5_OrderingFunctionTemplates_1() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -395,7 +397,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(x); //ambiguous 1 or 2 // } public void test_14_5_5_2s5_OrderingFunctionTemplates_2() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -411,7 +413,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template < class T, template < class X > class U, T *pT > class A { // }; public void testTemplateParameters() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -438,7 +440,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->a; // } public void testDeferredInstances() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -478,7 +480,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A a4; //uses #5, T is int, T2 is char, I is1 // A a5; //ambiguous, matches #3 & #5. public void test_14_5_4_1s2_MatchingTemplateSpecializations() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -521,7 +523,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template <> void f(int); //ok // template <> void f(int*); //ok public void test14_7_3_FunctionExplicitSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -538,7 +540,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T*); // void g(int* p) { f(p); } public void test_14_5_5_1_FunctionTemplates_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -552,7 +554,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T); // void g(int* p) { f(p); } public void test_14_5_5_1_FunctionTemplates_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -568,7 +570,7 @@ public class AST2TemplateTests extends AST2BaseTest { // int i = f(5); // Y is int // } public void test_14_8_1s2_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -584,7 +586,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f("Annemarie"); // } public void test14_8_3s6_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -604,7 +606,7 @@ public class AST2TemplateTests extends AST2BaseTest { // g(ip); //calls #4 // } public void test14_5_5_2s6_FunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -631,7 +633,7 @@ public class AST2TemplateTests extends AST2BaseTest { // X* p2; // }; public void test14_6_1s1_LocalNames() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -652,7 +654,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(&b); //call f(char**) // } public void test14_8s2_() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -683,7 +685,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> inline void f<>(int) { } //OK: inline // template<> int g<>(int) { } // OK: not inline public void test14_7_3s14() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -712,7 +714,7 @@ public class AST2TemplateTests extends AST2BaseTest { // x.a.a.a.a; // } public void test14_7_1s14_InfiniteInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -744,7 +746,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Y* q; // meaning Y // }; public void test14_6_1s2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -768,7 +770,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(g); // } public void testBug45129() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -791,7 +793,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.u; // } public void testBug76951_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -821,7 +823,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // void f(A p) { } public void testInstances() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -837,7 +839,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void f(T); // template void f(T) {} public void testTemplateParameterDeclarations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -859,7 +861,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a->pA; // }; public void testDeferredInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -905,7 +907,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ac.f<>(1); //template // } public void test14_5_2s2_MemberSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -949,7 +951,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A ac; // A ai; public void testClassSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -981,7 +983,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // explicitly specialized class template specialization // void A::f(int) { } public void test14_7_3s5_SpecializationMemberDefinition() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1018,7 +1020,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b.f(c); // } public void testNestedSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1060,7 +1062,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // A a; public void test14_5_4s7_UsingClassTemplate() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1090,7 +1092,7 @@ public class AST2TemplateTests extends AST2BaseTest { // c.y.x; c.z.x; // } public void testTemplateTemplateParameter() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1137,7 +1139,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.t; // } public void testNestedTypeSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1171,7 +1173,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.b.t; // } public void testNestedClassTypeSpecializations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1210,7 +1212,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A< C > a; a.s; // }; public void testTemplateParameterQualifiedType_1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1262,7 +1264,7 @@ public class AST2TemplateTests extends AST2BaseTest { // U u; // } public void testTemplateScopes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1286,7 +1288,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template void A::f<>(U){} public void testTemplateScopes_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1320,7 +1322,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A ab; // A ac; public void testEnclosingScopes_a() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPSpecialization b0= ba.assertNonProblem("A", 4, ICPPSpecialization.class, ICPPClassType.class); ICPPTemplateInstance b1= ba.assertNonProblem("A", 4, ICPPTemplateInstance.class, ICPPClassType.class); @@ -1363,7 +1365,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::B adb; // } public void testEnclosingScopes_b() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("B acb", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("B adb", 1, ICPPClassType.class, ICPPSpecialization.class); @@ -1392,7 +1394,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // X::Y::Z xayz; public void testEnclosingScopes_c() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("Y::Z x", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("Z xayz", 1, ICPPClassType.class); @@ -1417,7 +1419,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // X::N n; public void testEnclosingScopes_d() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b0= ba.assertNonProblem("N n", 1, ICPPClassType.class); ICPPClassType b1= ba.assertNonProblem("N {", 1, ICPPClassType.class); @@ -1443,7 +1445,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> template<> void A::g(int,char); // template<> void A::h(int) { } public void test14_7_3s16() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1505,7 +1507,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C b; // C is the template parameter, not N::C // } public void test14_6_1s6() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1538,7 +1540,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void sort(Array &); // template void sort<>(Array &); public void testBug90689_ExplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1564,7 +1566,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void sort(Array& v) { } // template void sort(Array&); // argument is deduced here public void test14_7_2s2_ExplicitInstantiation() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1587,7 +1589,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f() { this; } // }; public void testBug74204() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1606,7 +1608,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(t); // } public void testDeferredFunctionTemplates() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1625,7 +1627,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testRelaxationForTemplateInheritance() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1651,7 +1653,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // } public void testBug91707() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1681,7 +1683,7 @@ public class AST2TemplateTests extends AST2BaseTest { // (*t).i; // } public void testBug98961() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1704,7 +1706,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void begin(); // }; public void testBug98784() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1719,7 +1721,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(A(1)); // } public void testBug99254() throws Exception{ - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1749,7 +1751,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->add(core::A(10, 2)); // } public void testBug99254_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1776,7 +1778,7 @@ public class AST2TemplateTests extends AST2BaseTest { // b->add(A(10)); // } public void testBug99254_3() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1796,7 +1798,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testBug98666() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse("A::template B b;", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("A::template B b;", CPP); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1815,7 +1817,7 @@ public class AST2TemplateTests extends AST2BaseTest { // struct A::C::B{}; // A::C::B ab; public void testBug90678() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu = parse(getAboveComment(), CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1847,7 +1849,7 @@ public class AST2TemplateTests extends AST2BaseTest { // int l = f<>(1); // uses #1 public void testBug95208() throws Exception { String content= getAboveComment(); - IASTTranslationUnit tu = parse(content, ParserLanguage.CPP); + IASTTranslationUnit tu = parse(content, CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1862,7 +1864,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame(f1, col.getName(10).resolveBinding()); - tu = parse(content,ParserLanguage.CPP); + tu = parse(content,CPP); col = new CPPNameCollector(); tu.accept(col); @@ -1876,7 +1878,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A broken; // }; public void testBug103578() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1896,7 +1898,7 @@ public class AST2TemplateTests extends AST2BaseTest { // a.base; // } public void testBug103715() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1906,7 +1908,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(6).resolveBinding(); - ICPPBase[] bases = A.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(A, tu); assertEquals(bases.length, 1); assertSame(bases[0].getBaseClass(), B); } @@ -1921,7 +1923,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void complex::f(float){ // } public void testBug74276() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1947,7 +1949,7 @@ public class AST2TemplateTests extends AST2BaseTest { // myType t; // } public void testBug105852() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1968,7 +1970,7 @@ public class AST2TemplateTests extends AST2BaseTest { // k.c; // } public void testBug105769() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1983,7 +1985,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template <> C(wchar_t * c) : blah(c) {} // }; public void testBug162230() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2018,7 +2020,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template< class T > class C {}; // typedef struct C CInt; public void testBug169628() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2042,7 +2044,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testBug201204() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("makeClosure(this", 11, ICPPFunction.class); } @@ -2068,7 +2070,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(d, &C::m2); // } public void testBug233889() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn1= bh.assertNonProblem("func(c", 4, ICPPFunction.class); ICPPFunction fn2= bh.assertNonProblem("func(d", 4, ICPPFunction.class); assertNotSame(fn1, fn2); @@ -2091,7 +2093,7 @@ public class AST2TemplateTests extends AST2BaseTest { // GetPair(x, 1); // } public void testBug229917_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn = bh.assertNonProblem("GetPair(x", 7, ICPPFunction.class); } @@ -2108,7 +2110,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template // typename _C::value_type GetPair(_C& collection, typename _C::value_type::first_type key); public void testBug229917_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b0 = bh.assertNonProblem("value_type GetPair", 10, IBinding.class); } @@ -2127,7 +2129,7 @@ public class AST2TemplateTests extends AST2BaseTest { // str.m(); // } public void testBug232086() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0 = bh.assertNonProblem("m();", 1, ICPPFunction.class); } @@ -2150,7 +2152,7 @@ public class AST2TemplateTests extends AST2BaseTest { // bar(ca); // } public void testBug214646() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IBinding b0= bh.assertNonProblem("foo(a)", 3); IBinding b1= bh.assertNonProblem("bar(ca)", 3); @@ -2182,7 +2184,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(a2); // } public void testFunctionTemplate_245049_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0= bh.assertNonProblem("func(a1)", 4, ICPPFunction.class); assertInstance(b0, ICPPTemplateInstance.class); ICPPFunction b1= bh.assertNonProblem("func(a2)", 4, ICPPFunction.class); @@ -2205,7 +2207,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(a2); // } public void testFunctionTemplate_245049_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction b0= bh.assertNonProblem("func(a1)", 4, ICPPFunction.class); assertInstance(b0, ICPPTemplateInstance.class); ICPPFunction b1= bh.assertNonProblem("func(a2)", 4, ICPPFunction.class); @@ -2228,7 +2230,7 @@ public class AST2TemplateTests extends AST2BaseTest { // using ns::make_pair; // pair p = make_pair(1, 2); public void testFunctionTemplateWithUsing() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("make_pair(1", 9, ICPPFunction.class); } @@ -2246,7 +2248,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(a(x)); // } public void testFunctionTemplate_264963() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f(a(x));", 1, ICPPFunction.class); } @@ -2261,7 +2263,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f(&A::m); // } public void testFunctionTemplate_266532() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f(&A::m);", 1, ICPPFunction.class); } @@ -2336,7 +2338,7 @@ public class AST2TemplateTests extends AST2BaseTest { // f1(x, &f2); // } public void testFunctionTemplateWithFunctionPointer_281783() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("f1(x, &f2);", 2, ICPPFunction.class); } @@ -2362,7 +2364,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // foo -> CPPMethodInstance // } public void testCPPConstructorTemplateSpecialization() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2384,7 +2386,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return (lhs < rhs ? rhs : lhs); // } public void testNestedFuncTemplatedDeclarator_bug190241() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2434,7 +2436,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(B::tb r) {} public void testTemplateTypedef_214447() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2468,7 +2470,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(Vec::reference r) {} public void testRebindPattern_214447_1() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2508,7 +2510,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(Vec::reference r) {} public void testRebindPattern_214447_2() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2547,7 +2549,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void f(map::value_type r) {} public void testRebindPattern_236197() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); for (IASTName name : col.nameList) { @@ -2579,7 +2581,7 @@ public class AST2TemplateTests extends AST2BaseTest { // void main(Iter::iter_reference r); public void testSpecializationSelection_229218() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); for (IASTName name : col.nameList) { @@ -2608,7 +2610,7 @@ public class AST2TemplateTests extends AST2BaseTest { // B::b::a x; public void testDefaultTemplateParameter() throws Exception { CPPASTNameBase.sAllowNameComputation= true; - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2658,7 +2660,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(d); // } public void testUserDefinedConversions_224364() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class); } @@ -2678,7 +2680,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(d); // } public void testUserDefinedConversions_224364_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class); } @@ -2701,7 +2703,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // Z z= foo(*new E()); public void testUserDefinedConversions_224364_3() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(*new", 3, ICPPFunction.class); } @@ -2725,7 +2727,7 @@ public class AST2TemplateTests extends AST2BaseTest { // foo(cx); // } public void testUserDefinedConversions_226231() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunction fn= bh.assertNonProblem("foo(cx", 3, ICPPFunction.class); } @@ -2744,7 +2746,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return foo(c); // } public void testUserDefinedConversions_239023() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo(c);", 3); } @@ -2754,7 +2756,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testNonTypeArgumentIsIDExpression_229942_a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2773,7 +2775,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // }; public void testNonTypeArgumentIsIDExpression_229942_b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2787,7 +2789,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testExpressionArgumentIsExpression_229942_c() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2802,7 +2804,7 @@ public class AST2TemplateTests extends AST2BaseTest { // const int i= 1; // A a1; public void testTypeIdOperatorArgumentIsUnaryExpression_229942_d() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2815,7 +2817,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template< class T1, class T2, int q1, int q2> // class A< C, C > {}; public void testTemplateIdAsTemplateArgumentIsTypeId_229942_e() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2845,10 +2847,10 @@ public class AST2TemplateTests extends AST2BaseTest { // return at; // } public void testTypeIdAsTemplateArgumentIsTypeId_229942_f() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("T> at) {", 1); - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2868,7 +2870,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline const void foo(void (*f)(A), T* t) { // disallowed, but we're testing the AST // } public void testTypeIdAsTemplateArgumentIsTypeId_229942_g() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -2884,7 +2886,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template<> class Alias { // }; public void testNonAmbiguityCase_229942_h() throws Exception { - IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parse(getAboveComment(), CPP); CPPNameCollector col= new CPPNameCollector(); tu.accept(col); @@ -2910,7 +2912,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C c1; // C<> c2; // ok - default args public void testMissingTemplateArgumentLists() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ba.assertProblem("B b1", 1); ba.assertNonProblem("B<> b2", 1, ICPPTemplateDefinition.class, ICPPClassType.class); ba.assertProblem("B<> b2", 3); @@ -2927,7 +2929,7 @@ public class AST2TemplateTests extends AST2BaseTest { // member1 = 0; // } public void testDefinitionOfClassTemplateWithNonTypeParameter() throws Exception { - BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba=new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod f1= ba.assertNonProblem("fun1(void);", 4, ICPPMethod.class); ICPPField m1= ba.assertNonProblem("member1;", 7, ICPPField.class); ICPPMethod f2= ba.assertNonProblem("fun1(void) {", 4, ICPPMethod.class); @@ -2953,7 +2955,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::B<> b; // } public void testNestedTemplateDefinitionParameter() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateTypeParameter T3a= ba.assertNonProblem("T3 f", 2, ICPPTemplateTypeParameter.class); ICPPTemplateTypeParameter T3b= ba.assertNonProblem("T3)", 2, ICPPTemplateTypeParameter.class); ICPPClassType b= ba.assertNonProblem("B<>", 3, ICPPClassType.class, ICPPTemplateInstance.class); @@ -2969,7 +2971,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::Y y; // A::Z z; public void testNonTypeArgumentDisambiguation_233460() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType b2= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b3= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b4= ba.assertNonProblem("A", 7, ICPPClassType.class, ICPPTemplateInstance.class); @@ -2998,7 +3000,7 @@ public class AST2TemplateTests extends AST2BaseTest { // A::X x; //3 should be an error // A::Y y; //4 should be an error public void testNonTypeBooleanArgumentDisambiguation() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType X= ba.assertNonProblem("X x; //1", 1, ICPPClassType.class); ICPPClassType Y= ba.assertNonProblem("Y y; //2", 1, ICPPClassType.class); @@ -3029,7 +3031,7 @@ public class AST2TemplateTests extends AST2BaseTest { // baz(); // } public void testBug207871() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPVariable _256= ba.assertNonProblem("_256=0x100", 4, ICPPVariable.class); IQualifierType qt1= assertInstance(_256.getType(), IQualifierType.class); @@ -3070,7 +3072,7 @@ public class AST2TemplateTests extends AST2BaseTest { // C go(); // }; public void testDeferredNonTypeArgument() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPDeferredClassInstance ci= ba.assertNonProblem("C", 4, ICPPDeferredClassInstance.class); ICPPTemplateArgument[] args= ci.getTemplateArguments(); assertEquals(1, args.length); @@ -3082,7 +3084,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // A aint; // should be an error public void testTypeArgumentToNonTypeParameter() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertProblem("A", 6); } @@ -3102,7 +3104,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline This::This() : That(I) { // } public void testParameterReferenceInChainInitializer_a() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); // These intermediate assertions will not hold until deferred non-type arguments are // correctly modelled @@ -3135,7 +3137,7 @@ public class AST2TemplateTests extends AST2BaseTest { // inline This::This() : That() { // } public void testParameterReferenceInChainInitializer_b() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType tid= ba.assertNonProblem("This::T", 7, ICPPClassType.class); assertFalse(tid instanceof ICPPSpecialization); @@ -3157,7 +3159,7 @@ public class AST2TemplateTests extends AST2BaseTest { // // C ca5L; public void testIntegralConversionInPartialSpecializationMatching_237914() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateInstance ctps= ba.assertNonProblem("C", 7, ICPPTemplateInstance.class, ICPPClassType.class); assertInstance(ctps.getTemplateDefinition(), ICPPClassTemplatePartialSpecialization.class); } @@ -3177,7 +3179,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ca5L.test= 0; // } public void testIntegralConversionInSpecializationMatching_237914() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPSpecialization ctps= ba.assertNonProblem("C", 7, ICPPSpecialization.class, ICPPClassType.class); ba.assertNonProblem("test=", 4, ICPPField.class); } @@ -3193,7 +3195,7 @@ public class AST2TemplateTests extends AST2BaseTest { // B(const B& other) : A(other) {} // }; public void testChainInitializerLookupThroughDeferredClassBase() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("A(other", 1); } @@ -3212,7 +3214,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testMemberLookupThroughDeferredClassBase() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo(s", 3); } @@ -3228,7 +3230,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return foo(); // } public void testMemberReferenceFromTemplatedMethodDefinition_238232() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("foo();", 3); } @@ -3254,7 +3256,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testBug238180_ArrayOutOfBounds() throws Exception { // the code above used to trigger an ArrayOutOfBoundsException - parse(getAboveComment(), ParserLanguage.CPP); + parse(getAboveComment(), CPP); } // namespace detail { @@ -3273,7 +3275,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // detail public void testBug238180_ClassCast() throws Exception { // the code above used to trigger a ClassCastException - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPClassType p= ba.assertNonProblem("str", 0, ICPPClassType.class); ICPPConstructor con= p.getConstructors()[1]; ICPPReferenceType reftype= (ICPPReferenceType) con.getType().getParameterTypes()[0]; @@ -3293,7 +3295,7 @@ public class AST2TemplateTests extends AST2BaseTest { // test(new X(g)); // } public void testBug239586_ClassCast() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // template class CT { @@ -3301,7 +3303,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template int CT::x = sizeof(T); public void testUsingTemplParamInInitializerOfStaticField() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPTemplateTypeParameter t= ba.assertNonProblem("T)", 1, ICPPTemplateTypeParameter.class); } @@ -3348,7 +3350,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(cb); // } public void testTemplateMetaProgramming_245027() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod method= ba.assertNonProblem("method();", 6, ICPPMethod.class); ICPPVariable a= ba.assertNonProblem("a =", 1, ICPPVariable.class); ICPPVariable b= ba.assertNonProblem("b =", 1, ICPPVariable.class); @@ -3374,7 +3376,7 @@ public class AST2TemplateTests extends AST2BaseTest { // ns1::A<(sizeof(probe(x)) == 1)>::m(x); // } public void testNonTypeTemplateParameter_252108() throws Exception { - BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), CPP); ba.assertNonProblem("x))", 1, ICPPVariable.class); } @@ -3399,7 +3401,7 @@ public class AST2TemplateTests extends AST2BaseTest { @Override public void run() { try { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } catch (Throwable e) { th[0]= e; } @@ -3419,7 +3421,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; // template void A::foo(T t) {} public void testBug177418() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true ); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true ); CPPNameCollector col = new CPPNameCollector(); tu.accept( col ); @@ -3456,7 +3458,7 @@ public class AST2TemplateTests extends AST2BaseTest { // return new CT; // } public void testNewOfThisTemplate() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // template void f(T); @@ -3466,7 +3468,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFunctionSpecializationAsFriend() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f= bh.assertNonProblem("f(T)", 1); IFunction fref1= bh.assertNonProblem("f<>", 1); assertSame(fref1, f); @@ -3493,7 +3495,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testMethodImplWithNonDeferredType() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod m1= bh.assertNonProblem("m1();", 2); ICPPMethod m2= bh.assertNonProblem("m1() ", 2); assertSame(m1, m2); @@ -3518,7 +3520,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testClassTemplateMemberFunctionTemplate_Bug104262() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate A1= bh.assertNonProblem("A1", 2); ICPPMethod method= bh.assertNonProblem("A1::f1", 13); @@ -3541,7 +3543,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testQualifiedMethodTemplate() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod mt1= bh.assertNonProblem("m(V);", 1); ICPPMethod mt2= bh.assertNonProblem("m(V) ", 1); @@ -3570,7 +3572,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFieldReference_Bug257186() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IBinding a1= bh.assertNonProblem("a;", 1); IBinding a2= bh.assertNonProblem("a=", 1); @@ -3592,7 +3594,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testUnknownReferences_Bug257194() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("func();", 4, ICPPUnknownBinding.class); bh.assertNonProblem("var;", 3, ICPPUnknownBinding.class); @@ -3616,7 +3618,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeOfUnknownReferences_Bug257194a() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("b.c", 1, ICPPUnknownBinding.class); bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class); @@ -3641,7 +3643,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeOfUnknownReferences_Bug257194b() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("b->c", 1, ICPPUnknownBinding.class); bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class); @@ -3666,7 +3668,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTypeVsExpressionInArgsOfDependentTemplateID_257194() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPUnknownBinding b= bh.assertNonProblem("a>", 1); assertFalse(b instanceof IType); @@ -3702,7 +3704,7 @@ public class AST2TemplateTests extends AST2BaseTest { // func(p); // } public void testTypedefReference_259871() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("func(p)", 4, ICPPFunction.class); } @@ -3724,7 +3726,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testNestedTemplates_259872_1() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("A", 9, ICPPConstructor.class); } @@ -3749,7 +3751,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // }; public void testNestedTemplates_259872_2() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("A", 9, ICPPConstructor.class); } @@ -3768,7 +3770,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCtorWithTemplateID_259600() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPConstructor ctor= bh.assertNonProblem("DumbPtr/**/", 7); ICPPMethod dtor= bh.assertNonProblem("~DumbPtr/**/", 8); } @@ -3783,7 +3785,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCtorTemplateWithTemplateID_259600() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPConstructor ctor= bh.assertNonProblem("XT/**/", 2); ctor= bh.assertNonProblem("XT/**/", 5); } @@ -3807,7 +3809,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testResolutionOfUnknownBindings_262163() throws Exception { final String code = getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IVariable x= bh.assertNonProblem("x;", 1); ITypedef Nested= bh.assertNonProblem("Nested;", 6); IType t= x.getType(); @@ -3839,7 +3841,7 @@ public class AST2TemplateTests extends AST2BaseTest { // s.substr(0); // } public void testResolutionOfUnknownBindings_262328() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); bh.assertNonProblem("substr(0)", 6, ICPPMethod.class); } @@ -3881,7 +3883,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testConflictInTemplateArgumentDeduction() throws Exception { String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPMethod m= bh.assertNonProblem("append(3", 6); assertFalse(m instanceof ICPPTemplateInstance); } @@ -3900,7 +3902,7 @@ public class AST2TemplateTests extends AST2BaseTest { // p.m(); // } public void testConversionSequence_263159() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPMethod m= bh.assertNonProblem("m();", 1, ICPPMethod.class); } @@ -3921,7 +3923,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testForwardDeclarations_264109() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("A make_A(C* p) {", 4, ICPPTemplateInstance.class); parseAndCheckBindings(code); } @@ -3989,7 +3991,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testAmbiguousDeclaratorInFunctionTemplate_265342() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("getline2(i)", 8, ICPPTemplateInstance.class); parseAndCheckBindings(code); } @@ -4008,7 +4010,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testOwnerOfFriendTemplate_265671() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IFunction f= bh.assertNonProblem("f1(", 2, IFunction.class); IBinding owner= f.getOwner(); assertNull(owner); @@ -4034,7 +4036,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void g(T t) {} public void testDependentNameReferencingLaterDeclaration_265926a() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); IFunction gref= bh.assertNonProblem("g(t)", 1); assertInstance(gref, ICPPUnknownBinding.class); IFunction gdecl= bh.assertNonProblem("g(T t)", 1); @@ -4164,7 +4166,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testMethodSpecialization_322988() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } @@ -4198,7 +4200,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testInlineFriendFunction_287409() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunction func= bh.assertNonProblem("f(x)", 1, ICPPFunction.class); assertFalse(func instanceof ICPPUnknownBinding); } @@ -4231,7 +4233,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testResolutionOfNonDependentNames_293052() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunction func= bh.assertNonProblem("m();", 1, ICPPFunction.class); assertFalse(func instanceof ICPPUnknownBinding); bh.assertProblem("n();", 1); @@ -4256,7 +4258,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testArgumentDeduction_293409() throws Exception { final String code = getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f1(d);", 2, ICPPFunction.class); bh.assertNonProblem("f2(&d);", 2, ICPPFunction.class); bh.assertNonProblem("f2(&cd);", 2, ICPPFunction.class); @@ -4323,7 +4325,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testClosingAngleBrackets2_261268() throws Exception { final String code= getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.CPP, true, false); + IASTTranslationUnit tu = parse(code, CPP, true, false); IASTFunctionDefinition fdef= getDeclaration(tu, 2); IASTProblemStatement p1= getStatement(fdef, 1); } @@ -4364,22 +4366,22 @@ public class AST2TemplateTests extends AST2BaseTest { public void testRValueReferences_1_294730() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassType type= bh.assertNonProblem("X", 7); - ICPPMethod[] ms= type.getMethods(); + ICPPMethod[] ms= ClassTypeHelper.getMethods(type, null); int i= ms[0].getName().equals("f") ? 0 : 1; ICPPMethod m= ms[i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); type= bh.assertNonProblem("X", 14); - ms= type.getMethods(); + ms= ClassTypeHelper.getMethods(type, null); i= ms[0].getName().equals("f") ? 0 : 1; m= ms[i]; assertEquals("const int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); - m= ms[1-i]; + m= ms[1 - i]; assertEquals("const int &&", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); } @@ -4393,7 +4395,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testFunctionParameterPacks_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f= bh.assertNonProblem("f1", 2); assertEquals("void (int (*)(#0 ...))", ASTTypeUtil.getType(f.getType(), true)); assertFalse(f.getParameters()[0].isParameterPack()); @@ -4404,7 +4406,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertEquals("void (#0 (* ...)())", ASTTypeUtil.getType(f.getType(), true)); assertTrue(f.getParameters()[0].isParameterPack()); f= bh.assertNonProblem("f4", 2); - assertEquals("void (int (& ...)[`0])", ASTTypeUtil.getType(f.getType(), true)); + assertEquals("void (int (& ...)[3 *0 0])", ASTTypeUtil.getType(f.getType(), true)); assertTrue(f.getParameters()[0].isParameterPack()); f= bh.assertNonProblem("f5", 2); assertEquals("void (#0 ...)", ASTTypeUtil.getType(f.getType(), true)); @@ -4422,7 +4424,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTemplateParameterPacks_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate ct= bh.assertNonProblem("C1", 2); ICPPTemplateParameter tp= ct.getTemplateParameters()[0]; assertTrue(tp.isParameterPack()); @@ -4451,7 +4453,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testParameterPackExpansions_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPField field= bh.assertNonProblem("a= 1", 1); field= bh.assertNonProblem("b= 1", 1); @@ -4467,7 +4469,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testTemplateParameterPacksAmbiguity_280909() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate ft= bh.assertNonProblem("f1", 2); ICPPTemplateParameter tp= ft.getTemplateParameters()[0]; assertTrue(tp.isParameterPack()); @@ -4532,7 +4534,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Tuple* u; // syntax error public void testVariadicTemplateExamples_280909e() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("String<>", 6); bh.assertProblem("String*", 6); bh.assertNonProblem("Tuple<>", 5); @@ -4552,7 +4554,7 @@ public class AST2TemplateTests extends AST2BaseTest { // Y yc; // okay public void testVariadicTemplateExamples_280909f() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("X", 4); bh.assertProblem("X", 4); bh.assertProblem("X", 4); @@ -4575,7 +4577,7 @@ public class AST2TemplateTests extends AST2BaseTest { // template void B::f4() {} // error public void testVariadicTemplateExamples_280909g() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f1() {}", 2); bh.assertProblem("f2() {}", 2); bh.assertNonProblem("f3() {}", 2); @@ -4596,7 +4598,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } // int (*)(bool), Z is deduced to an empty sequence public void testVariadicTemplateExamples_280909h() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f(5.6)", 6); bh.assertProblem("f(5.6)", 1); bh.assertNonProblem("f(f)", 7); @@ -4617,7 +4619,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909i() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("f", 0); bh.assertNonProblem("f", 0); bh.assertNonProblem("f", 0); @@ -4673,7 +4675,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909p() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("Tuple<>", 0); bh.assertNonProblem("Tuple", 0); bh.assertNonProblem("Tuple", 0); @@ -4722,7 +4724,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testVariadicTemplateExamples_280909s() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ITypedef td= bh.assertNonProblem("T1;", 2); IType type = getNestedType(td, TDEF); assertEquals("Tuple,Pair>", ASTTypeUtil.getType(type, false)); @@ -4761,7 +4763,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testDefaultTemplateArgsForFunctionTemplates_294730() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPTemplateInstance f= bh.assertNonProblem("f(1, 'c');", 1); assertEquals("", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true)); @@ -4799,7 +4801,7 @@ public class AST2TemplateTests extends AST2BaseTest { // eval> eE; // error: E does not match TT in partial specialization public void testExtendingVariadicTemplateTemplateParameters_302282() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPClassTemplate ct= bh.assertNonProblem("eval;", -1); ICPPClassTemplatePartialSpecialization pspec= bh.assertNonProblem("eval>", 0); @@ -4833,7 +4835,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testExplicitSpecializations_296427() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPTemplateInstance inst; inst= bh.assertNonProblem("X", 0); @@ -4873,7 +4875,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testBug306213a() throws Exception { final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertNonProblem("func", 0); parseAndCheckBindings(code); } @@ -4890,7 +4892,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testBug306213b() throws Exception { CPPASTNameBase.sAllowRecursionBindings= true; final String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); bh.assertProblem("func", 0); } @@ -4917,7 +4919,7 @@ public class AST2TemplateTests extends AST2BaseTest { CPPASTNameBase.sAllowNameComputation= true; final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); final IASTTranslationUnit tu = bh.getTranslationUnit(); IBinding b= bh.assertNonProblem("CT {", 2); @@ -4950,7 +4952,7 @@ public class AST2TemplateTests extends AST2BaseTest { code.append('\n').append("int_<0> >::type,"); } code.append("int_<0> >::type tdef;"); - IASTTranslationUnit tu= parse(code.toString(), ParserLanguage.CPP, true, true); + IASTTranslationUnit tu= parse(code.toString(), CPP, true, true); tu = validateCopy(tu); assertEquals(1, tu.getDeclarations().length); } @@ -4986,7 +4988,7 @@ public class AST2TemplateTests extends AST2BaseTest { public void testInlineNamespaces_305980() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate ft= bh.assertNonProblem("f(T&)", 1); ICPPNamespace M= (ICPPNamespace) ft.getOwner(); @@ -5115,7 +5117,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testInstantiationOfFunctionTemplateWithOverloadedFunctionSetArgument_Bug326492() throws Exception { String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPFunctionTemplate f1= bh.assertNonProblem("f(T (*)(int), char)", 1); ICPPFunctionTemplate f2= bh.assertNonProblem("f(int (*)(T), int)", 1); IFunction g1= bh.assertNonProblem("g(char)", 1); @@ -5183,7 +5185,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testNestedTypedefSpecialization_Bug329795() throws Exception { String code= getAboveComment(); - BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + BindingAssertionHelper bh= new BindingAssertionHelper(code, CPP); ICPPField f1= bh.assertNonProblem("foo;", 3); IBinding f2= bh.assertNonProblem("foo =", 3); assertSame(f1, f2); @@ -5493,7 +5495,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testArgumentDeductionFromReturnTypeOfExplicitSpecialization_355304() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPFunctionTemplate template= bh.assertNonProblem("f();", 1); ICPPTemplateInstance inst= bh.assertNonProblem("f() {", 1); assertSame(template, inst.getTemplateDefinition()); @@ -5591,6 +5593,80 @@ public class AST2TemplateTests extends AST2BaseTest { parseAndCheckBindings(); } + // class A; + // class B; + // + // template + // struct bool_constant { + // static const bool value = bool_value; + // }; + // + // template + // struct ImplicitlyConvertible { + // static From MakeFrom(); + // + // static char Helper(To); + // static char (&Helper(...))[2]; + // + // static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; + // }; + // + // template + // struct IsAorB + // : public bool_constant< + // ImplicitlyConvertible::value || + // ImplicitlyConvertible::value> { + // }; + // + // namespace ns { + // + // template + // class C { + // }; + // + // template + // void f(V a); + // + // } // namespace ns + // + // void test() { + // ns::C::value> a; + // f(a); + // }; + public void testDependentExpressions_a() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct A { + // typedef T type; + // }; + // + // template + // struct B { + // struct C { + // template + // static typename V::pointer test(typename V::pointer*); + // template + // static T* test(...); + // + // typedef typename A::type D; + // typedef decltype(test(0)) type; + // }; + // + // typedef typename C::type pointer; + // }; + // + // B::pointer a; + public void testDependentExpressions_b() throws Exception { + parseAndCheckBindings(); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); + ICPPVariable var= bh.assertNonProblem("a;", 1, ICPPVariable.class); + IType type = var.getType(); + type = SemanticUtil.getNestedType(type, TDEF); + assertEquals("int *", type.toString()); + } + // template void* foo(int); // template void f(T t) { // if (T* i = foo<0>(0)) @@ -5715,7 +5791,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testTemplateShortNameInQualifiedName_367607() throws Exception { parseAndCheckBindings(); - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); ICPPDeferredClassInstance shortHand= bh.assertNonProblem("derived:", -1); assertTrue(shortHand.getClassTemplate() instanceof ICPPClassTemplatePartialSpecialization); } @@ -5762,7 +5838,7 @@ public class AST2TemplateTests extends AST2BaseTest { // e.x; // ERROR HERE: "Field 'x' could not be resolved" // } public void testAutoTypeWithTypedef_368311() throws Exception { - BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); IVariable v= bh.assertNonProblem("cur = r.begin()", 3); assertEquals("A::iterator_t", ASTTypeUtil.getType(v.getType(), true)); parseAndCheckBindings(); @@ -5832,4 +5908,84 @@ public class AST2TemplateTests extends AST2BaseTest { public void testConstInTypeParameter_377223() throws Exception { parseAndCheckBindings(); } + + // template + // struct integral_constant { + // static constexpr T value = v; + // typedef T value_type; + // typedef integral_constant type; + // }; + // + // typedef integral_constant true_type; + // + // typedef integral_constant false_type; + // + // template + // class helper { + // typedef char one; + // typedef struct { char arr[2]; } two; + // template struct Wrap_type {}; + // template static one test(Wrap_type*); + // template static two test(...); + // public: static const bool value = sizeof(test(0)) == 1; + // }; + // + // template + // struct has_category : integral_constant::value> {}; + // + // template::value> + // struct traits {}; + // + // template + // struct traits { + // typedef typename Iterator::value_type value_type; + // }; + // + // struct tag {}; + // + // struct C { + // typedef int value_type; + // typedef tag category; + // }; + // + // template::value_type> + // class A { + // }; + // + // typedef A type; + public void testSFINAE_a() throws Exception { + parseAndCheckBindings(); + } + + // template struct enable_if { typedef T type; }; + // template struct enable_if {}; + // + // template struct is_int { static const bool value = false; }; + // template <> struct is_int { static const bool value = true; }; + // + // template struct is_double { static const bool value = false; }; + // template <> struct is_double { static const bool value = true; }; + // + // template + // struct A { + // static int get() { return 0; } + // }; + // + // template + // struct A::value>::type> { + // static int get() { return 1; } + // }; + // + // template + // struct A::value>::type> { + // static int get() { return 2; } + // }; + // + // void test() { + // A::get(); + // A::get(); + // } + public void testSFINAE_b() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index d6fb38c2367..5c993b4ada3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -6327,11 +6327,6 @@ public class AST2Tests extends AST2BaseTest { return false; } - /** - * @param declarations - * @param index - * @return - */ private IBasicType getTypeForDeclaration(IASTDeclaration[] declarations, int index) { IASTInitializer init = ((IASTSimpleDeclaration) declarations[index]).getDeclarators()[0].getInitializer(); return (IBasicType)((IASTExpression)((IASTEqualsInitializer) init).getInitializerClause()).getExpressionType(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java index f3454e8e5cd..aadfeac5678 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ClassTypeHelperTests.java @@ -59,11 +59,11 @@ public class ClassTypeHelperTests extends AST2BaseTest { public void testHasTrivialCopyCtor() throws Exception { BindingAssertionHelper helper = getAssertionHelper(); ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classA)); + assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classA, null)); ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.hasTrivialCopyCtor(classB)); + assertTrue(ClassTypeHelper.hasTrivialCopyCtor(classB, null)); ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classC)); + assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classC, null)); } // struct A { @@ -87,11 +87,11 @@ public class ClassTypeHelperTests extends AST2BaseTest { public void testHasTrivialDestructor() throws Exception { BindingAssertionHelper helper = getAssertionHelper(); ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialDestructor(classA)); + assertFalse(ClassTypeHelper.hasTrivialDestructor(classA, null)); ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class); - assertTrue(ClassTypeHelper.hasTrivialDestructor(classB)); + assertTrue(ClassTypeHelper.hasTrivialDestructor(classB, null)); ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class); - assertFalse(ClassTypeHelper.hasTrivialDestructor(classC)); + assertFalse(ClassTypeHelper.hasTrivialDestructor(classC, null)); } // struct A { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 5e0277075f3..d2c052b0c22 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -90,7 +90,7 @@ import org.eclipse.core.runtime.Platform; public class CompleteParser2Tests extends BaseTestCase { private static final NullLogService NULL_LOG = new NullLogService(); - + public CompleteParser2Tests() { } public CompleteParser2Tests(String name) { @@ -107,16 +107,16 @@ public class CompleteParser2Tests extends BaseTestCase { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name){ + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx){ + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } static protected class CNameCollector extends ASTVisitor { { @@ -124,32 +124,32 @@ public class CompleteParser2Tests extends BaseTestCase { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name){ + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx){ + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } - protected void assertInstances( CPPNameCollector nameCollector, IBinding binding, int num ) throws Exception { + protected void assertInstances(CPPNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; - for( int i = 0; i < nameCollector.size(); i++ ) - if( nameCollector.getName( i ).resolveBinding() == binding ) + for (int i = 0; i < nameCollector.size(); i++) + if (nameCollector.getName(i).resolveBinding() == binding) count++; - - assertEquals( count, num ); + + assertEquals(count, num); } - protected void assertInstances( CNameCollector nameCollector, IBinding binding, int num ) throws Exception { + protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; - for( int i = 0; i < nameCollector.size(); i++ ) - if( nameCollector.getName( i ).resolveBinding() == binding ) + for (int i = 0; i < nameCollector.size(); i++) + if (nameCollector.getName(i).resolveBinding() == binding) count++; - - assertEquals( count, num ); + + assertEquals(count, num); } protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang) throws Exception { @@ -166,17 +166,9 @@ public class CompleteParser2Tests extends BaseTestCase { protected IASTTranslationUnit parse(String code) throws Exception { return parse(code, true, ParserLanguage.CPP); } - - /** - * @param string - * @param b - * @param c - * @param d - */ + protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - - FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); ISourceCodeParser parser2 = null; @@ -201,365 +193,339 @@ public class CompleteParser2Tests extends BaseTestCase { } IASTTranslationUnit tu = parser2.parse(); if (parser2.encounteredError() && expectedToPass) - throw new ParserException("FAILURE"); //$NON-NLS-1$ - if (expectedToPass) - { - if( lang == ParserLanguage.C ) - { - IASTProblem [] problems = CVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); - } - else if ( lang == ParserLanguage.CPP ) - { - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); + throw new ParserException("FAILURE"); + if (expectedToPass) { + if (lang == ParserLanguage.C) { + IASTProblem[] problems = CVisitor.getProblems(tu); + assertEquals(problems.length, 0); + } else if (lang == ParserLanguage.CPP) { + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertEquals(problems.length, 0); } } return tu; } - - public void testEmptyCompilationUnit() throws Exception - { - parse( "// no real code "); //$NON-NLS-1$ - } - - public void testSimpleNamespace() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { }"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - assertTrue( col.getName(0).resolveBinding() instanceof ICPPNamespace ); + + public void testEmptyCompilationUnit() throws Exception { + parse("// no real code "); } - public void testMultipleNamespaceDefinitions() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { } namespace A { }"); //$NON-NLS-1$ + public void testSimpleNamespace() throws Exception { + IASTTranslationUnit tu = parse("namespace A { }"); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 1); + assertTrue(col.getName(0).resolveBinding() instanceof ICPPNamespace); + } + + public void testMultipleNamespaceDefinitions() throws Exception { + IASTTranslationUnit tu = parse("namespace A { } namespace A { }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); - assertInstances( col, A, 2 ); + assertInstances(col, A, 2); } - public void testNestedNamespaceDefinitions() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { } }"); //$NON-NLS-1$ + public void testNestedNamespaceDefinitions() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); - - assertSame( A.getNamespaceScope(), B.getNamespaceScope().getParent() ); + + assertSame(A.getNamespaceScope(), B.getNamespaceScope().getParent()); } - - public void testEmptyClassDeclaration() throws Exception - { - IASTTranslationUnit tu = parse( "class A { };"); //$NON-NLS-1$ + + public void testEmptyClassDeclaration() throws Exception { + IASTTranslationUnit tu = parse("class A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType ); + tu.accept(col); + + assertEquals(col.size(), 1); + assertTrue(col.getName(0).resolveBinding() instanceof ICPPClassType); } - - public void testSimpleSubclass() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; class B : public A { };"); //$NON-NLS-1$ + + public void testSimpleSubclass() throws Exception { + IASTTranslationUnit tu = parse("class A { }; class B : public A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - - assertEquals( B.getBases().length, 1 ); + + assertInstances(col, A, 2); + + assertEquals(B.getBases().length, 1); ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); - assertEquals( base.getVisibility(), ICPPBase.v_public ); - assertFalse( base.isVirtual() ); + assertSame(base.getBaseClass(), A); + assertEquals(base.getVisibility(), ICPPBase.v_public); + assertFalse(base.isVirtual()); } - - public void testNestedSubclass() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { class A { }; } class B : protected virtual N::A { };"); //$NON-NLS-1$ + + public void testNestedSubclass() throws Exception { + IASTTranslationUnit tu = parse("namespace N { class A { }; } class B : protected virtual N::A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 3 ); - assertInstances( col, B, 1 ); - - assertSame( A.getScope(), N.getNamespaceScope() ); - + + assertInstances(col, N, 2); + assertInstances(col, A, 3); + assertInstances(col, B, 1); + + assertSame(A.getScope(), N.getNamespaceScope()); + ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); - assertTrue( base.isVirtual() ); - assertEquals( base.getVisibility(), ICPPBase.v_protected ); + assertSame(base.getBaseClass(), A); + assertTrue(base.isVirtual()); + assertEquals(base.getVisibility(), ICPPBase.v_protected); } - - public void testSimpleVariable() throws Exception - { - IASTTranslationUnit tu = parse( "int x;"); //$NON-NLS-1$ + + public void testSimpleVariable() throws Exception { + IASTTranslationUnit tu = parse("int x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); + tu.accept(col); + + assertEquals(col.size(), 1); IVariable x = (IVariable) col.getName(0).resolveBinding(); - - assertTrue( x.getType() instanceof IBasicType ); + + assertTrue(x.getType() instanceof IBasicType); IBasicType t = (IBasicType) x.getType(); - assertEquals( t.getType(), IBasicType.t_int ); + assertEquals(t.getType(), IBasicType.t_int); } - - public void testSimpleClassReferenceVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A x;"); //$NON-NLS-1$ + + public void testSimpleClassReferenceVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertSame( x.getType(), A ); + + assertInstances(col, A, 2); + assertSame(x.getType(), A); } - - public void testNestedClassReferenceVariable() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { class A { }; } N::A x;"); //$NON-NLS-1$ + + public void testNestedClassReferenceVariable() throws Exception { + IASTTranslationUnit tu = parse("namespace N { class A { }; } N::A x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 3 ); - assertSame( x.getType(), A ); - assertSame( A.getScope(), N.getNamespaceScope() ); + + assertInstances(col, N, 2); + assertInstances(col, A, 3); + assertSame(x.getType(), A); + assertSame(A.getScope(), N.getNamespaceScope()); } - - public void testMultipleDeclaratorsVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A x, y, z;"); //$NON-NLS-1$ + + public void testMultipleDeclaratorsVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A x, y, z;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); IVariable y = (IVariable) col.getName(3).resolveBinding(); IVariable z = (IVariable) col.getName(4).resolveBinding(); - - assertInstances( col, A, 2 ); - assertSame( A, x.getType() ); - assertSame( x.getType(), y.getType() ); - assertSame( y.getType(), z.getType() ); + + assertInstances(col, A, 2); + assertSame(A, x.getType()); + assertSame(x.getType(), y.getType()); + assertSame(y.getType(), z.getType()); } - - public void testSimpleField() throws Exception - { - IASTTranslationUnit tu = parse( "class A { double x; };"); //$NON-NLS-1$ + + public void testSimpleField() throws Exception { + IASTTranslationUnit tu = parse("class A { double x; };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField x = (ICPPField) col.getName(1).resolveBinding(); - - assertSame( x.getScope(), A.getCompositeScope() ); - IField [] fields = A.getFields(); - assertEquals( fields.length, 1 ); - assertSame( fields[0], x ); + + assertSame(x.getScope(), A.getCompositeScope()); + IField[] fields = A.getFields(); + assertEquals(fields.length, 1); + assertSame(fields[0], x); } - - public void testUsingClauses() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n " + //$NON-NLS-1$ - "using namespace A::B;\n " + //$NON-NLS-1$ - "using A::B::x;" + //$NON-NLS-1$ - "using A::B::C;" + //$NON-NLS-1$ - "using A::B::C::y;"); //$NON-NLS-1$ + + public void testUsingClauses() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { int x; class C { static int y = 5; }; } } \n " + + "using namespace A::B;\n " + + "using A::B::x;" + + "using A::B::C;" + + "using A::B::C::y;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 21 ); + tu.accept(col); + + assertEquals(col.size(), 21); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(3).resolveBinding(); ICPPField y = (ICPPField) col.getName(4).resolveBinding(); - + ICPPUsingDeclaration using_x = (ICPPUsingDeclaration) col.getName(11).resolveBinding(); ICPPUsingDeclaration using_C = (ICPPUsingDeclaration) col.getName(15).resolveBinding(); ICPPUsingDeclaration using_y = (ICPPUsingDeclaration) col.getName(20).resolveBinding(); - - assertInstances( col, A, 5 ); - assertInstances( col, B, 6 ); - assertInstances( col, x, 1 ); - assertInstances( col, C, 2 ); - assertInstances( col, y, 1 ); - - IBinding [] ds = using_x.getDelegates(); - assertSame( ds[0], x ); - assertSame( using_C.getDelegates()[0], C ); - assertSame( using_y.getDelegates()[0], y ); + + assertInstances(col, A, 5); + assertInstances(col, B, 6); + assertInstances(col, x, 1); + assertInstances(col, C, 2); + assertInstances(col, y, 1); + + IBinding[] ds = using_x.getDelegates(); + assertSame(ds[0], x); + assertSame(using_C.getDelegates()[0], C); + assertSame(using_y.getDelegates()[0], y); } - - public void testEnumerations() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}"); //$NON-NLS-1$ + + public void testEnumerations() throws Exception { + IASTTranslationUnit tu = parse("namespace A { enum E { e1, e2, e3 }; E varE;}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); IEnumeration E = (IEnumeration) col.getName(1).resolveBinding(); IEnumerator e1 = (IEnumerator) col.getName(2).resolveBinding(); IEnumerator e2 = (IEnumerator) col.getName(3).resolveBinding(); IEnumerator e3 = (IEnumerator) col.getName(4).resolveBinding(); IVariable varE = (IVariable) col.getName(6).resolveBinding(); - - assertInstances( col, E, 2 ); - assertSame( E.getScope(), A.getNamespaceScope() ); - assertSame( e1.getScope(), A.getNamespaceScope() ); - assertNotNull( e2 ); - assertNotNull( e3 ); - assertNotNull( varE ); + + assertInstances(col, E, 2); + assertSame(E.getScope(), A.getNamespaceScope()); + assertSame(e1.getScope(), A.getNamespaceScope()); + assertNotNull(e2); + assertNotNull(e3); + assertNotNull(varE); } - - public void testSimpleFunction() throws Exception - { - IASTTranslationUnit tu = parse( "void foo( void );"); //$NON-NLS-1$ + + public void testSimpleFunction() throws Exception { + IASTTranslationUnit tu = parse("void foo(void);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); IFunction foo = (IFunction) col.getName(0).resolveBinding(); IParameter p = (IParameter) col.getName(1).resolveBinding(); - - assertEquals( foo.getParameters().length, 1 ); - assertSame( foo.getParameters()[0], p ); - assertSame( p.getScope(), foo.getFunctionScope() ); + + assertEquals(foo.getParameters().length, 1); + assertSame(foo.getParameters()[0], p); + assertSame(p.getScope(), foo.getFunctionScope()); } - - public void testSimpleFunctionWithTypes() throws Exception - { - IASTTranslationUnit tu = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );"); //$NON-NLS-1$ + + public void testSimpleFunctionWithTypes() throws Exception { + IASTTranslationUnit tu = parse("class A { public: \n class B { }; }; const A::B & foo(A * myParam);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); IFunction foo = (IFunction) col.getName(5).resolveBinding(); IParameter p = (IParameter) col.getName(7).resolveBinding(); - - assertInstances( col, A, 3 ); - assertInstances( col, B, 3 ); - + + assertInstances(col, A, 3); + assertInstances(col, B, 3); + IFunctionType ftype = foo.getType(); - assertTrue( ftype.getReturnType() instanceof ICPPReferenceType ); + assertTrue(ftype.getReturnType() instanceof ICPPReferenceType); ICPPReferenceType rt = (ICPPReferenceType) ftype.getReturnType(); - assertTrue( rt.getType() instanceof IQualifierType ); - assertSame( ((IQualifierType)rt.getType()).getType(), B ); - + assertTrue(rt.getType() instanceof IQualifierType); + assertSame(((IQualifierType)rt.getType()).getType(), B); + IType pt = ftype.getParameterTypes()[0]; - assertTrue( p.getType().isSameType( pt ) ); - assertTrue( pt instanceof IPointerType ); - assertSame( ((IPointerType) pt).getType(), A ); + assertTrue(p.getType().isSameType(pt)); + assertTrue(pt instanceof IPointerType); + assertSame(((IPointerType) pt).getType(), A); } - - public void testSimpleMethod() throws Exception - { - IASTTranslationUnit tu = parse( "class A { void foo(); };"); //$NON-NLS-1$ + + public void testSimpleMethod() throws Exception { + IASTTranslationUnit tu = parse("class A { void foo(); };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); + tu.accept(col); + + assertEquals(col.size(), 2); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod foo = (ICPPMethod) col.getName(1).resolveBinding(); - - assertSame( foo.getScope(), A.getCompositeScope() ); + + assertSame(foo.getScope(), A.getCompositeScope()); } - - public void testSimpleMethodWithTypes() throws Exception - { - IASTTranslationUnit tu = parse( "class U { }; class A { U foo( U areDumb ); };"); //$NON-NLS-1$ + + public void testSimpleMethodWithTypes() throws Exception { + IASTTranslationUnit tu = parse("class U { }; class A { U foo(U areDumb); };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPClassType U = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPMethod foo = (ICPPMethod) col.getName(3).resolveBinding(); IParameter p = (IParameter) col.getName(5).resolveBinding(); - - assertInstances( col, U, 3 ); - assertSame( foo.getScope(), A.getCompositeScope() ); + + assertInstances(col, U, 3); + assertSame(foo.getScope(), A.getCompositeScope()); IFunctionType ft = foo.getType(); - assertSame( ft.getReturnType(), U ); - assertSame( p.getType(), U ); + assertSame(ft.getReturnType(), U); + assertSame(p.getType(), U); } - - public void testUsingDeclarationWithFunctionsAndMethods() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ); //$NON-NLS-1$ + + public void testUsingDeclarationWithFunctionsAndMethods() throws Exception { + IASTTranslationUnit tu = parse("namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction foo = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(3).resolveBinding(); ICPPMethod bar = (ICPPMethod) col.getName(4).resolveBinding(); - + ICPPUsingDeclaration using_foo = (ICPPUsingDeclaration) col.getName(8).resolveBinding(); ICPPUsingDeclaration using_bar = (ICPPUsingDeclaration) col.getName(11).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, foo, 1 ); - assertInstances( col, A, 2 ); - assertInstances( col, bar, 1 ); - - assertSame( using_foo.getDelegates()[0], foo ); - assertSame( using_bar.getDelegates()[0], bar ); - } - - public void testLinkageSpec() throws Exception - { - IASTTranslationUnit tu = parse( "extern \"C\" { int foo(); }"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 1 ); - IFunction foo = (IFunction) col.getName(0).resolveBinding(); - assertNotNull( foo ); - } - - public void testBogdansExample() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} "); //$NON-NLS-1$ + assertInstances(col, N, 2); + assertInstances(col, foo, 1); + assertInstances(col, A, 2); + assertInstances(col, bar, 1); + + assertSame(using_foo.getDelegates()[0], foo); + assertSame(using_bar.getDelegates()[0], bar); + } + + public void testLinkageSpec() throws Exception { + IASTTranslationUnit tu = parse("extern \"C\" { int foo(); }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 1); + IFunction foo = (IFunction) col.getName(0).resolveBinding(); + assertNotNull(foo); + } + + public void testBogdansExample() throws Exception { + IASTTranslationUnit tu = parse("namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} "); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding(); IEnumeration e1 = (IEnumeration) col.getName(2).resolveBinding(); @@ -568,550 +534,513 @@ public class CompleteParser2Tests extends BaseTestCase { IVariable x = (IVariable) col.getName(5).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(6).resolveBinding(); ICPPField y = (ICPPField) col.getName(7).resolveBinding(); - - assertSame( B.getScope(), A.getNamespaceScope() ); - assertSame( e1.getScope(), B.getNamespaceScope() ); - assertSame( e_1.getScope(), B.getNamespaceScope() ); - assertSame( e_2.getType(), e1 ); - assertNotNull( x ); - assertNotNull( C ); - assertNotNull( y ); + + assertSame(B.getScope(), A.getNamespaceScope()); + assertSame(e1.getScope(), B.getNamespaceScope()); + assertSame(e_1.getScope(), B.getNamespaceScope()); + assertSame(e_2.getType(), e1); + assertNotNull(x); + assertNotNull(C); + assertNotNull(y); } - - public void testAndrewsExample() throws Exception - { - IASTTranslationUnit tu = parse( "namespace N{ class A {}; } using namespace N; class B: public A{};"); //$NON-NLS-1$ + + public void testAndrewsExample() throws Exception { + IASTTranslationUnit tu = parse("namespace N{ class A {}; } using namespace N; class B: public A{};"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(3).resolveBinding(); - - assertInstances( col, N, 2 ); - assertInstances( col, A, 2 ); - + + assertInstances(col, N, 2); + assertInstances(col, A, 2); + ICPPBase base = B.getBases()[0]; - assertSame( base.getBaseClass(), A ); + assertSame(base.getBaseClass(), A); } - - public void testSimpleTypedef() throws Exception - { - IASTTranslationUnit tu = parse( "typedef int myInt;\n myInt var;"); //$NON-NLS-1$ + + public void testSimpleTypedef() throws Exception { + IASTTranslationUnit tu = parse("typedef int myInt;\n myInt var;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ITypedef myInt = (ITypedef) col.getName(0).resolveBinding(); IVariable var = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, myInt, 2 ); - assertTrue( myInt.getType() instanceof IBasicType ); - assertSame( var.getType(), myInt ); + + assertInstances(col, myInt, 2); + assertTrue(myInt.getType() instanceof IBasicType); + assertSame(var.getType(), myInt); } - - public void testComplexTypedef() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ }; typedef A ** A_DOUBLEPTR;"); //$NON-NLS-1$ + + public void testComplexTypedef() throws Exception { + IASTTranslationUnit tu = parse("class A{ }; typedef A ** A_DOUBLEPTR;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef APTR = (ITypedef) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertTrue( APTR.getType() instanceof IPointerType ); + + assertInstances(col, A, 2); + assertTrue(APTR.getType() instanceof IPointerType); IPointerType pt = (IPointerType) APTR.getType(); - assertTrue( pt.getType() instanceof IPointerType ); + assertTrue(pt.getType() instanceof IPointerType); pt = (IPointerType) pt.getType(); - assertSame( pt.getType(), A ); + assertSame(pt.getType(), A); } - - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) + + protected void assertQualifiedName(String[] fromAST, String[] theTruth) { - assertNotNull( fromAST ); - assertNotNull( theTruth ); - assertEquals( fromAST.length, theTruth.length ); - for( int i = 0; i < fromAST.length; ++i ) + assertNotNull(fromAST); + assertNotNull(theTruth); + assertEquals(fromAST.length, theTruth.length); + for (int i = 0; i < fromAST.length; ++i) { - assertEquals( fromAST[i], theTruth[i]); + assertEquals(fromAST[i], theTruth[i]); } } - public void testBug40842() throws Exception{ - Writer code = new StringWriter(); - code.write("class A {} a;\n"); //$NON-NLS-1$ + public void testBug40842() throws Exception { + Writer code = new StringWriter(); + code.write("class A {} a;\n"); IASTTranslationUnit tu = parse(code.toString()); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) decl.getDeclSpecifier(); ICPPClassType A = (ICPPClassType) comp.getName().resolveBinding(); IVariable a = (IVariable) decl.getDeclarators()[0].getName().resolveBinding(); - assertSame( a.getType(), A ); + assertSame(a.getType(), A); } - - public void testNestedClassname() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { \n class A::B { };}"); //$NON-NLS-1$ + + public void testNestedClassname() throws Exception { + IASTTranslationUnit tu = parse("namespace A { \n class A::B { };}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - + tu.accept(col); + ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); - assertInstances( col, A, 2 ); - assertEquals( B.getScope(), A.getNamespaceScope() ); + assertInstances(col, A, 2); + assertEquals(B.getScope(), A.getNamespaceScope()); } - - public void testForwardDeclaration() throws Exception - { - IASTTranslationUnit tu = parse( "class forward;"); //$NON-NLS-1$ + + public void testForwardDeclaration() throws Exception { + IASTTranslationUnit tu = parse("class forward;"); IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; - assertEquals( decl.getDeclarators().length, 0 ); - + assertEquals(decl.getDeclarators().length, 0); + IASTElaboratedTypeSpecifier spec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); ICPPClassType forward = (ICPPClassType) spec.getName().resolveBinding(); - assertNotNull( forward ); + assertNotNull(forward); } - - public void testElaboratedType() throws Exception - { - IASTTranslationUnit tu = parse( "class A; class A * a;"); //$NON-NLS-1$ + + public void testElaboratedType() throws Exception { + IASTTranslationUnit tu = parse("class A; class A * a;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable a = (IVariable) col.getName(2).resolveBinding(); IPointerType ptr = (IPointerType) a.getType(); - assertInstances( col, A, 2 ); - assertSame( ptr.getType(), A ); + assertInstances(col, A, 2); + assertSame(ptr.getType(), A); } - - public void testForewardDeclarationWithUsage() throws Exception - { - IASTTranslationUnit tu = parse( "class A; A * anA;class A { };"); //$NON-NLS-1$ + + public void testForewardDeclarationWithUsage() throws Exception { + IASTTranslationUnit tu = parse("class A; A * anA;class A { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, A, 3 ); + assertInstances(col, A, 3); IPointerType ptr = (IPointerType) anA.getType(); - assertSame( ptr.getType(), A ); - } - - - public void testASM() throws Exception - { - parse( "asm ( \"blah blah blah\" );" ); //$NON-NLS-1$ + assertSame(ptr.getType(), A); } - - /** + public void testASM() throws Exception { + parse("asm (\"blah blah blah\");"); + } + + /** * Tests GNU extensions to asm * e.g. asm volatile ("stuff"); - * asm ("addl %%ebx,%%eax" : "=a"(foo) : "a"(foo),"b"(bar) ); + * asm ("addl %%ebx,%%eax" : "=a"(foo) : "a"(foo),"b"(bar)); */ - public void testGNUASMExtension() throws Exception - { + public void testGNUASMExtension() throws Exception { // volatile keyword - parse( "asm volatile( \"blah blah blah\" );", true, ParserLanguage.C, true ); //$NON-NLS-1$ - parse( "asm volatile( \"blah blah blah\" );", true, ParserLanguage.CPP, true ); //$NON-NLS-1$ - + parse("asm volatile(\"blah blah blah\");", true, ParserLanguage.C, true); + parse("asm volatile(\"blah blah blah\");", true, ParserLanguage.CPP, true); + // Use of operands - parse( "asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar) );", true, ParserLanguage.C, true );//$NON-NLS-1$ - parse( "asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar) );", true, ParserLanguage.CPP, true );//$NON-NLS-1$ - + parse("asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar));", true, ParserLanguage.C, true);//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" : \"=a\"(foo) :\"a\"(foo), \"b\"(bar));", true, ParserLanguage.CPP, true);//$NON-NLS-1$ + // Invalid use of operands - parse( "asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar) );", false, ParserLanguage.C, true );//$NON-NLS-1$ - parse( "asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar) );", false, ParserLanguage.CPP, true );//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar));", false, ParserLanguage.C, true);//$NON-NLS-1$ + parse("asm (\"addl %%ebx,%%eax\" \"=a\"(foo) :\"a\"(foo) : \"b\"(bar));", false, ParserLanguage.CPP, true);//$NON-NLS-1$ // Code from bug 145389. - parse("#define mb() __asm__ __volatile__ (\"sync\" : : : \"memory\")\r\n" + - "\r\n" + - "int main(int argc, char **argv) {\r\n" + - " mb();\r\n" + + parse("#define mb() __asm__ __volatile__ (\"sync\" : : : \"memory\")\r\n" + + "\r\n" + + "int main(int argc, char **argv) {\r\n" + + " mb();\r\n" + "}"); // Code from bug 117001 - parse("static inline long\r\n" + - "div_ll_X_l_rem(long long divs, long div, long *rem)\r\n" + - "{\r\n" + - " long dum2;\r\n" + - " __asm__(\"divl %2\":\"=a\"(dum2), \"=d\"(*rem) // syntax error indicated at \":\"\r\n" + - " : \"rm\"(div), \"A\"(divs));\r\n" + - "\r\n" + - " return dum2;\r\n" + - "\r\n" + + parse("static inline long\r\n" + + "div_ll_X_l_rem(long long divs, long div, long *rem)\r\n" + + "{\r\n" + + " long dum2;\r\n" + + " __asm__(\"divl %2\":\"=a\"(dum2), \"=d\"(*rem) // syntax error indicated at \":\"\r\n" + + " : \"rm\"(div), \"A\"(divs));\r\n" + + "\r\n" + + " return dum2;\r\n" + + "\r\n" + "}"); } - public void testOverride() throws Exception - { - IASTTranslationUnit tu = parse( "void foo();\n void foo( int );\n"); //$NON-NLS-1$ + public void testOverride() throws Exception { + IASTTranslationUnit tu = parse("void foo();\n void foo(int);\n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo1 = (IFunction) col.getName(0).resolveBinding(); IFunction foo2 = (IFunction) col.getName(1).resolveBinding(); - - assertNotSame( foo1, foo2 ); - } - - public void testSimpleExpression() throws Exception - { - IASTTranslationUnit tu = parse( "int x; int y = x;"); //$NON-NLS-1$ + + assertNotSame(foo1, foo2); + } + + public void testSimpleExpression() throws Exception { + IASTTranslationUnit tu = parse("int x; int y = x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertNotNull( y ); + assertInstances(col, x, 2); + assertNotNull(y); } - - public void testParameterExpressions() throws Exception - { - IASTTranslationUnit tu = parse( "int x = 5; void foo( int sub = x ) { }"); //$NON-NLS-1$ + + public void testParameterExpressions() throws Exception { + IASTTranslationUnit tu = parse("int x = 5; void foo(int sub = x) { }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); IVariable x = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, x, 2 ); + assertInstances(col, x, 2); } - - public void testNestedNamespaceExpression() throws Exception - { - IASTTranslationUnit tu = parse( "namespace A { int x = 666; } int y = A::x;"); //$NON-NLS-1$ + + public void testNestedNamespaceExpression() throws Exception { + IASTTranslationUnit tu = parse("namespace A { int x = 666; } int y = A::x;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, A, 2 ); - assertInstances( col, x, 3 ); + assertInstances(col, A, 2); + assertInstances(col, x, 3); } - - public void testConstructorChain() throws Exception - { - IASTTranslationUnit tu = parse( "int x = 5;\n class A \n{ public : \n int a; \n A() : a( x ) { } };"); //$NON-NLS-1$ + + public void testConstructorChain() throws Exception { + IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable x = (IVariable) col.getName(0).resolveBinding(); ICPPField a = (ICPPField) col.getName(2).resolveBinding(); ICPPConstructor A = (ICPPConstructor) col.getName(3).resolveBinding(); - assertNotNull( A ); - assertInstances( col, x, 2 ); - assertInstances( col, a, 2 ); + assertNotNull(A); + assertInstances(col, x, 2); + assertInstances(col, a, 2); } - - public void testArrayModExpression() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 5; int y [ x ]; "); //$NON-NLS-1$ + + public void testArrayModExpression() throws Exception { + IASTTranslationUnit tu = parse("const int x = 5; int y[ x ]; "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertTrue( y.getType() instanceof IArrayType ); - assertTrue( ((IArrayType)y.getType()).getType() instanceof IBasicType ); + assertInstances(col, x, 2); + assertTrue(y.getType() instanceof IArrayType); + assertTrue(((IArrayType)y.getType()).getType() instanceof IBasicType); } - - public void testPointerVariable() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; A * anA;"); //$NON-NLS-1$ + public void testPointerVariable() throws Exception { + IASTTranslationUnit tu = parse("class A { }; A * anA;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, A, 2 ); - assertTrue( anA.getType() instanceof IPointerType ); - assertSame( ((IPointerType) anA.getType()).getType(), A ); - } - - public void testExceptionSpecification() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; void foo( void ) throw ( A );"); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); - assertInstances( col, A, 2 ); + assertInstances(col, A, 2); + assertTrue(anA.getType() instanceof IPointerType); + assertSame(((IPointerType) anA.getType()).getType(), A); } - - public void testNewExpressions() throws Exception { - IASTTranslationUnit tu = parse( "typedef int A; int B; int C; int D; int P; int*p = new (P) (A[B][C][D]);" ); //$NON-NLS-1$ + + public void testExceptionSpecification() throws Exception { + IASTTranslationUnit tu = parse("class A { }; void foo(void) throw (A);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 11 ); + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); + assertInstances(col, A, 2); + } + + public void testNewExpressions() throws Exception { + IASTTranslationUnit tu = parse("typedef int A; int B; int C; int D; int P; int*p = new (P) (A[B][C][D]);"); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 11); ITypedef A = (ITypedef) col.getName(0).resolveBinding(); IVariable B = (IVariable) col.getName(1).resolveBinding(); IVariable C = (IVariable) col.getName(2).resolveBinding(); IVariable D = (IVariable) col.getName(3).resolveBinding(); IVariable P = (IVariable) col.getName(4).resolveBinding(); IVariable p = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); - assertInstances( col, C, 2 ); - assertInstances( col, D, 2 ); - assertInstances( col, P, 2 ); - - assertTrue( p.getType() instanceof IPointerType ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); + assertInstances(col, C, 2); + assertInstances(col, D, 2); + assertInstances(col, P, 2); + + assertTrue(p.getType() instanceof IPointerType); } - public void testBug41520() throws Exception - { - IASTTranslationUnit tu = parse( "int f() { const int x = 666; const int y( x ); }"); //$NON-NLS-1$ + public void testBug41520() throws Exception { + IASTTranslationUnit tu = parse("int f() { const int x = 666; const int y(x); }"); IASTCompoundStatement s = (IASTCompoundStatement) ((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody(); IASTDeclarationStatement ds = (IASTDeclarationStatement) s.getStatements()[1]; - + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ds.getDeclaration(); IASTDeclarator dtor = decl.getDeclarators()[0]; - assertFalse( dtor instanceof IASTFunctionDeclarator ); - assertNotNull( dtor.getInitializer() ); - + assertFalse(dtor instanceof IASTFunctionDeclarator); + assertNotNull(dtor.getInitializer()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); IVariable x = (IVariable) col.getName(1).resolveBinding(); IVariable y = (IVariable) col.getName(2).resolveBinding(); assertNotNull(y); - assertInstances( col, x, 2 ); + assertInstances(col, x, 2); } - - public void testNewXReferences() throws Exception - { - IASTTranslationUnit tu = parse( "const int max = 5;\n int * x = new int[max];"); //$NON-NLS-1$ + + public void testNewXReferences() throws Exception { + IASTTranslationUnit tu = parse("const int max = 5;\n int * x = new int[max];"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IVariable max = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, max, 2 ); + assertInstances(col, max, 2); } - - public void testQualifiedNameReferences() throws Exception - { + + public void testQualifiedNameReferences() throws Exception { // Used to cause AST Semantic exception - IASTTranslationUnit tu = parse( "class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding(); ICPPClassType C = (ICPPClassType) col.getName(2).resolveBinding(); ICPPMethod cMethod = (ICPPMethod) col.getName(3).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); - assertInstances( col, C, 2 ); - assertInstances( col, cMethod, 3 ); - assertEquals( cMethod.getVisibility(), ICPPMember.v_public ); - assertSame( cMethod.getScope(), C.getCompositeScope() ); - assertSame( C.getScope(), B.getCompositeScope() ); - assertSame( B.getScope(), A.getCompositeScope() ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); + assertInstances(col, C, 2); + assertInstances(col, cMethod, 3); + assertEquals(cMethod.getVisibility(), ICPPMember.v_public); + assertSame(cMethod.getScope(), C.getCompositeScope()); + assertSame(C.getScope(), B.getCompositeScope()); + assertSame(B.getScope(), A.getCompositeScope()); } - public void testIsConstructor() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ public: A(); }; \n A::A() {}; \n" ); //$NON-NLS-1$ + public void testIsConstructor() throws Exception { + IASTTranslationUnit tu = parse("class A{ public: A(); }; \n A::A() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPConstructor ctor = (ICPPConstructor) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, ctor, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, ctor, 3); } - public void testIsDestructor() throws Exception - { - IASTTranslationUnit tu = parse( "class A{ public: ~A(); }; \n A::~A() {}; \n" ); //$NON-NLS-1$ + public void testIsDestructor() throws Exception { + IASTTranslationUnit tu = parse("class A{ public: ~A(); }; \n A::~A() {}; \n"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod dtor = (ICPPMethod) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, dtor, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, dtor, 3); } - - public void testBug41445() throws Exception - { - IASTTranslationUnit tu = parse( "class A { }; namespace N { class B : public A { struct A {}; }; }"); //$NON-NLS-1$ + + public void testBug41445() throws Exception { + IASTTranslationUnit tu = parse("class A { }; namespace N { class B : public A { struct A {}; }; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPNamespace N = (ICPPNamespace) col.getName(1).resolveBinding(); ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType A2 = (ICPPClassType) col.getName(4).resolveBinding(); - - assertInstances( col, A, 2 ); - assertNotSame( A, A2 ); - assertSame( A2.getScope(), B.getCompositeScope() ); - assertSame( B.getScope(), N.getNamespaceScope() ); - assertSame( B.getBases()[0].getBaseClass(), A ); - + + assertInstances(col, A, 2); + assertNotSame(A, A2); + assertSame(A2.getScope(), B.getCompositeScope()); + assertSame(B.getScope(), N.getNamespaceScope()); + assertSame(B.getBases()[0].getBaseClass(), A); + } - - public void testSimpleFunctionBody() throws Exception - { - IASTTranslationUnit tu = parse( "class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }"); //$NON-NLS-1$ + + public void testSimpleFunctionBody() throws Exception { + IASTTranslationUnit tu = parse("class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, f1, 3 ); - assertInstances( col, x, 3 ); + + assertInstances(col, A, 2); + assertInstances(col, f1, 3); + assertInstances(col, x, 3); } - - public void testSimpleForLoop() throws Exception - { - IASTTranslationUnit tu = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) { x += i; } }"); //$NON-NLS-1$ + public void testSimpleForLoop() throws Exception { + IASTTranslationUnit tu = parse("const int FIVE = 5; void f() { int x = 0; for (int i = 0; i < FIVE; ++i) { x += i; } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); IVariable FIVE = (IVariable) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); IVariable i = (IVariable) col.getName(3).resolveBinding(); - - assertInstances( col, FIVE, 2 ); - assertInstances( col, x, 2 ); - assertInstances( col, i, 4 ); + + assertInstances(col, FIVE, 2); + assertInstances(col, x, 2); + assertInstances(col, i, 4); } - public void testBug42541() throws Exception - { - IASTTranslationUnit tu = parse( "union{ int v; char a; } id;" ); //$NON-NLS-1$ + public void testBug42541() throws Exception { + IASTTranslationUnit tu = parse("union{ int v; char a; } id;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPClassType unnamed = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField v = (ICPPField) col.getName(1).resolveBinding(); ICPPField a = (ICPPField) col.getName(2).resolveBinding(); IVariable id = (IVariable) col.getName(3).resolveBinding(); - - assertEquals( unnamed.getKey(), ICompositeType.k_union ); - assertSame( v.getScope(), unnamed.getCompositeScope() ); - assertSame( a.getScope(), unnamed.getCompositeScope() ); - assertSame( id.getType(), unnamed ); + + assertEquals(unnamed.getKey(), ICompositeType.k_union); + assertSame(v.getScope(), unnamed.getCompositeScope()); + assertSame(a.getScope(), unnamed.getCompositeScope()); + assertSame(id.getType(), unnamed); } - - - - public void testSimpleIfStatement() throws Exception - { - IASTTranslationUnit tu =parse( "const bool T = true; int foo() { if( T ) { return 5; } else if( ! T ) return 20; else { return 10; } }"); //$NON-NLS-1$ - + + public void testSimpleIfStatement() throws Exception { + IASTTranslationUnit tu =parse("const bool T = true; int foo() { if (T) { return 5; } else if (! T) return 20; else { return 10; } }"); + IASTFunctionDefinition foo = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTCompoundStatement compound = (IASTCompoundStatement) foo.getBody(); IASTIfStatement ifstmt = (IASTIfStatement) compound.getStatements()[0]; - assertTrue( ifstmt.getConditionExpression() instanceof IASTIdExpression ); - assertTrue( ifstmt.getThenClause() instanceof IASTCompoundStatement ); - assertTrue( ifstmt.getElseClause() instanceof IASTIfStatement ); + assertTrue(ifstmt.getConditionExpression() instanceof IASTIdExpression); + assertTrue(ifstmt.getThenClause() instanceof IASTCompoundStatement); + assertTrue(ifstmt.getElseClause() instanceof IASTIfStatement); ifstmt = (IASTIfStatement) ifstmt.getElseClause(); - assertTrue( ifstmt.getConditionExpression() instanceof IASTUnaryExpression ); - assertTrue( ifstmt.getThenClause() instanceof IASTReturnStatement ); - assertTrue( ifstmt.getElseClause() instanceof IASTCompoundStatement ); - + assertTrue(ifstmt.getConditionExpression() instanceof IASTUnaryExpression); + assertTrue(ifstmt.getThenClause() instanceof IASTReturnStatement); + assertTrue(ifstmt.getElseClause() instanceof IASTCompoundStatement); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + IVariable T = (IVariable) col.getName(0).resolveBinding(); - assertInstances( col, T, 3 ); + assertInstances(col, T, 3); } - - public void testSimpleWhileStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }"); //$NON-NLS-1$ + + public void testSimpleWhileStatement() throws Exception { + IASTTranslationUnit tu = parse("const bool T = true; void foo() { int x = 0; while(T) { ++x; if (x == 100) break; } }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable T = (IVariable) col.getName(0).resolveBinding(); IVariable x = (IVariable) col.getName(2).resolveBinding(); - assertInstances( col, T, 2 ); - assertInstances( col, x, 3 ); + assertInstances(col, T, 2); + assertInstances(col, x, 3); } - - public void testSimpleSwitchStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 5; const int y = 10; " + //$NON-NLS-1$ - "void foo() { " + //$NON-NLS-1$ - " while( true ) { " + //$NON-NLS-1$ - " switch( x ) { " + //$NON-NLS-1$ - " case 1: break; " + //$NON-NLS-1$ - " case 2: goto blah; " + //$NON-NLS-1$ - " case y: continue; " + //$NON-NLS-1$ - " default: break; " + //$NON-NLS-1$ - " } " + //$NON-NLS-1$ - " } " + //$NON-NLS-1$ - " blah : ; " + //$NON-NLS-1$ - "} "); //$NON-NLS-1$ + + public void testSimpleSwitchStatement() throws Exception { + IASTTranslationUnit tu = parse("const int x = 5; const int y = 10; " + + "void foo() { " + + " while(true) { " + + " switch(x) { " + + " case 1: break; " + + " case 2: goto blah; " + + " case y: continue; " + + " default: break; " + + " } " + + " } " + + " blah : ; " + + "} "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable y = (IVariable) col.getName(1).resolveBinding(); ILabel blah = (ILabel) col.getName(4).resolveBinding(); - assertNotNull( blah ); - assertInstances( col, x, 2 ); - assertInstances( col, y, 2 ); - assertInstances( col, blah, 2 ); + assertNotNull(blah); + assertInstances(col, x, 2); + assertInstances(col, y, 2); + assertInstances(col, blah, 2); } - - public void testSimpleDoStatement() throws Exception - { - IASTTranslationUnit tu = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } "); //$NON-NLS-1$ + + public void testSimpleDoStatement() throws Exception { + IASTTranslationUnit tu = parse("const int x = 3; int counter = 0; void foo() { do { ++counter; } while(counter != x); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 6 ); + tu.accept(col); + + assertEquals(col.size(), 6); IVariable x = (IVariable) col.getName(0).resolveBinding(); IVariable counter = (IVariable) col.getName(1).resolveBinding(); - assertInstances( col, x, 2 ); - assertInstances( col, counter, 3 ); + assertInstances(col, x, 2); + assertInstances(col, counter, 3); } - + public void testThrowStatement() throws Exception { - IASTTranslationUnit tu = parse("class A { }; void foo() throw ( A ) { A a; throw a; throw; } "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A { }; void foo() throw (A) { A a; throw a; throw; } "); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1122,430 +1051,405 @@ public class CompleteParser2Tests extends BaseTestCase { IVariable a = (IVariable) col.getName(4).resolveBinding(); assertInstances(col, a, 2); } - - public void testScoping() throws Exception - { - IASTTranslationUnit tu = parse( "void foo() { int x = 3; if( x == 1 ) { int x = 4; } else int x = 2; }"); //$NON-NLS-1$ + + public void testScoping() throws Exception { + IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); IVariable x1 = (IVariable) col.getName(1).resolveBinding(); IVariable x2 = (IVariable) col.getName(3).resolveBinding(); IVariable x3 = (IVariable) col.getName(4).resolveBinding(); - - assertInstances( col, x1, 2 ); - assertInstances( col, x2, 1 ); - assertInstances( col, x3, 1 ); + + assertInstances(col, x1, 2); + assertInstances(col, x2, 1); + assertInstances(col, x3, 1); } - - public void testEnumeratorReferences() throws Exception - { - IASTTranslationUnit tu = parse( "enum E { e1, e2, e3 }; E anE = e1;"); //$NON-NLS-1$ + + public void testEnumeratorReferences() throws Exception { + IASTTranslationUnit tu = parse("enum E { e1, e2, e3 }; E anE = e1;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IEnumeration E = (IEnumeration) col.getName(0).resolveBinding(); IEnumerator e1 = (IEnumerator) col.getName(1).resolveBinding(); IEnumerator e2 = (IEnumerator) col.getName(2).resolveBinding(); IEnumerator e3 = (IEnumerator) col.getName(3).resolveBinding(); IVariable anE = (IVariable) col.getName(5).resolveBinding(); - - assertInstances( col, E, 2 ); - assertInstances( col, e1, 2 ); - assertInstances( col, e2, 1 ); - assertInstances( col, e3, 1 ); - assertInstances( col, anE, 1 ); + + assertInstances(col, E, 2); + assertInstances(col, e1, 2); + assertInstances(col, e2, 1); + assertInstances(col, e3, 1); + assertInstances(col, anE, 1); } - - public void testBug42840() throws Exception - { - IASTTranslationUnit tu = parse( "void foo(); void foo() { } class SearchMe { };"); //$NON-NLS-1$ + + public void testBug42840() throws Exception { + IASTTranslationUnit tu = parse("void foo(); void foo() { } class SearchMe { };"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo = (IFunction) col.getName(0).resolveBinding(); - - assertInstances( col, foo, 2 ); + + assertInstances(col, foo, 2); } - - public void testBug42872() throws Exception - { - IASTTranslationUnit tu = parse( "struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }" ); //$NON-NLS-1$ + + public void testBug42872() throws Exception { + IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICompositeType B = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType D = (ICompositeType) col.getName(1).resolveBinding(); - - assertInstances( col, B, 4 ); - assertInstances( col, D, 2 ); + + assertInstances(col, B, 4); + assertInstances(col, D, 2); } - + public void testBug43503A() throws Exception { - IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 8 ); + tu.accept(col); + + assertEquals(col.size(), 8); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - assertInstances( col, SD_01, 2 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, f_SD_01, 2 ); - } - - - public void testBug42979() throws Exception - { - Writer code = new StringWriter(); - code.write( "class OperatorOverload{\n" ); //$NON-NLS-1$ - code.write( "public:\n" ); //$NON-NLS-1$ - code.write( " bool operator==( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( " { return true; }\n" ); //$NON-NLS-1$ - code.write( " bool operator!=( const class OperatorOverload& that );\n" ); //$NON-NLS-1$ - code.write( "}; \n" ); //$NON-NLS-1$ - - code.write( "bool OperatorOverload::operator!=( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( "{ return false; }\n" ); //$NON-NLS-1$ + assertInstances(col, SD_01, 2); + assertInstances(col, ctor, 1); + assertInstances(col, f_SD_01, 2); + } - IASTTranslationUnit tu = parse( code.toString() ); + public void testBug42979() throws Exception { + Writer code = new StringWriter(); + code.write("class OperatorOverload{\n"); + code.write("public:\n"); + code.write(" bool operator==(const class OperatorOverload& that)\n"); + code.write(" { return true; }\n"); + code.write(" bool operator!=(const class OperatorOverload& that);\n"); + code.write("}; \n"); + + code.write("bool OperatorOverload::operator!=(const class OperatorOverload& that)\n"); + code.write("{ return false; }\n"); + + IASTTranslationUnit tu = parse(code.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICompositeType OperatorOverload = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod op1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod op2 = (ICPPMethod) col.getName(4).resolveBinding(); - - assertInstances( col, OperatorOverload, 5 ); - assertInstances( col, op1, 1 ); - assertInstances( col, op2, 3 ); + + assertInstances(col, OperatorOverload, 5); + assertInstances(col, op1, 1); + assertInstances(col, op2, 3); } - /** + /** * class A { static int x; } int A::x = 5; */ - public void testBug43373() throws Exception - { - IASTTranslationUnit tu = parse( "class A { static int x; }; int A::x = 5;" ); //$NON-NLS-1$ + public void testBug43373() throws Exception { + IASTTranslationUnit tu = parse("class A { static int x; }; int A::x = 5;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); ICPPField x = (ICPPField) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, x, 3 ); - } - - public void testBug39504() throws Exception - { - IASTTranslationUnit tu = parse( "const int w = 2; int x[ 5 ]; int y = sizeof ( x[w] );" ); //$NON-NLS-1$ - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); - IVariable w = (IVariable) col.getName(0).resolveBinding(); - IVariable x = (IVariable) col.getName(1).resolveBinding(); - - assertInstances( col, w, 2 ); - assertInstances( col, x, 2 ); - } - - public void testBug43375() throws Exception - { - parse( "extern int x;"); //$NON-NLS-1$ + + assertInstances(col, A, 2); + assertInstances(col, x, 3); } - public void testBug43503() throws Exception - { - StringBuffer buff = new StringBuffer(); - - buff.append( "class SD_02 { "); //$NON-NLS-1$ - buff.append( " public: "); //$NON-NLS-1$ - buff.append( " void f_SD_02(); "); //$NON-NLS-1$ - buff.append( " }; "); //$NON-NLS-1$ - buff.append( "class SD_01 { \n"); //$NON-NLS-1$ - buff.append( " public: \n"); //$NON-NLS-1$ - buff.append( " SD_02 *next; \n"); //$NON-NLS-1$ // REFERENCE SD_02 - buff.append( " void f_SD_01(); \n"); //$NON-NLS-1$ - buff.append( "}; \n"); //$NON-NLS-1$ - buff.append( "int main(){ \n"); //$NON-NLS-1$ - buff.append( " SD_01* a = new SD_01(); \n"); //$NON-NLS-1$ // REFERENCE SD_01 * 2 - buff.append( " a->f_SD_01(); \n"); //$NON-NLS-1$ // REFERENCE a && REFERENCE f_SD_01 - buff.append( "} \n"); //$NON-NLS-1$ - buff.append( "void SD_01::f_SD_01() \n"); //$NON-NLS-1$ // REFERENCE SD_01 - buff.append( "{ \n"); //$NON-NLS-1$ - buff.append( " next->f_SD_02(); \n"); //$NON-NLS-1$ // REFERENCE next && reference f_SD_02 - buff.append( "} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buff.toString() ); - + public void testBug39504() throws Exception { + IASTTranslationUnit tu = parse("const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 17 ); + tu.accept(col); + + assertEquals(col.size(), 5); + IVariable w = (IVariable) col.getName(0).resolveBinding(); + IVariable x = (IVariable) col.getName(1).resolveBinding(); + + assertInstances(col, w, 2); + assertInstances(col, x, 2); + } + + public void testBug43375() throws Exception { + parse("extern int x;"); + } + + public void testBug43503() throws Exception { + StringBuffer buff = new StringBuffer(); + + buff.append("class SD_02 { "); + buff.append(" public: "); + buff.append(" void f_SD_02(); "); + buff.append(" }; "); + buff.append("class SD_01 { \n"); + buff.append(" public: \n"); + buff.append(" SD_02 *next; \n"); // REFERENCE SD_02 + buff.append(" void f_SD_01(); \n"); + buff.append("}; \n"); + buff.append("int main(){ \n"); + buff.append(" SD_01* a = new SD_01(); \n"); // REFERENCE SD_01 * 2 + buff.append(" a->f_SD_01(); \n"); // REFERENCE a && REFERENCE f_SD_01 + buff.append("} \n"); + buff.append("void SD_01::f_SD_01() \n"); // REFERENCE SD_01 + buff.append("{ \n"); + buff.append(" next->f_SD_02(); \n"); // REFERENCE next && reference f_SD_02 + buff.append("} \n"); + IASTTranslationUnit tu = parse(buff.toString()); + + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 17); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPField next = (ICPPField) col.getName(4).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(5).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - - assertInstances( col, SD_02, 2 ); - assertInstances( col, f_SD_02, 2 ); - assertInstances( col, SD_01, 3 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, next, 2 ); - assertInstances( col, f_SD_01, 4 ); + + assertInstances(col, SD_02, 2); + assertInstances(col, f_SD_02, 2); + assertInstances(col, SD_01, 3); + assertInstances(col, ctor, 1); + assertInstances(col, next, 2); + assertInstances(col, f_SD_01, 4); } - - public void testBug43679_A () throws Exception - { - IASTTranslationUnit tu = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } " ); //$NON-NLS-1$ + + public void testBug43679_A () throws Exception { + IASTTranslationUnit tu = parse("struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod size = (ICPPMethod) col.getName(1).resolveBinding(); IFunction getSample = (IFunction) col.getName(3).resolveBinding(); - assertInstances( col, sample, 2 ); - assertInstances( col, size, 2 ); - assertInstances( col, getSample, 2 ); + assertInstances(col, sample, 2); + assertInstances(col, size, 2); + assertInstances(col, getSample, 2); } - public void testBug43679_B () throws Exception - { - IASTTranslationUnit tu = parse( "struct Sample{int size() const; }; struct Sample; " ); //$NON-NLS-1$ + public void testBug43679_B () throws Exception { + IASTTranslationUnit tu = parse("struct Sample{int size() const; }; struct Sample; "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); ICompositeType sample = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod size = (ICPPMethod) col.getName(1).resolveBinding(); - - assertInstances( col, sample, 2 ); - assertInstances( col, size, 1 ); + + assertInstances(col, sample, 2); + assertInstances(col, size, 1); } - - public void testBug43951() throws Exception - { - IASTTranslationUnit tu = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}" ); //$NON-NLS-1$ + + public void testBug43951() throws Exception { + IASTTranslationUnit tu = parse("class B{ B(); ~B(); }; B::B(){} B::~B(){}"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICPPClassType B = (ICPPClassType) col.getName(0).resolveBinding(); ICPPConstructor constructor = (ICPPConstructor) col.getName(1).resolveBinding(); ICPPMethod destructor = (ICPPMethod) col.getName(2).resolveBinding(); - - assertInstances( col, B, 3 ); - assertInstances( col, constructor, 3 ); - assertInstances( col, destructor, 3 ); - } + + assertInstances(col, B, 3); + assertInstances(col, constructor, 3); + assertInstances(col, destructor, 3); + } public void testBug44342() throws Exception { - IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; - IVariable a = (IVariable) col.getName( 6 ).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, f1, 2 ); - assertInstances( col, f2, 1 ); - assertInstances( col, ctor, 1 ); - assertInstances( col, a, 2 ); - } + IVariable a = (IVariable) col.getName(6).resolveBinding(); - - public void testCDesignatedInitializers() throws Exception - { + assertInstances(col, A, 2); + assertInstances(col, f1, 2); + assertInstances(col, f2, 1); + assertInstances(col, ctor, 1); + assertInstances(col, a, 2); + } + + public void testCDesignatedInitializers() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "struct Inner { int a,b,c; };"); //$NON-NLS-1$ - buffer.append( "struct A { int x; int y[]; struct Inner innerArray[]; int z []; };"); //$NON-NLS-1$ - buffer.append( "struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); //$NON-NLS-1$ - parse( buffer.toString(), true, ParserLanguage.C ); - } - - public void testBug39551A() throws Exception - { - parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C); //$NON-NLS-1$ + buffer.append("struct Inner { int a,b,c; };"); + buffer.append("struct A { int x; int y[]; struct Inner innerArray[]; int z[]; };"); + buffer.append("struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); + parse(buffer.toString(), true, ParserLanguage.C); } - public void testBug39551B() throws Exception - { + public void testBug39551A() throws Exception { + parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C); + } + + public void testBug39551B() throws Exception { //this used to be 99.99 * __I__, but I don't know where the __I__ came from, its not in C99, nor in GCC - parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C); //$NON-NLS-1$ + parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C); } - - public void testCBool() throws Exception - { - parse( "_Bool x;", true, ParserLanguage.C ); //$NON-NLS-1$ + + public void testCBool() throws Exception { + parse("_Bool x;", true, ParserLanguage.C); } - - public void testCBoolAsParameter() throws Exception - { - parse( "void f( _Bool b ) {} " + //$NON-NLS-1$ - "_Bool g( _Bool b ) {} " + //$NON-NLS-1$ - "void main(){" + //$NON-NLS-1$ - " _Bool b; " + //$NON-NLS-1$ - " f(b);" + //$NON-NLS-1$ - " f( g( (_Bool) 1 ) );" + //$NON-NLS-1$ - "}", //$NON-NLS-1$ - true, ParserLanguage.C ); + + public void testCBoolAsParameter() throws Exception { + parse("void f(_Bool b) {} " + + "_Bool g(_Bool b) {} " + + "void main(){" + + " _Bool b; " + + " f(b);" + + " f(g((_Bool) 1) );" + + "}", + true, ParserLanguage.C); } - - public void testBug44510() throws Exception - { - IASTTranslationUnit tu = parse( "int initialize(); " + //$NON-NLS-1$ - "int initialize( char ){} " + //$NON-NLS-1$ - "int initialize(){ return 1; } " + //$NON-NLS-1$ - "void main(){ int i = initialize(); }" ); //$NON-NLS-1$ - + + public void testBug44510() throws Exception { + IASTTranslationUnit tu = parse("int initialize(); " + + "int initialize(char){} " + + "int initialize(){ return 1; } " + + "void main(){ int i = initialize(); }"); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); IFunction init1 = (IFunction) col.getName(0).resolveBinding(); IFunction init2 = (IFunction) col.getName(1).resolveBinding(); - - assertInstances( col, init1, 3 ); - assertInstances( col, init2, 1 ); - } - - public void testBug44925() throws Exception - { + + assertInstances(col, init1, 3); + assertInstances(col, init2, 1); + } + + public void testBug44925() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "class MyClass { };"); //$NON-NLS-1$ - buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$ - buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$ - buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("class MyClass { };"); + buffer.append("class MyClass myObj1;"); + buffer.append("enum MyEnum { Item1 };"); + buffer.append("enum MyEnum myObj2;"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPClassType myClass = (ICPPClassType) col.getName(0).resolveBinding(); IVariable obj1 = (IVariable) col.getName(2).resolveBinding(); IEnumeration myEnum = (IEnumeration) col.getName(3).resolveBinding(); IEnumerator item = (IEnumerator) col.getName(4).resolveBinding(); IVariable obj2 = (IVariable)col.getName(6).resolveBinding(); - - assertInstances( col, myClass, 2 ); - assertInstances( col, myEnum, 2 ); - assertSame( obj1.getType(), myClass ); - assertSame( obj2.getType(), myEnum ); - assertSame( item.getType(), myEnum ); + + assertInstances(col, myClass, 2); + assertInstances(col, myEnum, 2); + assertSame(obj1.getType(), myClass); + assertSame(obj2.getType(), myEnum); + assertSame(item.getType(), myEnum); } - - public void testBug44838() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + + public void testBug44838() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("class A { int myX; A(int x); };\n"); + buffer.append("A::A(int x) : myX(x) { if (x == 5) myX++; }\n"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 12 ); + tu.accept(col); + + assertEquals(col.size(), 12); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPField myX = (ICPPField) col.getName(1).resolveBinding(); ICPPConstructor ctor = (ICPPConstructor) col.getName(2).resolveBinding(); IParameter x = (IParameter) col.getName(3).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, myX, 3 ); - assertInstances( col, ctor, 3 ); - assertInstances( col, x, 4 ); - } - - public void testBug46165() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - parse( buffer.toString() ); + + assertInstances(col, A, 2); + assertInstances(col, myX, 3); + assertInstances(col, ctor, 3); + assertInstances(col, x, 4); } - public void testBug47624() throws Exception - { + public void testBug46165() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "struct s { }; \n" ); //$NON-NLS-1$ - buffer.append( "void f ( int s ) { \n" ); //$NON-NLS-1$ - buffer.append( " struct s sInstance; \n" ); //$NON-NLS-1$ - buffer.append( "}\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("class A { int myX; A(int x); };\n"); + buffer.append("A::A(int x) : myX(x) { if (x == 5) myX++; }\n"); + parse(buffer.toString()); + } + + public void testBug47624() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("struct s { }; \n"); + buffer.append("void f (int s) { \n"); + buffer.append(" struct s sInstance; \n"); + buffer.append("}\n"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding(); IParameter s2 = (IParameter) col.getName(2).resolveBinding(); IVariable instance = (IVariable) col.getName(4).resolveBinding(); - assertInstances( col, s, 2 ); - assertInstances( col, s2, 1 ); - assertSame( instance.getType(), s ); + assertInstances(col, s, 2); + assertInstances(col, s2, 1); + assertSame(instance.getType(), s); } - - public void testQualifiedLookup() throws Exception{ + + public void testQualifiedLookup() throws Exception { //this is meant to test that on a->f, the lookup for f is qualified //the namespace is necessary because of bug 47926 StringBuffer buffer = new StringBuffer(); - buffer.append( "namespace N {" ); //$NON-NLS-1$ - buffer.append( " void f () {} \n" ); //$NON-NLS-1$ - buffer.append( " class A { }; \n" ); //$NON-NLS-1$ - buffer.append( "}" ); //$NON-NLS-1$ - buffer.append( "void main() { N::A * a = new N::A(); a->f(); } "); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("namespace N {"); + buffer.append(" void f () {} \n"); + buffer.append(" class A { }; \n"); + buffer.append("}"); + buffer.append("void main() { N::A * a = new N::A(); a->f(); } "); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 13 ); + tu.accept(col); + + assertEquals(col.size(), 13); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction f = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; - + IProblemBinding fp = (IProblemBinding) col.getName(12).resolveBinding(); - assertEquals( fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND ); - - assertInstances( col, N, 3 ); - assertInstances( col, f, 1 ); - assertInstances( col, A, 3 ); - assertInstances( col, ctor, 2 ); + assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); + + assertInstances(col, N, 3); + assertInstances(col, f, 1); + assertInstances(col, A, 3); + assertInstances(col, ctor, 2); } - - public void testBug43110() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append("void x( int y, ... );\n"); //$NON-NLS-1$ - buffer.append("void y( int x... );\n"); //$NON-NLS-1$ - buffer.append("void z(...);"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( buffer.toString() ); - + + public void testBug43110() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("void x(int y, ...);\n"); + buffer.append("void y(int x...);\n"); + buffer.append("void z(...);"); + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 5 ); + tu.accept(col); + + assertEquals(col.size(), 5); IFunction x = (IFunction) col.getName(0).resolveBinding(); IFunction y = (IFunction) col.getName(2).resolveBinding(); IFunction z = (IFunction) col.getName(4).resolveBinding(); @@ -1553,1088 +1457,1023 @@ public class CompleteParser2Tests extends BaseTestCase { assertNotNull(y); assertNotNull(z); } - - public void testBug43110_XRef() throws Exception - { + + public void testBug43110_XRef() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( buffer.toString() ); - + buffer.append("void foo(...) {}\n"); + buffer.append("void main(){ foo(1); }\n"); + + IASTTranslationUnit tu = parse(buffer.toString()); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); + tu.accept(col); + + assertEquals(col.size(), 3); IFunction foo = (IFunction) col.getName(0).resolveBinding(); - assertInstances( col, foo, 2 ); + assertInstances(col, foo, 2); } - + public void testErrorHandling_1() throws Exception { - IASTTranslationUnit tu = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ); //$NON-NLS-1$ - + IASTTranslationUnit tu = parse("A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); IProblemBinding p = (IProblemBinding) col.getName(0).resolveBinding(); IVariable anA = (IVariable) col.getName(1).resolveBinding(); - assertNotNull( col.getName(2).resolveBinding() ); + assertNotNull(col.getName(2).resolveBinding()); IProblemBinding p2 = (IProblemBinding) col.getName(3).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(4).resolveBinding(); - - assertInstances( col, anA, 2 ); - assertInstances( col, A, 2 ); - - assertNotNull( p ); - assertNotNull( p2 ); - + + assertInstances(col, anA, 2); + assertInstances(col, A, 2); + + assertNotNull(p); + assertNotNull(p2); + IProblemType pt= (IProblemType) anA.getType(); assertEquals(ISemanticProblem.TYPE_UNRESOLVED_NAME, pt.getID()); } - + public void testBug44340() throws Exception { - // inline function with reference to variables declared after them - IASTTranslationUnit tu = parse ("class A{ int getX() {return x[1];} int x[10];};"); //$NON-NLS-1$ - + // Inline function with reference to variables declared after them + IASTTranslationUnit tu = parse ("class A{ int getX() {return x[1];} int x[10];};"); + CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + ICPPField x = (ICPPField) col.getName(2).resolveBinding(); - assertInstances( col, x, 2 ); - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug47636() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void f( char [] ); \n" ); //$NON-NLS-1$ - writer.write( "void f( char * ){} \n" ); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - IFunction f1 = (IFunction) col.getName(0).resolveBinding(); - IParameter p1 = (IParameter)col.getName(1).resolveBinding(); - IFunction f2 = (IFunction) col.getName(2).resolveBinding(); - IParameter p2 = (IParameter)col.getName(3).resolveBinding(); - assertSame( f1, f2 ); - assertSame( p1, p2 ); - } - - public void testBug45697() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " int f( bool ); \n"); //$NON-NLS-1$ - writer.write( " int f( char ){ } "); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); - IFunction f1 = (IFunction) col.getName(0).resolveBinding(); - IParameter p1 = (IParameter)col.getName(1).resolveBinding(); - IFunction f2 = (IFunction) col.getName(2).resolveBinding(); - IParameter p2 = (IParameter)col.getName(3).resolveBinding(); - - assertNotSame( f1, f2 ); - assertNotSame( p1, p2 ); + assertInstances(col, x, 2); } - public void testBug54639() throws Exception - { + public void testBug47628() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef enum _A { } A, *pA; " ); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("void h(char) { }\n"); + writer.write("void h(unsigned char) { }\n"); + writer.write("void h(signed char) { } // not shown in outline, parsed as char\n"); + + parse(writer.toString()); + } + + public void testBug47636() throws Exception { + Writer writer = new StringWriter(); + writer.write("void f(char[]); \n"); + writer.write("void f(char *){} \n"); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 3 ); - + tu.accept(col); + + assertEquals(col.size(), 4); + IFunction f1 = (IFunction) col.getName(0).resolveBinding(); + IParameter p1 = (IParameter)col.getName(1).resolveBinding(); + IFunction f2 = (IFunction) col.getName(2).resolveBinding(); + IParameter p2 = (IParameter)col.getName(3).resolveBinding(); + assertSame(f1, f2); + assertSame(p1, p2); + } + + public void testBug45697() throws Exception { + Writer writer = new StringWriter(); + writer.write(" int f(bool); \n"); + writer.write(" int f(char){ } "); + + IASTTranslationUnit tu = parse(writer.toString()); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 4); + IFunction f1 = (IFunction) col.getName(0).resolveBinding(); + IParameter p1 = (IParameter)col.getName(1).resolveBinding(); + IFunction f2 = (IFunction) col.getName(2).resolveBinding(); + IParameter p2 = (IParameter)col.getName(3).resolveBinding(); + + assertNotSame(f1, f2); + assertNotSame(p1, p2); + } + + public void testBug54639() throws Exception { + Writer writer = new StringWriter(); + writer.write("typedef enum _A { } A, *pA; "); + + IASTTranslationUnit tu = parse(writer.toString()); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 3); + IEnumeration _A = (IEnumeration) col.getName(0).resolveBinding(); ITypedef A = (ITypedef) col.getName(1).resolveBinding(); ITypedef pA = (ITypedef)col.getName(2).resolveBinding(); - - assertNotNull( _A ); - assertSame( A.getType(), _A ); - assertTrue( pA.getType() instanceof IPointerType ); - assertSame( ((IPointerType)pA.getType()).getType(), _A ); + + assertNotNull(_A); + assertSame(A.getType(), _A); + assertTrue(pA.getType() instanceof IPointerType); + assertSame(((IPointerType)pA.getType()).getType(), _A); } - - public void testBug55163() throws Exception - { + + public void testBug55163() throws Exception { Writer writer = new StringWriter(); - writer.write( "void foo() { \n"); //$NON-NLS-1$ - writer.write( " int i, n; \n"); //$NON-NLS-1$ - writer.write( " double di; \n"); //$NON-NLS-1$ - writer.write( " for( i = n - 1, di = (double)( i + i ); i > 0; i-- ){ } \n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("void foo() { \n"); + writer.write(" int i, n; \n"); + writer.write(" double di; \n"); + writer.write(" for (i = n - 1, di = (double)(i + i); i > 0; i--){ } \n"); + writer.write("}\n"); + + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 11 ); + tu.accept(col); + + assertEquals(col.size(), 11); IVariable i = (IVariable)col.getName(1).resolveBinding(); IVariable n = (IVariable)col.getName(2).resolveBinding(); IVariable di = (IVariable)col.getName(3).resolveBinding(); - - assertInstances( col, i, 6 ); - assertInstances( col, n, 2 ); - assertInstances( col, di, 2 ); + + assertInstances(col, i, 6); + assertInstances(col, n, 2); + assertInstances(col, di, 2); } - public void testBug55673() throws Exception{ + public void testBug55673() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct Example { int i; int ( * pfi ) ( int ); }; "); //$NON-NLS-1$ - - parse( writer.toString() ); - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("struct Example { int i; int (* pfi) (int); }; "); + + parse(writer.toString()); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 4 ); + tu.accept(col); + + assertEquals(col.size(), 4); ICPPField pfi = (ICPPField)col.getName(2).resolveBinding(); - - assertNotNull( pfi ); - assertTrue( pfi.getType() instanceof IPointerType ); - assertTrue( ((IPointerType)pfi.getType()).getType() instanceof IFunctionType ); + + assertNotNull(pfi); + assertTrue(pfi.getType() instanceof IPointerType); + assertTrue(((IPointerType)pfi.getType()).getType() instanceof IFunctionType); } - - public void testBug54531() throws Exception - { - parse( "typedef enum _A {} A, *pA;" ); //$NON-NLS-1$ + + public void testBug54531() throws Exception { + parse("typedef enum _A {} A, *pA;"); } - - public void testBug56516() throws Exception - { - IASTTranslationUnit tu = parse( "typedef struct blah sb;"); //$NON-NLS-1$ + + public void testBug56516() throws Exception { + IASTTranslationUnit tu = parse("typedef struct blah sb;"); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 2 ); - + tu.accept(col); + + assertEquals(col.size(), 2); + ICPPClassType blah = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef sb = (ITypedef) col.getName(1).resolveBinding(); - assertSame( sb.getType(), blah ); - } - - public void testBug53786() throws Exception - { - parse( "struct Example { struct Data * data; };"); //$NON-NLS-1$ - } - - public void testBug54029() throws Exception - { - parse( "typedef int T; T i;" ); //$NON-NLS-1$ + assertSame(sb.getType(), blah); } - public void testBug47625() throws Exception - { + public void testBug53786() throws Exception { + parse("struct Example { struct Data * data; };"); + } + + public void testBug54029() throws Exception { + parse("typedef int T; T i;"); + } + + public void testBug47625() throws Exception { Writer writer = new StringWriter(); - writer.write("struct s { int num; }; "); //$NON-NLS-1$ - writer.write("namespace ns{ "); //$NON-NLS-1$ - writer.write(" struct s { double num; };"); //$NON-NLS-1$ - writer.write(" s inner = { 3.14 };"); //$NON-NLS-1$ - writer.write(" ::s outer = { 42 };"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString() ); - - CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + writer.write("struct s { int num; }; "); + writer.write("namespace ns{ "); + writer.write(" struct s { double num; };"); + writer.write(" s inner = { 3.14 };"); + writer.write(" ::s outer = { 42 };"); + writer.write("}"); + + IASTTranslationUnit tu = parse(writer.toString()); + + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + assertEquals(col.size(), 10); - assertEquals( col.size(), 10 ); - ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType s2 = (ICPPClassType) col.getName(3).resolveBinding(); - + ICPPClassType ref1 = (ICPPClassType) col.getName(5).resolveBinding(); - ICPPClassType ref2 = (ICPPClassType) col.getName( 8 ).resolveBinding(); - - assertSame( s, ref2 ); - assertSame( s2, ref1 ); + ICPPClassType ref2 = (ICPPClassType) col.getName(8).resolveBinding(); + + assertSame(s, ref2); + assertSame(s2, ref1); } - - public void testBug57754() throws Exception - { + + public void testBug57754() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct X { " ); //$NON-NLS-1$ - writer.write( " typedef int T; " ); //$NON-NLS-1$ - writer.write( " void f( T ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void X::f( T ) { } " ); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("struct X { "); + writer.write(" typedef int T; "); + writer.write(" void f(T); "); + writer.write("}; "); + writer.write("void X::f(T) { } "); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 10 ); + tu.accept(col); + + assertEquals(col.size(), 10); ICPPClassType X = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef T = (ITypedef) col.getName(1).resolveBinding(); ICPPMethod f = (ICPPMethod) col.getName(2).resolveBinding(); - - assertInstances( col, X, 2 ); - assertInstances( col, T, 3 ); - assertInstances( col, f, 3 ); - } - - public void testBug57800() throws Exception - { + + assertInstances(col, X, 2); + assertInstances(col, T, 3); + assertInstances(col, f, 3); + } + + public void testBug57800() throws Exception { Writer writer= new StringWriter(); - writer.write( "class G2 { int j; };"); //$NON-NLS-1$ - writer.write( "typedef G2 AltG2;"); //$NON-NLS-1$ - writer.write( "class AltG3 : AltG2 { int x;};"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse( writer.toString() ); + writer.write("class G2 { int j; };"); + writer.write("typedef G2 AltG2;"); + writer.write("class AltG3 : AltG2 { int x;};"); + IASTTranslationUnit tu = parse(writer.toString()); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 7 ); + tu.accept(col); + + assertEquals(col.size(), 7); ICPPClassType G2 = (ICPPClassType) col.getName(0).resolveBinding(); ITypedef alt = (ITypedef) col.getName(3).resolveBinding(); - - assertInstances( col, G2, 2 ); - assertInstances( col, alt, 2 ); + + assertInstances(col, G2, 2); + assertInstances(col, alt, 2); } - - public void testBug46246() throws Exception - { + + public void testBug46246() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct A { "); //$NON-NLS-1$ - writer.write( " struct B { int ab; } b; "); //$NON-NLS-1$ - writer.write( " int a; "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "struct A a1; "); //$NON-NLS-1$ - writer.write( "struct B b1; "); //$NON-NLS-1$ - - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.C ); + writer.write("struct A { "); + writer.write(" struct B { int ab; } b; "); + writer.write(" int a; "); + writer.write("}; "); + writer.write("struct A a1; "); + writer.write("struct B b1; "); + + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.C); CNameCollector col = new CNameCollector(); - tu.accept( col ); - - assertEquals( col.size(), 9 ); + tu.accept(col); + + assertEquals(col.size(), 9); ICompositeType A = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType B = (ICompositeType) col.getName(1).resolveBinding(); - - assertInstances( col, A, 2 ); - assertInstances( col, B, 2 ); + + assertInstances(col, A, 2); + assertInstances(col, B, 2); } - - public void testBug45235() throws Exception - { - parse( "class A { friend class B; friend void f(); }; " ); //$NON-NLS-1$ + + public void testBug45235() throws Exception { + parse("class A { friend class B; friend void f(); }; "); } - - public void testBug57791() throws Exception - { + + public void testBug57791() throws Exception { Writer writer = new StringWriter(); - writer.write(" void f() { "); //$NON-NLS-1$ - writer.write(" struct astruct astruct; "); //$NON-NLS-1$ - writer.write(" astruct.foo++; "); //$NON-NLS-1$ - writer.write(" }"); //$NON-NLS-1$ - - parse( writer.toString(), true, ParserLanguage.C ); - } - - public void testBug44249() throws Exception - { + writer.write(" void f() { "); + writer.write(" struct astruct astruct; "); + writer.write(" astruct.foo++; "); + writer.write(" }"); - parse( "class SD_01 { public:\n void SD_01::f_SD_01();};" ); //$NON-NLS-1$ + parse(writer.toString(), true, ParserLanguage.C); } - - public void testBug59149() throws Exception - { + + public void testBug44249() throws Exception { + + parse("class SD_01 { public:\n void SD_01::f_SD_01();};"); + } + + public void testBug59149() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ friend class B; friend class B; };" ); //$NON-NLS-1$ - writer.write( "class B{ };" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug59302() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class A { class N{}; }; "); //$NON-NLS-1$ - writer.write("class B { friend class A::N; }; "); //$NON-NLS-1$ - parse( writer.toString() ); - } - - - - public void testULong() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifndef ASMINCLUDE\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned short ushort;\n"); //$NON-NLS-1$ - writer.write( "typedef volatile unsigned long semaphore;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long ulong;\n"); //$NON-NLS-1$ - writer.write( "#ifndef _NO_LONGLONG\n"); //$NON-NLS-1$ - writer.write( "typedef long long longlong;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long long ulonglong;\n"); //$NON-NLS-1$ - writer.write( "#endif /* _NO_LONGLONG */\n"); //$NON-NLS-1$ - writer.write( "#endif /* ASMINCLUDE */\n"); //$NON-NLS-1$ - writer.write( "typedef struct section_type_ {\n"); //$NON-NLS-1$ - writer.write( "ulong source;\n"); //$NON-NLS-1$ - writer.write( "ulong dest;\n"); //$NON-NLS-1$ - writer.write( "ulong bytes;\n"); //$NON-NLS-1$ - writer.write( "} section_type;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug47926() throws Exception - { - parse( "void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false ); //$NON-NLS-1$ - } - - public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "class num_put { " ); //$NON-NLS-1$ - writer.write( " typedef _OutIter iter_type; " ); //$NON-NLS-1$ - writer.write( " template< typename _ValueT > " ); //$NON-NLS-1$ - writer.write( " iter_type _M_convert_float( iter_type ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "template < typename _ValueT > " ); //$NON-NLS-1$ - writer.write( "_OutIter num_put<_OutIter>::_M_convert_float( _OutIter ) { } " ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testGloballyQualifiedUsingDeclaration() throws Exception - { - parse( "int iii; namespace N { using ::iii; }" ); //$NON-NLS-1$ - } - - public void test57513_new() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( int ); }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( " A * a2 = new(1)A(); \n" ); //$NON-NLS-1$ - writer.write( " A * a3 = new A( 1 ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A{ friend class B; friend class B; };"); + writer.write("class B{ };"); + parse(writer.toString()); } - public void test57513_NoConstructor() throws Exception - { + public void testBug59302() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { class N{}; }; "); + writer.write("class B { friend class A::N; }; "); + parse(writer.toString()); } - - public void test57513_ctorinit() throws Exception - { + + public void testULong() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( A * ); }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A { B(); }; \n" ); //$NON-NLS-1$ - writer.write( "B::B():A( new A ){} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("#ifndef ASMINCLUDE\n"); + writer.write("typedef unsigned short ushort;\n"); + writer.write("typedef volatile unsigned long semaphore;\n"); + writer.write("typedef unsigned long ulong;\n"); + writer.write("#ifndef _NO_LONGLONG\n"); + writer.write("typedef long long longlong;\n"); + writer.write("typedef unsigned long long ulonglong;\n"); + writer.write("#endif /* _NO_LONGLONG */\n"); + writer.write("#endif /* ASMINCLUDE */\n"); + writer.write("typedef struct section_type_ {\n"); + writer.write("ulong source;\n"); + writer.write("ulong dest;\n"); + writer.write("ulong bytes;\n"); + writer.write("} section_type;\n"); + parse(writer.toString()); + } + + public void testBug47926() throws Exception { + parse("void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false); + } + + public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception { + Writer writer = new StringWriter(); + writer.write("template < typename _OutIter > "); + writer.write("class num_put { "); + writer.write(" typedef _OutIter iter_type; "); + writer.write(" template< typename _ValueT > "); + writer.write(" iter_type _M_convert_float(iter_type); "); + writer.write("}; "); + writer.write("template < typename _OutIter > "); + writer.write("template < typename _ValueT > "); + writer.write("_OutIter num_put<_OutIter>::_M_convert_float(_OutIter) { } "); + parse(writer.toString()); } - - public void test575513_qualified() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace Foo{ " ); //$NON-NLS-1$ - writer.write( " class Bar{ public : Bar(); }; " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - writer.write( "void main(){ " ); //$NON-NLS-1$ - writer.write( " Foo::Bar * bar = new Foo::Bar(); " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - parse( writer.toString() ); + + public void testGloballyQualifiedUsingDeclaration() throws Exception { + parse("int iii; namespace N { using ::iii; }"); } - - public void testBug60944() throws Exception - { + + public void test57513_new() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef int OurInt;\n"); //$NON-NLS-1$ - writer.write( "class A { int x; };\n"); //$NON-NLS-1$ - writer.write( "typedef A AnotherA;\n"); //$NON-NLS-1$ - writer.write( "typedef AnotherA SecondA;\n"); //$NON-NLS-1$ - writer.write( "typedef OurInt AnotherInt;\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("class A{ A(); A(int); }; \n"); + writer.write(" void f() { \n"); + writer.write(" A * a1 = new A; \n"); + writer.write(" A * a2 = new(1)A(); \n"); + writer.write(" A * a3 = new A(1); \n"); + writer.write("} \n"); + + parse(writer.toString()); } - - public void testDestructorReference() throws Exception - { + + public void test57513_NoConstructor() throws Exception { Writer writer = new StringWriter(); - writer.write( "class ABC {\n"); //$NON-NLS-1$ - writer.write( " public:\n"); //$NON-NLS-1$ - writer.write( " ~ABC(){ }\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC * abc = new ABC();\n"); //$NON-NLS-1$ - writer.write( "abc->~ABC();\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A{ }; \n"); + writer.write(" void f() { \n"); + writer.write(" A * a1 = new A; \n"); + writer.write("} \n"); + + parse(writer.toString()); + } + + public void test57513_ctorinit() throws Exception { + Writer writer = new StringWriter(); + writer.write("class A{ A(); A(A *); }; \n"); + writer.write("class B : public A { B(); }; \n"); + writer.write("B::B():A(new A){} \n"); + + parse(writer.toString()); + } + + public void test575513_qualified() throws Exception { + Writer writer = new StringWriter(); + writer.write("namespace Foo{ "); + writer.write(" class Bar{ public : Bar(); }; "); + writer.write("} "); + writer.write("void main(){ "); + writer.write(" Foo::Bar * bar = new Foo::Bar(); "); + writer.write("} "); + + parse(writer.toString()); + } + + public void testBug60944() throws Exception { + Writer writer = new StringWriter(); + writer.write("typedef int OurInt;\n"); + writer.write("class A { int x; };\n"); + writer.write("typedef A AnotherA;\n"); + writer.write("typedef AnotherA SecondA;\n"); + writer.write("typedef OurInt AnotherInt;\n"); + parse(writer.toString()); + } + + public void testDestructorReference() throws Exception { + Writer writer = new StringWriter(); + writer.write("class ABC {\n"); + writer.write(" public:\n"); + writer.write(" ~ABC(){ }\n"); + writer.write("};\n"); + writer.write("int main() { ABC * abc = new ABC();\n"); + writer.write("abc->~ABC();\n"); + writer.write("}\n"); + + parse(writer.toString()); } - - public void testBug39676_tough() throws Exception - { - parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, ParserLanguage.C, true ); //$NON-NLS-1$ + + public void testBug39676_tough() throws Exception { + parse("int widths[] = {[0 ... 9] = 1,[10 ... 99] = 2,[100] = 3 };", true, ParserLanguage.C, true); } - - public void testBug60939() throws Exception - { - for( int i = 0; i < 2; ++i ) + + public void testBug60939() throws Exception { + for (int i = 0; i < 2; ++i) { Writer writer = new StringWriter(); - writer.write( "namespace ABC { class DEF { }; }\n"); //$NON-NLS-1$ - if( i == 0 ) - writer.write( "using namespace ABC;\n"); //$NON-NLS-1$ + writer.write("namespace ABC { class DEF { }; }\n"); + if (i == 0) + writer.write("using namespace ABC;\n"); else - writer.write( "using ABC::DEF;\n"); //$NON-NLS-1$ - writer.write( "class GHI : public DEF { };"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("using ABC::DEF;\n"); + writer.write("class GHI : public DEF { };"); + parse(writer.toString()); } - + } - } - - public void testBug64010() throws Exception - { + public void testBug64010() throws Exception { Writer writer = new StringWriter(); - writer.write( " #define ONE else if (0) { } \n"); //$NON-NLS-1$ - writer.write( " #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); //$NON-NLS-1$ - writer.write( " #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); //$NON-NLS-1$ - writer.write( " #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); //$NON-NLS-1$ - writer.write("void foo() "); //$NON-NLS-1$ - writer.write("{ "); //$NON-NLS-1$ - writer.write(" if (0) { } "); //$NON-NLS-1$ - writer.write(" /* 2,500 else if's. */ "); //$NON-NLS-1$ - writer.write(" THOU THOU HUN HUN HUN HUN HUN "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write(" #define ONE else if (0) { } \n"); + writer.write(" #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); + writer.write(" #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); + writer.write(" #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); + writer.write("void foo() "); + writer.write("{ "); + writer.write(" if (0) { } "); + writer.write(" /* 2,500 else if's. */ "); + writer.write(" THOU THOU HUN HUN HUN HUN HUN "); + writer.write("} "); + + parse(writer.toString()); } - - public void testBug64271() throws Exception - { + + public void testBug64271() throws Exception { Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = blah;\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int DWORD;\n"); + writer.write("typedef char BYTE;\n"); + writer.write("#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); + writer.write("((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); + writer.write("((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))\n"); + writer.write("enum e {\n"); + writer.write("blah1 = 5,\n"); + writer.write("blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); + writer.write("blah3\n"); + writer.write("};\n"); + writer.write("e mye = blah;\n"); + parse(writer.toString()); } - - public void testBug47752() throws Exception - { + + public void testBug47752() throws Exception { Writer writer = new StringWriter(); - writer.write( "class BBC\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "int x;\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "void func( BBC bar )\n"); //$NON-NLS-1$ - writer.write( "try\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "catch ( BBC error )\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( " //... error handling code ...\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("class BBC\n"); + writer.write("{\n"); + writer.write("int x;\n"); + writer.write("};\n"); + writer.write("void func(BBC bar)\n"); + writer.write("try\n"); + writer.write("{\n"); + writer.write("}\n"); + writer.write("catch (BBC error)\n"); + writer.write("{\n"); + writer.write(" //... error handling code ...\n"); + writer.write("}\n"); + parse(writer.toString()); } - public void testBug61972() throws Exception - { - parse( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false ); //$NON-NLS-1$ + public void testBug61972() throws Exception { + parse("#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false); } - - public void testBug65569() throws Exception - { - parse( "class Sample;\nstruct Sample { /* ... */ };" ); //$NON-NLS-1$ + + public void testBug65569() throws Exception { + parse("class Sample;\nstruct Sample { /* ... */ };"); } - - public void testBug64268() throws Exception - { + + public void testBug64268() throws Exception { Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write("for (;;) { \\\n"); //$NON-NLS-1$ - writer.write("/* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write("up the parser. */ }\n"); //$NON-NLS-1$ - writer.write(" void abc() {\n"); //$NON-NLS-1$ - writer.write("BODY\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("#define BODY \\\n"); + writer.write("for (;;) { \\\n"); + writer.write("/* this multi-line comment messes \\\n"); + writer.write("up the parser. */ }\n"); + writer.write(" void abc() {\n"); + writer.write("BODY\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ + + public void testBug67622() throws Exception { + parse("const char * x = __FILE__;"); } - - public void testBug67680() throws Exception - { + + public void testBug67680() throws Exception { Writer writer = new StringWriter(); - writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived : public Base, Base, foo {}; \n" ); //$NON-NLS-1$ - - parse( writer.toString(), false ); + writer.write("template < class T> class Base {}; \n"); + writer.write("class Derived : public Base, Base, foo {}; \n"); + + parse(writer.toString(), false); } - - public void testTypeIDSignature() throws Exception - { - parse( "int * v = (int*)0;");//$NON-NLS-1$ + + public void testTypeIDSignature() throws Exception { + parse("int * v = (int*)0;");//$NON-NLS-1$ } - - public void testUnaryAmperCast() throws Exception{ + + public void testUnaryAmperCast() throws Exception { Writer writer = new StringWriter(); - writer.write( "void f( char * ); \r\n "); //$NON-NLS-1$ - writer.write( "void f( char ); \n "); //$NON-NLS-1$ - writer.write( "void main() { \n "); //$NON-NLS-1$ - writer.write( " char * t = new char [ 5 ]; \n "); //$NON-NLS-1$ - writer.write( " f( &t[1] ); \n "); //$NON-NLS-1$ - writer.write( "} \n "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("void f(char *); \r\n "); + writer.write("void f(char ); \n "); + writer.write("void main() { \n "); + writer.write(" char * t = new char[ 5 ]; \n "); + writer.write(" f(&t[1]); \n "); + writer.write("} \n "); + + parse(writer.toString()); } - - public void testBug68235() throws Exception{ + + public void testBug68235() throws Exception { Writer writer = new StringWriter(); - writer.write( " struct xTag { int x; }; "); //$NON-NLS-1$ - writer.write( " typedef xTag xType; "); //$NON-NLS-1$ - writer.write( " typedef struct yTag { int x; } yType; "); //$NON-NLS-1$ - writer.write( " class C1 { xType x; yType y; }; "); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write(" struct xTag { int x; }; "); + writer.write(" typedef xTag xType; "); + writer.write(" typedef struct yTag { int x; } yType; "); + writer.write(" class C1 { xType x; yType y; }; "); + + parse(writer.toString()); } - - public void testBug60407() throws Exception - { + + public void testBug60407() throws Exception { Writer writer = new StringWriter(); - writer.write( "struct ZZZ { int x, y, z; };\r\n" ); //$NON-NLS-1$ - writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ - writer.write( "typedef _FILE FILE;\n" ); //$NON-NLS-1$ - writer.write( "static void static_function(FILE * lcd){}\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "FILE * file = 0;\n" ); //$NON-NLS-1$ - writer.write( "static_function( file );\n" ); //$NON-NLS-1$ - writer.write( "return 0;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("struct ZZZ { int x, y, z; };\r\n"); + writer.write("typedef struct ZZZ _FILE;\n"); + writer.write("typedef _FILE FILE;\n"); + writer.write("static void static_function(FILE * lcd){}\n"); + writer.write("int main(int argc, char **argv) {\n"); + writer.write("FILE * file = 0;\n"); + writer.write("static_function(file);\n"); + writer.write("return 0;\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug68623() throws Exception{ + + public void testBug68623() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A(); \n" ); //$NON-NLS-1$ - writer.write( " class sub{}; \n" ); //$NON-NLS-1$ - writer.write( " sub * x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "A::A() : x( (sub *) 0 ) {} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - + writer.write("class A { \n"); + writer.write(" A(); \n"); + writer.write(" class sub{}; \n"); + writer.write(" sub * x; \n"); + writer.write("}; \n"); + writer.write("A::A() : x((sub *) 0) {} \n"); + + parse(writer.toString()); + writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A() : x (0) {} \n" ); //$NON-NLS-1$ - writer.write( " int x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { \n"); + writer.write(" A() : x (0) {} \n"); + writer.write(" int x; \n"); + writer.write("}; \n"); + + parse(writer.toString()); } - - public void testBug69798() throws Exception{ + + public void testBug69798() throws Exception { Writer writer = new StringWriter(); - writer.write( "enum Flags { FLAG1, FLAG2 }; \n" ); //$NON-NLS-1$ - writer.write( "int f() { int a, b; b = ( a ? FLAG1 : 0 ) | FLAG2; } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("enum Flags { FLAG1, FLAG2 }; \n"); + writer.write("int f() { int a, b; b = (a ? FLAG1 : 0) | FLAG2; } \n"); + + parse(writer.toString()); } - - public void testBug69662() throws Exception{ + + public void testBug69662() throws Exception { Writer writer = new StringWriter(); - writer.write( "class A { operator float * (); }; \n" ); //$NON-NLS-1$ - writer.write( "A::operator float * () { } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("class A { operator float * (); }; \n"); + writer.write("A::operator float * () { } \n"); + + parse(writer.toString()); } - - - public void testBug68528() throws Exception - { + + public void testBug68528() throws Exception { Writer writer = new StringWriter(); - writer.write( "namespace N526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "template \n" ); //$NON-NLS-1$ - writer.write( "class T526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "typedef int diff;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "template\n" ); //$NON-NLS-1$ - writer.write( "inline T526026< T >\n" ); //$NON-NLS-1$ - writer.write( "operator+(typename T526026::diff d, const T526026 & x )\n" ); //$NON-NLS-1$ - writer.write( "{ return T526026< T >(); }\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString(), false ); + writer.write("namespace N526026\n"); + writer.write("{\n"); + writer.write("template \n"); + writer.write("class T526026\n"); + writer.write("{\n"); + writer.write("typedef int diff;\n"); + writer.write("};\n"); + writer.write("\n"); + writer.write("template\n"); + writer.write("inline T526026< T >\n"); + writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); + writer.write("{ return T526026< T >(); }\n"); + writer.write("}\n"); + parse(writer.toString(), false); } - - public void testBug71094() throws Exception - { + + public void testBug71094() throws Exception { Writer writer = new StringWriter(); - writer.write( "using namespace DOESNOTEXIST;\n" ); //$NON-NLS-1$ - writer.write( "class A { int x; };\n" ); //$NON-NLS-1$ - parse( writer.toString(), false ); + writer.write("using namespace DOESNOTEXIST;\n"); + writer.write("class A { int x; };\n"); + parse(writer.toString(), false); } - + public void testPredefinedSymbol_bug70928() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU built-in storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "#define __cdecl __attribute__ ((__cdecl__))\n" ); //$NON-NLS-1$ - writer.write( "typedef int size_t; \n int __cdecl foo(); \n" ); //$NON-NLS-1$ + writer.write("#define __cdecl __attribute__ ((__cdecl__))\n"); + writer.write("typedef int size_t; \n int __cdecl foo(); \n"); parse(writer.toString(), true, ParserLanguage.CPP, true); } - + public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU builtin storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "#define __cdecl __attribute__ ((__cdecl__))\n" ); //$NON-NLS-1$ - writer.write( "typedef int size_t; \n int __cdecl foo(); \n" ); //$NON-NLS-1$ + writer.write("#define __cdecl __attribute__ ((__cdecl__))\n"); + writer.write("typedef int size_t; \n int __cdecl foo(); \n"); parse(writer.toString(), false, ParserLanguage.CPP, false);// test for an infinite loop if the GCC extensions aren't supported parse(writer.toString(), false, ParserLanguage.C, false);// test for an infinite loop if the GCC extensions aren't supported } - + public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type + // GNU builtin storage class type __cdecl preceded by a custom return type Writer writer = new StringWriter(); - writer.write( "int x __attribute__ ((aligned (16))) = 0;\n" ); //$NON-NLS-1$ + writer.write("int x __attribute__ ((aligned (16))) = 0;\n"); parse(writer.toString(), false, ParserLanguage.CPP, false);// test for an infinite loop if the GCC extensions aren't supported parse(writer.toString(), false, ParserLanguage.C, false);// test for an infinite loop if the GCC extensions aren't supported } - + public void testBug102376() throws Exception { Writer writer = new StringWriter(); - writer.write( "int func1 (void) __attribute__((,id2,id (,,),,,));\n" ); //$NON-NLS-1$ - writer.write( "int func2 (void) __attribute__((id,id (id)));\n" ); //$NON-NLS-1$ - writer.write( "int func3 (void) __attribute__((id,id (3)));\n" ); //$NON-NLS-1$ - writer.write( "int func4 (void) __attribute__((id,id (1+2)));\n" ); //$NON-NLS-1$ - writer.write( "void (****f1)(void) __attribute__((noreturn));\n" ); //$NON-NLS-1$ - writer.write( "void (__attribute__((noreturn)) ****f2) (void);\n" ); //$NON-NLS-1$ - writer.write( "char *__attribute__((aligned(8))) *f3;\n" ); //$NON-NLS-1$ - writer.write( "char * __attribute__((aligned(8))) * f3;\n" ); //$NON-NLS-1$ - writer.write( "void fatal1 () __attribute__ ((noreturn));\n" ); //$NON-NLS-1$ - writer.write( "int square1 (int) __attribute__ ((pure));\n" ); //$NON-NLS-1$ - writer.write( "extern int\n" ); //$NON-NLS-1$ - writer.write( "my_printf1 (void *my_object, const char *my_format, ...)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__ ((format (printf, 2, 3)));\n" ); //$NON-NLS-1$ - writer.write( "extern char *\n" ); //$NON-NLS-1$ - writer.write( "my_dgettext1 (char *my_domain, const char *my_format)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__ ((format_arg (2)));\n" ); //$NON-NLS-1$ - writer.write( "extern void *\n" ); //$NON-NLS-1$ - writer.write( "my_memcpy1 (void *dest, const void *src, size_t len)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__((nonnull (1, 2)));\n" ); //$NON-NLS-1$ - writer.write( "extern void *\n" ); //$NON-NLS-1$ - writer.write( "my_memcpy2 (void *dest, const void *src, size_t len)\n" ); //$NON-NLS-1$ - writer.write( "__attribute__((nonnull));\n" ); //$NON-NLS-1$ - writer.write( "extern void foobar3 (void) __attribute__ ((section (\"bar\")));\n" ); //$NON-NLS-1$ - writer.write( "int old_fn () __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "void f5 () __attribute__ ((weak, alias (\"__f\")));\n" ); //$NON-NLS-1$ - writer.write( "void __attribute__ ((visibility (\"protected\")))\n" ); //$NON-NLS-1$ - writer.write( "f6 () { /* Do something. */; }\n" ); //$NON-NLS-1$ - writer.write( "int i2 __attribute__ ((visibility (\"hidden\")));\n" ); //$NON-NLS-1$ - writer.write( "void f7 () __attribute__ ((interrupt (\"IRQ\")));\n" ); //$NON-NLS-1$ - writer.write( "void *alt_stack9;\n" ); //$NON-NLS-1$ - writer.write( "void f8 () __attribute__ ((interrupt_handler,\n" ); //$NON-NLS-1$ - writer.write( "sp_switch (\"alt_stack\")));\n" ); //$NON-NLS-1$ - writer.write( "int x1 __attribute__ ((aligned (16))) = 0;\n" ); //$NON-NLS-1$ - writer.write( "struct foo11 { int x[2] __attribute__ ((aligned (8))); };\n" ); //$NON-NLS-1$ - writer.write( "short array12[3] __attribute__ ((aligned));\n" ); //$NON-NLS-1$ - writer.write( "extern int old_var14 __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "struct foo13\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char a15;\n" ); //$NON-NLS-1$ - writer.write( "int x16[2] __attribute__ ((packed));\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "struct duart15 a16 __attribute__ ((section (\"DUART_A\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "struct duart15 b17 __attribute__ ((section (\"DUART_B\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "char stack18[10000] __attribute__ ((section (\"STACK\"))) = { 0 };\n" ); //$NON-NLS-1$ - writer.write( "int init_data19 __attribute__ ((section (\"INITDATA\"))) = 0;\n" ); //$NON-NLS-1$ - writer.write( "int foo20 __attribute__((section (\"shared\"), shared)) = 0;\n" ); //$NON-NLS-1$ - writer.write( "int foo21 __attribute__ ((vector_size (16)));\n" ); //$NON-NLS-1$ - writer.write( "struct S22 { int a23; };\n" ); //$NON-NLS-1$ - writer.write( "struct S24 __attribute__ ((vector_size (16))) foo;\n" ); //$NON-NLS-1$ - writer.write( "struct S25 { short f27[3]; } __attribute__ ((aligned (8)));\n" ); //$NON-NLS-1$ - writer.write( "typedef int more_aligned_int __attribute__ ((aligned (8)));\n" ); //$NON-NLS-1$ - writer.write( "struct S26 { short f28[3]; } __attribute__ ((aligned));\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "struct my_unpacked_struct29\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char c;\n" ); //$NON-NLS-1$ - writer.write( "int i;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( " \n" ); //$NON-NLS-1$ - writer.write( "struct my_packed_struct __attribute__ ((__packed__))\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "char c;\n" ); //$NON-NLS-1$ - writer.write( "int i;\n" ); //$NON-NLS-1$ - writer.write( "struct my_unpacked_struct29 s;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "typedef union\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "int *__ip;\n" ); //$NON-NLS-1$ - writer.write( "union wait *__up;\n" ); //$NON-NLS-1$ - writer.write( "} wait_status_ptr_t __attribute__ ((__transparent_union__));\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "typedef int T1 __attribute__ ((deprecated));\n" ); //$NON-NLS-1$ - writer.write( "typedef short __attribute__((__may_alias__)) short_a;\n" ); //$NON-NLS-1$ - writer.write( "extern const unsigned short int ** __ctype_b_loc (void) __attribute__ ((__const));" ); //$NON-NLS-1$ - parse( writer.toString(), true, ParserLanguage.C, true ); - parse( writer.toString(), true, ParserLanguage.CPP, true ); + writer.write("int func1 (void) __attribute__((,id2,id (,,),,,));\n"); + writer.write("int func2 (void) __attribute__((id,id (id)));\n"); + writer.write("int func3 (void) __attribute__((id,id (3)));\n"); + writer.write("int func4 (void) __attribute__((id,id (1+2)));\n"); + writer.write("void (****f1)(void) __attribute__((noreturn));\n"); + writer.write("void (__attribute__((noreturn)) ****f2) (void);\n"); + writer.write("char *__attribute__((aligned(8))) *f3;\n"); + writer.write("char * __attribute__((aligned(8))) * f3;\n"); + writer.write("void fatal1 () __attribute__ ((noreturn));\n"); + writer.write("int square1 (int) __attribute__ ((pure));\n"); + writer.write("extern int\n"); + writer.write("my_printf1 (void *my_object, const char *my_format, ...)\n"); + writer.write("__attribute__ ((format (printf, 2, 3)));\n"); + writer.write("extern char *\n"); + writer.write("my_dgettext1 (char *my_domain, const char *my_format)\n"); + writer.write("__attribute__ ((format_arg (2)));\n"); + writer.write("extern void *\n"); + writer.write("my_memcpy1 (void *dest, const void *src, size_t len)\n"); + writer.write("__attribute__((nonnull (1, 2)));\n"); + writer.write("extern void *\n"); + writer.write("my_memcpy2 (void *dest, const void *src, size_t len)\n"); + writer.write("__attribute__((nonnull));\n"); + writer.write("extern void foobar3 (void) __attribute__ ((section (\"bar\")));\n"); + writer.write("int old_fn () __attribute__ ((deprecated));\n"); + writer.write("void f5 () __attribute__ ((weak, alias (\"__f\")));\n"); + writer.write("void __attribute__ ((visibility (\"protected\")))\n"); + writer.write("f6 () { /* Do something. */; }\n"); + writer.write("int i2 __attribute__ ((visibility (\"hidden\")));\n"); + writer.write("void f7 () __attribute__ ((interrupt (\"IRQ\")));\n"); + writer.write("void *alt_stack9;\n"); + writer.write("void f8 () __attribute__ ((interrupt_handler,\n"); + writer.write("sp_switch (\"alt_stack\")));\n"); + writer.write("int x1 __attribute__ ((aligned (16))) = 0;\n"); + writer.write("struct foo11 { int x[2] __attribute__ ((aligned (8))); };\n"); + writer.write("short array12[3] __attribute__ ((aligned));\n"); + writer.write("extern int old_var14 __attribute__ ((deprecated));\n"); + writer.write("struct foo13\n"); + writer.write("{\n"); + writer.write("char a15;\n"); + writer.write("int x16[2] __attribute__ ((packed));\n"); + writer.write("};\n"); + writer.write("struct duart15 a16 __attribute__ ((section (\"DUART_A\"))) = { 0 };\n"); + writer.write("struct duart15 b17 __attribute__ ((section (\"DUART_B\"))) = { 0 };\n"); + writer.write("char stack18[10000] __attribute__ ((section (\"STACK\"))) = { 0 };\n"); + writer.write("int init_data19 __attribute__ ((section (\"INITDATA\"))) = 0;\n"); + writer.write("int foo20 __attribute__((section (\"shared\"), shared)) = 0;\n"); + writer.write("int foo21 __attribute__ ((vector_size (16)));\n"); + writer.write("struct S22 { int a23; };\n"); + writer.write("struct S24 __attribute__ ((vector_size (16))) foo;\n"); + writer.write("struct S25 { short f27[3]; } __attribute__ ((aligned (8)));\n"); + writer.write("typedef int more_aligned_int __attribute__ ((aligned (8)));\n"); + writer.write("struct S26 { short f28[3]; } __attribute__ ((aligned));\n"); + writer.write("\n"); + writer.write("struct my_unpacked_struct29\n"); + writer.write("{\n"); + writer.write("char c;\n"); + writer.write("int i;\n"); + writer.write("};\n"); + writer.write(" \n"); + writer.write("struct my_packed_struct __attribute__ ((__packed__))\n"); + writer.write("{\n"); + writer.write("char c;\n"); + writer.write("int i;\n"); + writer.write("struct my_unpacked_struct29 s;\n"); + writer.write("};\n"); + writer.write("\n"); + writer.write("typedef union\n"); + writer.write("{\n"); + writer.write("int *__ip;\n"); + writer.write("union wait *__up;\n"); + writer.write("} wait_status_ptr_t __attribute__ ((__transparent_union__));\n"); + writer.write("\n"); + writer.write("typedef int T1 __attribute__ ((deprecated));\n"); + writer.write("typedef short __attribute__((__may_alias__)) short_a;\n"); + writer.write("extern const unsigned short int ** __ctype_b_loc (void) __attribute__ ((__const));"); + parse(writer.toString(), true, ParserLanguage.C, true); + parse(writer.toString(), true, ParserLanguage.CPP, true); } - public void testBug73652() throws Exception - { + public void testBug73652() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$ - writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$ - writer.write( "void hang(void)\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() , false ); + writer.write("#define DoSuperMethodA IDoSuperMethodA\n"); + writer.write("#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n"); + writer.write("void hang(void)\n"); + writer.write("{\n"); + writer.write("DoSuperMethodA(0,0,0);\n"); + writer.write("}\n"); + parse(writer.toString() , false); } - - public void testBug73428() throws Exception - { - parse( "namespace { }");//$NON-NLS-1$ - parse( "namespace { };");//$NON-NLS-1$ - parse( "namespace { int abc; };");//$NON-NLS-1$ - parse( "namespace { int abc; }");//$NON-NLS-1$ + + public void testBug73428() throws Exception { + parse("namespace { }");//$NON-NLS-1$ + parse("namespace { };");//$NON-NLS-1$ + parse("namespace { int abc; };");//$NON-NLS-1$ + parse("namespace { int abc; }");//$NON-NLS-1$ } - - public void testBug73615() throws Exception - { - for( int i = 0; i < 2; ++i ) - { + + public void testBug73615() throws Exception { + for (int i = 0; i < 2; ++i) { StringWriter writer = new StringWriter(); - if( i == 0 ) - writer.write( "class B;\n"); //$NON-NLS-1$ - writer.write( "class A { A( B * ); };\n"); //$NON-NLS-1$ - if( i == 0 ) - parse( writer.toString() ); + if (i == 0) + writer.write("class B;\n"); + writer.write("class A { A(B *); };\n"); + if (i == 0) + parse(writer.toString()); else - parse( writer.toString(), false ); + parse(writer.toString(), false); } } - - public void testBug74180() throws Exception - { - parse( "enum DHCPFOBoolean { false, true } additionalHB, more_payload; \n", true, ParserLanguage.C ); //$NON-NLS-1$ + + public void testBug74180() throws Exception { + parse("enum DHCPFOBoolean { false, true } additionalHB, more_payload; \n", true, + ParserLanguage.C); } - - public void testBug72691() throws Exception{ + + public void testBug72691() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int * PINT; \n"); + writer.write("typedef int * PINT; \n"); + writer.write("PINT pint; \n"); + parse(writer.toString()); } - - public void testBug72691_2() throws Exception{ + + public void testBug72691_2() throws Exception { StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "namespace N { \n" ); //$NON-NLS-1$ - writer.write( " typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "using namespace N; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("typedef int * PINT; \n"); + writer.write("namespace N { \n"); + writer.write(" typedef int * PINT; \n"); + writer.write("} \n"); + writer.write("using namespace N; \n"); + writer.write("PINT pint; \n"); + parse(writer.toString()); } - - public void testBug74328() throws Exception - { + + public void testBug74328() throws Exception { Writer writer = new StringWriter(); - writer.write( "int\n" ); //$NON-NLS-1$ - writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " char *sign;\n" ); //$NON-NLS-1$ - writer.write( "sign = \"\"; // IProblem generated here, syntax error\n" ); //$NON-NLS-1$ - writer.write( "return argc;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("int\n"); + writer.write("main(int argc, char **argv) {\n"); + writer.write(" char *sign;\n"); + writer.write("sign = \"\"; // IProblem generated here, syntax error\n"); + writer.write("return argc;\n"); + writer.write("}\n"); + parse(writer.toString()); } - - public void testBug71733() throws Exception - { + + public void testBug71733() throws Exception { Writer writer = new StringWriter(); - writer.write( "void foo( int );\n"); //$NON-NLS-1$ - writer.write( "#define BLAH() \\\n"); //$NON-NLS-1$ - writer.write( " foo ( /* slash / is misinterpreted as end of comment */ \\\n"); //$NON-NLS-1$ - writer.write( " 4 );\n"); //$NON-NLS-1$ - writer.write( "int f() { BLAH() }\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("void foo(int);\n"); + writer.write("#define BLAH() \\\n"); + writer.write(" foo (/* slash / is misinterpreted as end of comment */ \\\n"); + writer.write(" 4);\n"); + writer.write("int f() { BLAH() }\n"); + parse(writer.toString()); } - - public void testBug69526() throws Exception - { + + public void testBug69526() throws Exception { Writer writer = new StringWriter(); - writer.write( "unsigned inkernel;\n" ); //$NON-NLS-1$ - writer.write( "#define lock_kernel() (inkernel |= 0x01)" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {" ); //$NON-NLS-1$ - writer.write( "lock_kernel();" ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("unsigned inkernel;\n"); + writer.write("#define lock_kernel() (inkernel |= 0x01)"); + writer.write("int main(int argc, char **argv) {"); + writer.write("lock_kernel();"); + writer.write("}"); + parse(writer.toString()); } - - public void testBug69454() throws Exception - { + + public void testBug69454() throws Exception { Writer writer = new StringWriter(); - writer.write( "#define CATCH_ALL_EXCEPTIONS() \\\n" ); //$NON-NLS-1$ - writer.write( " catch( Exception &ex ) { handleException( ex ); } \\\n" ); //$NON-NLS-1$ - writer.write( " catch( ... ) { handleException(); } \n" ); //$NON-NLS-1$ - writer.write( "class Exception; \n" ); //$NON-NLS-1$ - writer.write( "void handleException( Exception & ex ) {} \n" ); //$NON-NLS-1$ - writer.write( "void handleException() {} \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " try { int i; } \n" ); //$NON-NLS-1$ - writer.write( " CATCH_ALL_EXCEPTIONS(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ + writer.write("#define CATCH_ALL_EXCEPTIONS() \\\n"); + writer.write(" catch(Exception &ex) { handleException(ex); } \\\n"); + writer.write(" catch(...) { handleException(); } \n"); + writer.write("class Exception; \n"); + writer.write("void handleException(Exception & ex) {} \n"); + writer.write("void handleException() {} \n"); + writer.write("void f() { \n"); + writer.write(" try { int i; } \n"); + writer.write(" CATCH_ALL_EXCEPTIONS(); \n"); + writer.write("} \n"); - parse( writer.toString() ); + parse(writer.toString()); } - - public void testBug72692A() throws Exception - { + public void testBug72692A() throws Exception { Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "extern double pow2(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "using ::pow2;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - writer.write( "using DS::pow2;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug72692B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "inline float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return ::pow(static_cast(__x), static_cast(__y)); }\n" ); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using namespace DS;\n"); //$NON-NLS-1$ - writer.write( "float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double);\n"); + writer.write("extern double pow2(double, double){}\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("using ::pow2;\n"); + writer.write("}\n"); + writer.write("using DS::pow;\n"); + writer.write("using DS::pow2;\n"); + parse(writer.toString()); } - public void testBug72692C() throws Exception - { + public void testBug72692B() throws Exception { Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double);\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("inline float pow(float __x, float __y)\n"); + writer.write("{ return ::pow(static_cast(__x), static_cast(__y)); }\n"); + writer.write("}\n"); + writer.write("using namespace DS;\n"); + writer.write("float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); + parse(writer.toString()); } - - public void testBug74575A() throws Exception - { + public void testBug72692C() throws Exception { Writer writer = new StringWriter(); - writer.write( "double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return 0; }\n"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("extern double pow(double, double){}\n"); + writer.write("namespace DS {\n"); + writer.write("using ::pow;\n"); + writer.write("}\n"); + writer.write("using DS::pow;\n"); + parse(writer.toString()); } - - public void testBug75338() throws Exception - { + + public void testBug74575A() throws Exception { Writer writer = new StringWriter(); - writer.write( "class Thrown { };\n"); //$NON-NLS-1$ - writer.write( "void foo() throw( Thrown );"); //$NON-NLS-1$ - parse( writer.toString() ); + writer.write("double pow(double, double);\n"); + writer.write("float pow(float __x, float __y)\n"); + writer.write("{ return 0; }\n"); + parse(writer.toString()); } - + + public void testBug75338() throws Exception { + Writer writer = new StringWriter(); + writer.write("class Thrown { };\n"); + writer.write("void foo() throw(Thrown);"); + parse(writer.toString()); + } + public void testBug74847() throws Exception { - String code = "class A : public FOO {};"; //$NON-NLS-1$ - parse( code, false ); + String code = "class A : public FOO {};"; + parse(code, false); } - - public void testBug76696() throws Exception{ + + public void testBug76696() throws Exception { Writer writer = new StringWriter(); - writer.write(" void f(){ \n"); //$NON-NLS-1$ - writer.write(" if( A a) { \n"); //$NON-NLS-1$ - writer.write(" } else { \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - - parse( writer.toString(), false ); + writer.write(" void f(){ \n"); + writer.write(" if (A a) { \n"); + writer.write(" } else { \n"); + writer.write(" } \n"); + writer.write(" } \n"); + + parse(writer.toString(), false); } - - public void testBug74069() throws Exception{ + + public void testBug74069() throws Exception { Writer writer = new StringWriter(); - writer.write( "int f() { \n"); //$NON-NLS-1$ - writer.write( " int a, b, c; \n"); //$NON-NLS-1$ - writer.write( " if( a < b ) \n"); //$NON-NLS-1$ - writer.write( " if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( " else if ( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); + writer.write("int f() { \n"); + writer.write(" int a, b, c; \n"); + writer.write(" if (a < b) \n"); + writer.write(" if (b < c) \n"); + writer.write(" return b; \n"); + writer.write(" else if (a < c) \n"); + writer.write(" return c; \n"); + writer.write(" else \n"); + writer.write(" return a; \n"); + writer.write(" else if (a < c) \n"); + writer.write(" return a; \n"); + writer.write(" else if (b < c) \n"); + writer.write(" return c; \n"); + writer.write(" else \n"); + writer.write(" return b; \n"); + writer.write("} \n"); + + parse(writer.toString()); } + public void testBug77805() throws Exception { Writer writer = new StringWriter(); - writer.write("#if X // Do something only if X is true\n"); //$NON-NLS-1$ - writer.write("/* some statements */\n"); //$NON-NLS-1$ - writer.write("#endif\n"); //$NON-NLS-1$ + writer.write("#if X // Do something only if X is true\n"); + writer.write("/* some statements */\n"); + writer.write("#endif\n"); parse(writer.toString()); } - + public void testBug77821() throws Exception { Writer writer = new StringWriter(); - writer.write("typedef struct { /* ... */ }TYPE;\n"); //$NON-NLS-1$ - writer.write("void ptrArith(const TYPE* pType) {\n"); //$NON-NLS-1$ - writer.write("TYPE *temp = 0;\n"); //$NON-NLS-1$ - writer.write("temp = (TYPE*)(pType + 1); /* Parser error is here */\n}\n"); //$NON-NLS-1$ + writer.write("typedef struct { /* ... */ }TYPE;\n"); + writer.write("void ptrArith(const TYPE* pType) {\n"); + writer.write("TYPE *temp = 0;\n"); + writer.write("temp = (TYPE*)(pType + 1); /* Parser error is here */\n}\n"); parse(writer.toString()); } - - public void testBug77009() throws Exception - { - parse("int foo(volatile int &);\n"); //$NON-NLS-1$ + + public void testBug77009() throws Exception { + parse("int foo(volatile int &);\n"); } - - + public void testBug77281() throws Exception { Writer writer = new StringWriter(); - writer.write("void fun2(float a, float b) {}\n"); //$NON-NLS-1$ - writer.write("int main() { fun2(0.24f, 0.25f); }\n"); //$NON-NLS-1$ + writer.write("void fun2(float a, float b) {}\n"); + writer.write("int main() { fun2(0.24f, 0.25f); }\n"); parse(writer.toString()); } - + public void testBug77921() throws Exception { Writer writer = new StringWriter(); - writer.write("void f()\n{\n"); //$NON-NLS-1$ - writer.write("static float v0[] = { -1.0f, -1.0f, 1.0f };\n}\n"); //$NON-NLS-1$ + writer.write("void f()\n{\n"); + writer.write("static float v0[] = { -1.0f, -1.0f, 1.0f };\n}\n"); parse(writer.toString()); } - - + public void testBug71317A() throws Exception { Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("using ::f;\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ + writer.write("void f();\n"); + writer.write("namespace NS {\n"); + writer.write("using ::f;\n"); + writer.write("using ::f;\n}"); parse(writer.toString()); } public void testBug71317B() throws Exception { Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ + writer.write("void f();\n"); + writer.write("namespace NS {\n"); + writer.write("void f();\n"); + writer.write("using ::f;\n}"); parse(writer.toString()); } - + public void testBug77097() throws Exception { Writer writer = new StringWriter(); - writer.write("#define SOME_MACRO() { \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Hello World\"); \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Good morning\"); \\\r\n"); //$NON-NLS-1$ + writer.write("#define SOME_MACRO() { \\\r\n"); + writer.write("printf(\"Hello World\"); \\\r\n"); + writer.write("printf(\"Good morning\"); \\\r\n"); parse(writer.toString()); } - + public void testBug77276() throws Exception { Writer writer = new StringWriter(); - writer.write("#if (!defined(OS_LIBMODE_R) && !defined(OS_LIBMODE_RP) && \\\r\n"); //$NON-NLS-1$ - writer.write("!defined(OS_LIBMODE_T))\r\n"); //$NON-NLS-1$ - writer.write("#define OS_LIBMODE_DP\r\n"); //$NON-NLS-1$ - writer.write("#endif\r\n"); //$NON-NLS-1$ + writer.write("#if (!defined(OS_LIBMODE_R) && !defined(OS_LIBMODE_RP) && \\\r\n"); + writer.write("!defined(OS_LIBMODE_T))\r\n"); + writer.write("#define OS_LIBMODE_DP\r\n"); + writer.write("#endif\r\n"); parse(writer.toString()); } - + public void testBug78165() throws Exception { Writer writer = new StringWriter(); - writer.write("struct Node {\n"); //$NON-NLS-1$ - writer.write("struct Node* Next; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("struct Data* Data; // OK: Declares type Data at global scope and member Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data {\n"); //$NON-NLS-1$ - writer.write("struct Node* Node; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Base {\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Declares nested Data\n"); //$NON-NLS-1$ - writer.write("struct ::Data* thatData; // OK: Refers to ::Data\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* thisData; // OK: Refers to nested Data\n"); //$NON-NLS-1$ - writer.write("friend class ::Data; // OK: global Data is a friend\n"); //$NON-NLS-1$ - writer.write("friend class Data; // OK: nested Data is a friend\n"); //$NON-NLS-1$ - writer.write("struct Data { /* ... */ }; // Defines nested Data\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares nested Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares Data at global scope\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* pBase; // OK: refers to nested Data\n"); //$NON-NLS-1$ + writer.write("struct Node {\n"); + writer.write("struct Node* Next; // OK: Refers to Node at global scope\n"); + writer.write("struct Data* Data; // OK: Declares type Data at global scope and member Data\n"); + writer.write("};\n"); + writer.write("struct Data {\n"); + writer.write("struct Node* Node; // OK: Refers to Node at global scope\n"); + writer.write("friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.\n"); + writer.write("};\n"); + writer.write("struct Base {\n"); + writer.write("struct Data; // OK: Declares nested Data\n"); + writer.write("struct ::Data* thatData; // OK: Refers to ::Data\n"); + writer.write("struct Base::Data* thisData; // OK: Refers to nested Data\n"); + writer.write("friend class ::Data; // OK: global Data is a friend\n"); + writer.write("friend class Data; // OK: nested Data is a friend\n"); + writer.write("struct Data { /* ... */ }; // Defines nested Data\n"); + writer.write("struct Data; // OK: Redeclares nested Data\n"); + writer.write("};\n"); + writer.write("struct Data; // OK: Redeclares Data at global scope\n"); + writer.write("struct Base::Data* pBase; // OK: refers to nested Data\n"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug103560() throws Exception { Writer writer = new StringWriter(); - writer.write("#define A( a, b ) a ## b \n"); //$NON-NLS-1$ - writer.write("#define FOOBAR 1 \n"); //$NON-NLS-1$ - writer.write("int i = A( FOO, BAR ); \n"); //$NON-NLS-1$ - parse( writer.toString(), true, ParserLanguage.CPP ); + writer.write("#define A(a, b) a ## b \n"); + writer.write("#define FOOBAR 1 \n"); + writer.write("int i = A(FOO, BAR); \n"); + parse(writer.toString(), true, ParserLanguage.CPP); } - + public void test158192_declspec_on_class() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("class __declspec(foobar) Foo1 {};\n"); writer.write("union __declspec(foobar) Foo2 {};\n"); writer.write("struct __declspec(foobar) Foo3 {};\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true ); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 3, col.size()); + assertEquals(3, col.size()); ICompositeType fooClass = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType fooUnion = (ICompositeType) col.getName(1).resolveBinding(); ICompositeType fooStruct = (ICompositeType) col.getName(2).resolveBinding(); @@ -2649,17 +2488,17 @@ public class CompleteParser2Tests extends BaseTestCase { } public void test158192_declspec_on_variable() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("__declspec(foobar) class Foo {} bar;\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 2, col.size()); + assertEquals(2, col.size()); ICompositeType fooClass = (ICompositeType) col.getName(0).resolveBinding(); ICPPVariable bar = (ICPPVariable) col.getName(1).resolveBinding(); @@ -2670,33 +2509,33 @@ public class CompleteParser2Tests extends BaseTestCase { // MSVC does not allow declspec in this position, GCC does so we test for this // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=158192 public void test158192_declspec_in_declarator() throws Exception { - if(!Platform.getOS().equals(Platform.OS_WIN32)) + if (!Platform.getOS().equals(Platform.OS_WIN32)) return; // XXX: see GPPParserExtensionConfiguration.supportDeclspecSpecifiers() - + Writer writer = new StringWriter(); writer.write("int * __declspec(foo) bar = 0;\n"); - IASTTranslationUnit tu = parse( writer.toString(), true, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parse(writer.toString(), true, ParserLanguage.CPP, true); - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertFalse("__declspec rejected inside declarator", problems.length>0 ); + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertFalse("__declspec rejected inside declarator", problems.length>0); CPPNameCollector col = new CPPNameCollector(); - tu.accept( col ); + tu.accept(col); - assertEquals( 1, col.size()); + assertEquals(1, col.size()); ICPPVariable bar = (ICPPVariable) col.getName(0).resolveBinding(); assertInstances(col, bar, 1); } - + public void test173874_nestedClasses() throws Exception { String code = "class aClass { class bClass; int x; };"; IASTTranslationUnit tu = parse(code, true, ParserLanguage.CPP, true); - + CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + ICPPClassType cls = (ICPPClassType)col.getName(0).resolveBinding(); ICPPClassType[] nested = cls.getNestedClasses(); assertEquals(1, nested.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 8fea36b2b9a..7c7b93a3234 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -151,15 +151,10 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest { public String getParserDialect() { return dialect; } - } private static final String[] EMPTY_STRING_ARRAY = new String[0]; - /** - * @param name - * @param className - */ public DOMLocationInclusionTests(String name) { super(name, DOMLocationInclusionTests.class); } @@ -178,13 +173,6 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest { new ParserConfiguration(s, code)); } - /** - * @param pathEndsWith - * TODO - * @param offset - * @param length - * @param declarator - */ protected void assertSoleFileLocation(IASTNode n, String pathEndsWith, int offset, int length) { IASTNodeLocation[] locations = n.getNodeLocations(); assertEquals(locations.length, 1); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 34dd6256ac4..80ec78f9b37 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -178,11 +178,6 @@ public class DOMLocationTests extends AST2BaseTest { } - /** - * @param declarator - * @param offset - * @param length - */ private void assertSoleLocation(IASTNode n, int offset, int length) { assertEquals(length, ((ASTNode)n).getLength()); IASTNodeLocation[] locations = n.getNodeLocations(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java index eb7eb48b99c..10fc1e5a816 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSearchUtil.java @@ -35,8 +35,8 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.content.IContentType; /** - * Utility class to have commonly used algorithms in one place for searching with the DOM. - * + * Utility class to have commonly used algorithms in one place for searching with the DOM. + * * @author dsteffle */ public class DOMSearchUtil { @@ -48,28 +48,26 @@ public class DOMSearchUtil { public static final int DECLARATIONS_DEFINITIONS = 3; public static final int REFERENCES = 4; public static final int ALL_OCCURRENCES = 5; + /** - * This retrieves the ParserLanguage from an IFile. - * - * @param file - * @return - */ + * Retrieves the ParserLanguage from an file. + */ public static ParserLanguage getLanguageFromFile(IFile file) { IProject project = file.getProject(); IContentType contentType = CCorePlugin.getContentType(project, file.getFullPath().lastSegment()); if (contentType != null) { String lid = contentType.getId(); - if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid) || + if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid) || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(lid)) { return ParserLanguage.CPP; } - } + } return ParserLanguage.C; } /** * The CPPNameCollector used to get IASTNames from an IASTNode. - * + * * @author dsteffle */ static public class CPPNameCollector extends ASTVisitor { @@ -78,21 +76,21 @@ public class DOMSearchUtil { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name) { + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } /** * The CNameCollector used to get IASTNames from an IASTNode. - * + * * @author dsteffle */ static public class CNameCollector extends ASTVisitor { @@ -101,27 +99,22 @@ public class DOMSearchUtil { } public List nameList = new ArrayList(); @Override - public int visit( IASTName name ){ - nameList.add( name ); + public int visit(IASTName name) { + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) return null; - return (IASTName) nameList.get( idx ); + return (IASTName) nameList.get(idx); } - public int size() { return nameList.size(); } + public int size() { return nameList.size(); } } - + /** * Returns the ParserLanguage corresponding to the IPath and IProject. Returns ParserLanguage.CPP if the file type is a header. - * - * @param path - * @param project - * @return */ - public static ParserLanguage getLanguage( IPath path, IProject project ) - { + public static ParserLanguage getLanguage(IPath path, IProject project) { //FIXME: ALAIN, for headers should we assume CPP ?? // The problem is that it really depends on how the header was included. String id = null; @@ -135,7 +128,7 @@ public class DOMSearchUtil { } else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) { return ParserLanguage.CPP; } else if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) { - return ParserLanguage.C; + return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) { return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) { @@ -148,24 +141,24 @@ public class DOMSearchUtil { /** * This is used to get the names from the TU that the IASTName searchName belongs to. - * - * @param searchName the IASTName whose references/delcarations are to be retrieved - * @param limitTo used to specify whether to get declarations, references, or both, one of: - * ( CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES ) + * + * @param searchName the IASTName whose references/declarations are to be retrieved + * @param limitTo used to specify whether to get declarations, references, or both, one of: + * (CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES) * @return IASTName[] declarations, references, or both depending on limitTo that correspond to the IASTName searchName searched for */ public static IName[] getNamesFromDOM(IASTName searchName, int limitTo) { IName[] names = null; IASTTranslationUnit tu = searchName.getTranslationUnit(); - + if (tu == null) { return BLANK_NAME_ARRAY; } - + IBinding binding = searchName.resolveBinding(); if (binding instanceof IIndexBinding) { Assert.fail("Not implemented"); -// try { +// try { // ArrayList pdomNames = new ArrayList(); // IPDOMResolver pdom= ((PDOMBinding) binding).getPDOM(); // // First decls @@ -180,22 +173,23 @@ public class DOMSearchUtil { // } } else { names = getNames(tu, binding, limitTo); - - if (names == null || names.length == 0) { // try alternate strategies + + if (names == null || names.length == 0) { // try alternate strategies try { // fix for 86829, 95224 - if ((binding instanceof ICPPConstructor || (binding instanceof ICPPMethod && ((ICPPMethod)binding).isDestructor())) + if ((binding instanceof ICPPConstructor || (binding instanceof ICPPMethod && ((ICPPMethod)binding).isDestructor())) && binding.getScope() instanceof ICPPClassScope) { binding = ((ICPPClassScope)binding.getScope()).getClassType(); names = getNames(tu, binding, limitTo); } - } catch (DOMException e) {} + } catch (DOMException e) { + } } } return names; } - + private static IASTName[] getNames(IASTTranslationUnit tu, IBinding binding, int limitTo) { IASTName[] names = null; if (limitTo == DECLARATIONS || @@ -205,15 +199,14 @@ public class DOMSearchUtil { names = tu.getReferences(binding); } else if (limitTo == DEFINITIONS) { names = tu.getDefinitionsInAST(binding); - } else if (limitTo == ALL_OCCURRENCES){ + } else if (limitTo == ALL_OCCURRENCES) { names = tu.getDeclarationsInAST(binding); names = ArrayUtil.addAll(IASTName.class, names, tu.getReferences(binding)); } else { // assume ALL names = tu.getDeclarationsInAST(binding); names = ArrayUtil.addAll(IASTName.class, names, tu.getReferences(binding)); } - + return names; } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java index 56570492300..33cc1a0d043 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -44,23 +44,15 @@ import org.eclipse.cdt.internal.core.parser.ParserException; * @author jcamelon */ public class QuickParser2Tests extends TestCase { - private static final NullLogService NULL_LOG = new NullLogService(); - /** - * - */ public QuickParser2Tests() { super(); } - /** - * @param name - */ public QuickParser2Tests(String name) { super(name); } - @Override protected void setUp() throws Exception { @@ -69,7 +61,7 @@ public class QuickParser2Tests extends TestCase { } /** - * Test code: int x = 5; Purpose: to test the simple decaration in it's + * Test code: int x = 5; Purpose: to test the simple declaration in it's * simplest form. */ public void testIntGlobal() throws Exception { @@ -160,30 +152,29 @@ public class QuickParser2Tests extends TestCase { public void testSimpleClassMembers() throws Exception { // Parse and get the translaton unit Writer code = new StringWriter(); - code - .write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); + code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); parse(code.toString()); } /** - * Test code: int myFunction( void ); + * Test code: int myFunction(void); */ public void testSimpleFunctionDeclaration() throws Exception { // Parse and get the translaton unit Writer code = new StringWriter(); - code.write("void myFunction( void );"); + code.write("void myFunction(void);"); parse(code.toString()); } /** - * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); + * Test code: bool myFunction(int parm1 = 3 * 4, double parm2); * * @throws Exception */ public void testFunctionDeclarationWithParameters() throws Exception { // Parse and get the translaton unit Writer code = new StringWriter(); - code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );"); + code.write("bool myFunction(int parm1 = 3 * 4, double parm2);"); parse(code.toString()); } @@ -208,8 +199,8 @@ public class QuickParser2Tests extends TestCase { } public void testBug36290() throws Exception { - parse("typedef void ( A:: * pMethod ) ( void ); "); - parse("typedef void (boo) ( void ); "); + parse("typedef void (A:: * pMethod) (void); "); + parse("typedef void (boo) (void); "); parse("typedef void boo (void); "); } @@ -245,113 +236,113 @@ public class QuickParser2Tests extends TestCase { // failing, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856 public void _testBug36932C() throws Exception { - parse("X::X( ) : var( new int ) {}"); - parse("X::X( ) : var( new int(5) ) {}"); - parse("X::X( ) : var( new int(B) ) {}"); - parse("X::X( ) : var( new int(B,C) ) {}"); - parse("X::X( ) : var( new int[5] ) {}"); - parse("X::X( ) : var( new int[5][10] ) {}"); - parse("X::X( ) : var( new int[B] ) {}"); - parse("X::X( ) : var( new int[B][C][D] ) {}"); + parse("X::X() : var(new int) {}"); + parse("X::X() : var(new int(5)) {}"); + parse("X::X() : var(new int(B)) {}"); + parse("X::X() : var(new int(B,C)) {}"); + parse("X::X() : var(new int[5]) {}"); + parse("X::X() : var(new int[5][10]) {}"); + parse("X::X() : var(new int[B]) {}"); + parse("X::X() : var(new int[B][C][D]) {}"); - parse("X::X( ) : var( new A ) {}"); - parse("X::X( ) : var( new A(5) ) {}"); - parse("X::X( ) : var( new A(B) ) {}"); - parse("X::X( ) : var( new A(B,C) ) {}"); - parse("X::X( ) : var( new A[5] ) {}"); - parse("X::X( ) : var( new A[5][10] ) {}"); - parse("X::X( ) : var( new A[B] ) {}"); - parse("X::X( ) : var( new A[B][C][D] ) {}"); + parse("X::X() : var(new A) {}"); + parse("X::X() : var(new A(5)) {}"); + parse("X::X() : var(new A(B)) {}"); + parse("X::X() : var(new A(B,C)) {}"); + parse("X::X() : var(new A[5]) {}"); + parse("X::X() : var(new A[5][10]) {}"); + parse("X::X() : var(new A[B]) {}"); + parse("X::X() : var(new A[B][C][D]) {}"); - parse("X::X( ) : var( new (int) ) {}"); - parse("X::X( ) : var( new (int)(5) ) {}"); - parse("X::X( ) : var( new (int)(B) ) {}"); - parse("X::X( ) : var( new (int)(B,C) ) {}"); - parse("X::X( ) : var( new (int[5]) ) {}"); - parse("X::X( ) : var( new (int[5][10]) ) {}"); - parse("X::X( ) : var( new (int[B]) ) {}"); - parse("X::X( ) : var( new (int[B][C][D]) ) {}"); + parse("X::X() : var(new (int)) {}"); + parse("X::X() : var(new (int)(5)) {}"); + parse("X::X() : var(new (int)(B)) {}"); + parse("X::X() : var(new (int)(B,C)) {}"); + parse("X::X() : var(new (int[5])) {}"); + parse("X::X() : var(new (int[5][10])) {}"); + parse("X::X() : var(new (int[B])) {}"); + parse("X::X() : var(new (int[B][C][D])) {}"); - parse("X::X( ) : var( new (A) ) {}"); - parse("X::X( ) : var( new (A)(5) ) {}"); - parse("X::X( ) : var( new (A)(B) ) {}"); - parse("X::X( ) : var( new (A)(B,C) ) {}"); - parse("X::X( ) : var( new (A[5]) ) {}"); - parse("X::X( ) : var( new (A[5][10]) ) {}"); - parse("X::X( ) : var( new (A[B]) ) {}"); - parse("X::X( ) : var( new (A[B][C][D]) ) {}"); + parse("X::X() : var(new (A)) {}"); + parse("X::X() : var(new (A)(5)) {}"); + parse("X::X() : var(new (A)(B)) {}"); + parse("X::X() : var(new (A)(B,C)) {}"); + parse("X::X() : var(new (A[5])) {}"); + parse("X::X() : var(new (A[5][10])) {}"); + parse("X::X() : var(new (A[B])) {}"); + parse("X::X() : var(new (A[B][C][D])) {}"); - parse("X::X( ) : var( new (0) int ) {}"); - parse("X::X( ) : var( new (0) int(5) ) {}"); - parse("X::X( ) : var( new (0) int(B) ) {}"); - parse("X::X( ) : var( new (0) int(B,C) ) {}"); - parse("X::X( ) : var( new (0) int[5] ) {}"); - parse("X::X( ) : var( new (0) int[5][10] ) {}"); - parse("X::X( ) : var( new (0) int[B] ) {}"); - parse("X::X( ) : var( new (0) int[B][C][D] ) {}"); + parse("X::X() : var(new (0) int) {}"); + parse("X::X() : var(new (0) int(5)) {}"); + parse("X::X() : var(new (0) int(B)) {}"); + parse("X::X() : var(new (0) int(B,C)) {}"); + parse("X::X() : var(new (0) int[5]) {}"); + parse("X::X() : var(new (0) int[5][10]) {}"); + parse("X::X() : var(new (0) int[B]) {}"); + parse("X::X() : var(new (0) int[B][C][D]) {}"); - parse("X::X( ) : var( new (0) A ) {}"); - parse("X::X( ) : var( new (0) A(5) ) {}"); - parse("X::X( ) : var( new (0) A(B) ) {}"); - parse("X::X( ) : var( new (0) A(B,C) ) {}"); - parse("X::X( ) : var( new (0) A[5] ) {}"); - parse("X::X( ) : var( new (0) A[5][10] ) {}"); - parse("X::X( ) : var( new (0) A[B] ) {}"); - parse("X::X( ) : var( new (0) A[B][C][D] ) {}"); + parse("X::X() : var(new (0) A) {}"); + parse("X::X() : var(new (0) A(5)) {}"); + parse("X::X() : var(new (0) A(B)) {}"); + parse("X::X() : var(new (0) A(B,C)) {}"); + parse("X::X() : var(new (0) A[5]) {}"); + parse("X::X() : var(new (0) A[5][10]) {}"); + parse("X::X() : var(new (0) A[B]) {}"); + parse("X::X() : var(new (0) A[B][C][D]) {}"); - parse("X::X( ) : var( new (0) (int) ) {}"); - parse("X::X( ) : var( new (0) (int)(5) ) {}"); - parse("X::X( ) : var( new (0) (int)(B) ) {}"); - parse("X::X( ) : var( new (0) (int)(B,C) ) {}"); - parse("X::X( ) : var( new (0) (int[5]) ) {}"); - parse("X::X( ) : var( new (0) (int[5][10]) ) {}"); - parse("X::X( ) : var( new (0) (int[B]) ) {}"); - parse("X::X( ) : var( new (0) (int[B][C][D]) ) {}"); + parse("X::X() : var(new (0) (int)) {}"); + parse("X::X() : var(new (0) (int)(5)) {}"); + parse("X::X() : var(new (0) (int)(B)) {}"); + parse("X::X() : var(new (0) (int)(B,C)) {}"); + parse("X::X() : var(new (0) (int[5])) {}"); + parse("X::X() : var(new (0) (int[5][10])) {}"); + parse("X::X() : var(new (0) (int[B])) {}"); + parse("X::X() : var(new (0) (int[B][C][D])) {}"); - parse("X::X( ) : var( new (0) (A) ) {}"); - parse("X::X( ) : var( new (0) (A)(5) ) {}"); - parse("X::X( ) : var( new (0) (A)(B) ) {}"); - parse("X::X( ) : var( new (0) (A)(B,C) ) {}"); - parse("X::X( ) : var( new (0) (A[5]) ) {}"); - parse("X::X( ) : var( new (0) (A[5][10]) ) {}"); - parse("X::X( ) : var( new (0) (A[B]) ) {}"); - parse("X::X( ) : var( new (0) (A[B][C][D]) ) {}"); + parse("X::X() : var(new (0) (A)) {}"); + parse("X::X() : var(new (0) (A)(5)) {}"); + parse("X::X() : var(new (0) (A)(B)) {}"); + parse("X::X() : var(new (0) (A)(B,C)) {}"); + parse("X::X() : var(new (0) (A[5])) {}"); + parse("X::X() : var(new (0) (A[5][10])) {}"); + parse("X::X() : var(new (0) (A[B])) {}"); + parse("X::X() : var(new (0) (A[B][C][D])) {}"); - parse("X::X( ) : var( new (P) int ) {}"); - parse("X::X( ) : var( new (P) int(5) ) {}"); - parse("X::X( ) : var( new (P) int(B) ) {}"); - parse("X::X( ) : var( new (P) int(B,C) ) {}"); - parse("X::X( ) : var( new (P) int[5] ) {}"); - parse("X::X( ) : var( new (P) int[5][10] ) {}"); - parse("X::X( ) : var( new (P) int[B] ) {}"); - parse("X::X( ) : var( new (P) int[B][C][D] ) {}"); + parse("X::X() : var(new (P) int) {}"); + parse("X::X() : var(new (P) int(5)) {}"); + parse("X::X() : var(new (P) int(B)) {}"); + parse("X::X() : var(new (P) int(B,C)) {}"); + parse("X::X() : var(new (P) int[5]) {}"); + parse("X::X() : var(new (P) int[5][10]) {}"); + parse("X::X() : var(new (P) int[B]) {}"); + parse("X::X() : var(new (P) int[B][C][D]) {}"); - parse("X::X( ) : var( new (P) A ) {}"); - parse("X::X( ) : var( new (P) A(5) ) {}"); - parse("X::X( ) : var( new (P) A(B) ) {}"); - parse("X::X( ) : var( new (P) A(B,C) ) {}"); - parse("X::X( ) : var( new (P) A[5] ) {}"); - parse("X::X( ) : var( new (P) A[5][10] ) {}"); - parse("X::X( ) : var( new (P) A[B] ) {}"); - parse("X::X( ) : var( new (P) A[B][C][D] ) {}"); + parse("X::X() : var(new (P) A) {}"); + parse("X::X() : var(new (P) A(5)) {}"); + parse("X::X() : var(new (P) A(B)) {}"); + parse("X::X() : var(new (P) A(B,C)) {}"); + parse("X::X() : var(new (P) A[5]) {}"); + parse("X::X() : var(new (P) A[5][10]) {}"); + parse("X::X() : var(new (P) A[B]) {}"); + parse("X::X() : var(new (P) A[B][C][D]) {}"); - parse("X::X( ) : var( new (P) (int) ) {}"); - parse("X::X( ) : var( new (P) (int)(5) ) {}"); - parse("X::X( ) : var( new (P) (int)(B) ) {}"); - parse("X::X( ) : var( new (P) (int)(B,C) ) {}"); - parse("X::X( ) : var( new (P) (int[5]) ) {}"); - parse("X::X( ) : var( new (P) (int[5][10]) ) {}"); - parse("X::X( ) : var( new (P) (int[B]) ) {}"); - parse("X::X( ) : var( new (P) (int[B][C][D]) ) {}"); + parse("X::X() : var(new (P) (int)) {}"); + parse("X::X() : var(new (P) (int)(5)) {}"); + parse("X::X() : var(new (P) (int)(B)) {}"); + parse("X::X() : var(new (P) (int)(B,C)) {}"); + parse("X::X() : var(new (P) (int[5])) {}"); + parse("X::X() : var(new (P) (int[5][10])) {}"); + parse("X::X() : var(new (P) (int[B])) {}"); + parse("X::X() : var(new (P) (int[B][C][D])) {}"); - parse("X::X( ) : var( new (P) (A) ) {}"); - parse("X::X( ) : var( new (P) (A)(5) ) {}"); - parse("X::X( ) : var( new (P) (A)(B) ) {}"); - parse("X::X( ) : var( new (P) (A)(B,C) ) {}"); - parse("X::X( ) : var( new (P) (A[5]) ) {}"); - parse("X::X( ) : var( new (P) (A[5][10]) ) {}"); - parse("X::X( ) : var( new (P) (A[B]) ) {}"); - parse("X::X( ) : var( new (P) (A[B][C][D]) ) {}"); + parse("X::X() : var(new (P) (A)) {}"); + parse("X::X() : var(new (P) (A)(5)) {}"); + parse("X::X() : var(new (P) (A)(B)) {}"); + parse("X::X() : var(new (P) (A)(B,C)) {}"); + parse("X::X() : var(new (P) (A[5])) {}"); + parse("X::X() : var(new (P) (A[5][10])) {}"); + parse("X::X() : var(new (P) (A[B])) {}"); + parse("X::X() : var(new (P) (A[B][C][D])) {}"); } public void testBugSingleton192() throws Exception { @@ -372,7 +363,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug37019() throws Exception { - parse("static const A a( 1, 0 );"); + parse("static const A a(1, 0);"); } public void testBug36766and36769A() throws Exception { @@ -414,7 +405,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug36932A() throws Exception { - parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); + parse("A::A() : var(new char[ (unsigned)bufSize ]) {}"); } // failing, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236856 @@ -529,7 +520,6 @@ public class QuickParser2Tests extends TestCase { } public void testBug36769A() throws Exception { - parse("template cls::operator otherType() const {}\n"); parse("template cls::cls() {}\n"); parse("template cls::~cls() {}\n"); @@ -539,7 +529,6 @@ public class QuickParser2Tests extends TestCase { Writer code = new StringWriter(); code.write("unsigned long a = 0UL;\n"); code.write("unsigned long a2 = 0L; \n"); - parse(code.toString()); } @@ -548,11 +537,11 @@ public class QuickParser2Tests extends TestCase { "class Functor {"+ "template Functor(Fun fun) : spImpl_(new FunctorHandler(fun)){}" + "};" - ); + ); } public void testBug36932() throws Exception { - parse("A::A(): b( new int( 5 ) ), b( new B ), c( new int ) {}"); + parse("A::A(): b(new int(5)), b(new B), c(new int) {}"); } public void testBug36704() throws Exception { @@ -590,8 +579,7 @@ public class QuickParser2Tests extends TestCase { Writer code = new StringWriter(); code.write("void mad_decoder_init(struct mad_decoder *, void *,\n"); code.write(" enum mad_flow (*)(void *, struct mad_stream *),\n"); - code - .write(" enum mad_flow (*)(void *, struct mad_header const *),\n"); + code.write(" enum mad_flow (*)(void *, struct mad_header const *),\n"); code.write(" enum mad_flow (*)(void *,\n"); code.write(" struct mad_stream const *,\n"); code.write(" struct mad_frame *),\n"); @@ -605,16 +593,13 @@ public class QuickParser2Tests extends TestCase { code.write(");\n"); parse(code.toString()); - } public void testBug36852() throws Exception { Writer code = new StringWriter(); - code - .write("int CBT::senseToAllRect( double id_standardQuot = DOSE, double id_minToleranz =15.0,\n"); - code - .write("double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n"); - code.write("unsigned int iui_maxY = HEIGHT );\n"); + code.write("int CBT::senseToAllRect(double id_standardQuot = DOSE, double id_minToleranz =15.0,\n"); + code.write("double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n"); + code.write("unsigned int iui_maxY = HEIGHT);\n"); parse(code.toString()); } @@ -623,14 +608,12 @@ public class QuickParser2Tests extends TestCase { code.write("template\n"); code.write("<\n"); code.write("class AbstractFact,\n"); - code - .write("template class Creator = OpNewFactoryUnit,\n"); + code.write("template class Creator = OpNewFactoryUnit,\n"); code.write("class TList = typename AbstractFact::ProductList\n"); code.write(">\n"); code.write("class ConcreteFactory\n"); code.write(": public GenLinearHierarchy<\n"); - code - .write("typename TL::Reverse::Result, Creator, AbstractFact>\n"); + code.write("typename TL::Reverse::Result, Creator, AbstractFact>\n"); code.write("{\n"); code.write("public:\n"); code.write("typedef typename AbstractFact::ProductList ProductList;\n"); @@ -688,23 +671,23 @@ public class QuickParser2Tests extends TestCase { } /** - * Test code: "class A { int floor( double input ), someInt; };" + * Test code: "class A { int floor(double input), someInt; };" */ public void testMultipleDeclarators() throws Exception { - // Parse and get the translaton unit - parse("class A { int floor( double input ), someInt; };"); + // Parse and get the translation unit + parse("class A { int floor(double input), someInt; };"); } public void testFunctionModifiers() throws Exception { - parse("class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};"); + parse("class A {virtual void foo(void) const throw (yay, nay, we::dont::care) = 0;};"); } public void testArrays() throws Exception { - parse("int x [5][];"); + parse("int x[5][];"); } public void testElaboratedParms() throws Exception { - parse("int x( struct A myA ) { /* junk */ }"); + parse("int x(struct A myA) { /* junk */ }"); } public void testMemberDeclarations() throws Exception { @@ -733,16 +716,16 @@ public class QuickParser2Tests extends TestCase { } public void testASMDefinition() throws Exception { - parse("asm( \"mov ep1 ds2\");"); + parse("asm(\"mov ep1 ds2\");"); } public void testConstructorChain() throws Exception { //TODO - requires CPPVisitor in order to reduce ambiguities - parse("TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}"); + parse("TrafficLight_Actor::TrafficLight_Actor(RTController * rtg_rts, RTActorRef * rtg_ref) : RTActor(rtg_rts, rtg_ref), myId(0) {}"); } public void testBug36237() throws Exception { - parse("A::A():B( (char *)0 ){}"); + parse("A::A():B((char *)0){}"); } public void testBug36532() throws Exception { @@ -760,7 +743,7 @@ public class QuickParser2Tests extends TestCase { } public void testTemplateDeclarationOfFunction() throws Exception { - parse("template A aTemplatedFunction( B bInstance );"); + parse("template A aTemplatedFunction(B bInstance);"); } public void testTemplateDeclarationOfClass() throws Exception { @@ -779,15 +762,15 @@ public class QuickParser2Tests extends TestCase { } public void testBug36250() throws Exception { - parse("int f( int = 0 );"); + parse("int f(int = 0);"); } public void testBug36240() throws Exception { - parse("A & A::operator=( A ){}"); + parse("A & A::operator=(A){}"); } public void testBug36254() throws Exception { - parse("unsigned i;\nvoid f( unsigned p1 = 0 );"); + parse("unsigned i;\nvoid f(unsigned p1 = 0);"); } public void testBug36432() throws Exception { @@ -868,8 +851,7 @@ public class QuickParser2Tests extends TestCase { public void testBug36692() throws Exception { Writer code = new StringWriter(); code.write("template \n"); - code - .write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); + code.write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); code.write("Destroyer d = Private::Deleter::Delete){}\n"); parse(code.toString()); } @@ -888,7 +870,7 @@ public class QuickParser2Tests extends TestCase { // code.write("INLINE_DEF int f ();\n"); // code.write("INLINE_DEF A g ();"); // code.write("INLINE_DEF A * h ();"); -// code.write("INLINE_DEF A & unlock( void );"); +// code.write("INLINE_DEF A & unlock(void);"); // code.write("};"); // parse(code.toString()); // } @@ -911,7 +893,7 @@ public class QuickParser2Tests extends TestCase { public void testPointersToFunctions() throws Exception { Writer code = new StringWriter(); - code.write("void (*name)( void );\n"); + code.write("void (*name)(void);\n"); code .write("static void * (* const orig_malloc_hook)(const char *file, int line, size_t size);\n"); @@ -924,8 +906,8 @@ public class QuickParser2Tests extends TestCase { public void testBug36713() throws Exception { Writer code = new StringWriter(); - code.write("A ( * const fPtr) (void *); \n"); - code.write("A (* const fPtr2) ( A * ); \n"); + code.write("A (* const fPtr) (void *); \n"); + code.write("A (* const fPtr2) (A *); \n"); parse(code.toString()); } @@ -935,7 +917,7 @@ public class QuickParser2Tests extends TestCase { // { // // Parse and get the translaton unit // Writer code = new StringWriter(); - // code.write("bool myFunction( parm1, parm2, parm3 )\n"); + // code.write("bool myFunction(parm1, parm2, parm3)\n"); // code.write("const char* parm1;\n"); // code.write("int (*parm2)(float);\n"); // code.write("{}"); @@ -946,82 +928,82 @@ public class QuickParser2Tests extends TestCase { // assertEquals(1, declarations.size()); // SimpleDeclaration simpleDeclaration = // (SimpleDeclaration)declarations.get(0); - // assertEquals( simpleDeclaration.getDeclSpecifier().getType(), - // DeclSpecifier.t_bool ); + // assertEquals(simpleDeclaration.getDeclSpecifier().getType(), + // DeclSpecifier.t_bool); // List declarators = simpleDeclaration.getDeclarators(); - // assertEquals( 1, declarators.size() ); - // Declarator functionDeclarator = (Declarator)declarators.get( 0 ); - // assertEquals( functionDeclarator.getName().toString(), "myFunction" ); + // assertEquals(1, declarators.size()); + // Declarator functionDeclarator = (Declarator)declarators.get(0); + // assertEquals(functionDeclarator.getName().toString(), "myFunction"); // // ParameterDeclarationClause pdc = functionDeclarator.getParms(); - // assertNotNull( pdc ); + // assertNotNull(pdc); // List parameterDecls = pdc.getDeclarations(); - // assertEquals( 3, parameterDecls.size() ); - // ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 - // ); - // assertNotNull( parm1.getDeclSpecifier().getName() ); - // assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() ); + // assertEquals(3, parameterDecls.size()); + // ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get(0 + //); + // assertNotNull(parm1.getDeclSpecifier().getName()); + // assertEquals("parm1", parm1.getDeclSpecifier().getName().toString()); // List parm1Decls = parm1.getDeclarators(); - // assertEquals( 1, parm1Decls.size() ); + // assertEquals(1, parm1Decls.size()); // - // ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 - // ); - // assertNotNull( parm2.getDeclSpecifier().getName() ); - // assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); + // ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get(1 + //); + // assertNotNull(parm2.getDeclSpecifier().getName()); + // assertEquals("parm2", parm2.getDeclSpecifier().getName().toString()); // List parm2Decls = parm2.getDeclarators(); - // assertEquals( 1, parm2Decls.size() ); + // assertEquals(1, parm2Decls.size()); // - // ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 - // ); - // assertNotNull( parm3.getDeclSpecifier().getName() ); - // assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); + // ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get(2 + //); + // assertNotNull(parm3.getDeclSpecifier().getName()); + // assertEquals("parm3", parm3.getDeclSpecifier().getName().toString()); // List parm3Decls = parm3.getDeclarators(); - // assertEquals( 1, parm3Decls.size() ); + // assertEquals(1, parm3Decls.size()); // // OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); - // assertNotNull( clause ); - // assertEquals( clause.getDeclarations().size(), 2 ); + // assertNotNull(clause); + // assertEquals(clause.getDeclarations().size(), 2); // SimpleDeclaration decl1 = // (SimpleDeclaration)clause.getDeclarations().get(0); - // assertEquals( decl1.getDeclarators().size(), 1 ); + // assertEquals(decl1.getDeclarators().size(), 1); // assertTrue(decl1.getDeclSpecifier().isConst()); // assertFalse(decl1.getDeclSpecifier().isVolatile()); - // assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); - // Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); - // assertEquals( declarator1.getName().toString(), "parm1" ); + // assertEquals(decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); + // Declarator declarator1 = (Declarator)decl1.getDeclarators().get(0); + // assertEquals(declarator1.getName().toString(), "parm1"); // List ptrOps1 = declarator1.getPointerOperators(); - // assertNotNull( ptrOps1 ); - // assertEquals( 1, ptrOps1.size() ); + // assertNotNull(ptrOps1); + // assertEquals(1, ptrOps1.size()); // PointerOperator po1 = (PointerOperator)ptrOps1.get(0); - // assertNotNull( po1 ); - // assertFalse( po1.isConst() ); - // assertFalse( po1.isVolatile() ); - // assertEquals( po1.getType(), PointerOperator.t_pointer ); + // assertNotNull(po1); + // assertFalse(po1.isConst()); + // assertFalse(po1.isVolatile()); + // assertEquals(po1.getType(), PointerOperator.t_pointer); // // SimpleDeclaration declaration = // (SimpleDeclaration)clause.getDeclarations().get(1); - // assertEquals( declaration.getDeclSpecifier().getType(), - // DeclSpecifier.t_int ); - // assertEquals( declaration.getDeclarators().size(), 1); - // assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() - // ); + // assertEquals(declaration.getDeclSpecifier().getType(), + // DeclSpecifier.t_int); + // assertEquals(declaration.getDeclarators().size(), 1); + // assertNull(((Declarator)declaration.getDeclarators().get(0)).getName() + //); // assertNotNull( - // ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); + // ((Declarator)declaration.getDeclarators().get(0)).getDeclarator()); // assertEquals( // ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), - // "parm2" ); + // "parm2"); // ParameterDeclarationClause clause2 = // ((Declarator)declaration.getDeclarators().get(0)).getParms(); - // assertEquals( clause2.getDeclarations().size(), 1 ); + // assertEquals(clause2.getDeclarations().size(), 1); // assertEquals( // ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), - // 1 ); + // 1); // assertNull( // ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() - // ); + //); // assertEquals( // ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), - // DeclSpecifier.t_float ); + // DeclSpecifier.t_float); // } public void testPointersToMemberFunctions() throws Exception { @@ -1038,10 +1020,8 @@ public class QuickParser2Tests extends TestCase { code.write("%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */\n"); code.write("#ifndef glue\n"); code.write("#error glue not defined!\n"); - code.write("#endif\n"); - + code.write("#endif\n"); code.write("%:define str(x) %:x /* #define str(x) #x */\n"); - code.write("int main (int argc, char *argv<::>) /* argv[] */\n"); code.write("glue (<, %) /* { */\n"); code.write(" /* di_str[] = */\n"); @@ -1063,17 +1043,14 @@ public class QuickParser2Tests extends TestCase { code.write("??=include \n"); code.write("??=define TWELVE 1??/\n"); code.write("2\n"); - code.write("static const char str??(??) = \"0123456789??/n\";\n"); - code.write("int\n"); code.write("main(void)\n"); code.write("??<\n"); code.write(" unsigned char x = 5;\n"); code.write(" if (sizeof str != TWELVE)\n"); code.write(" abort ();\n"); - code - .write(" /* Test ^=, the only multi-character token to come from trigraphs. */\n"); + code.write(" /* Test ^=, the only multi-character token to come from trigraphs. */\n"); code.write(" x ??'= 3;\n"); code.write(" if (x != 6)\n"); code.write(" abort ();\n"); @@ -1098,7 +1075,7 @@ public class QuickParser2Tests extends TestCase { } public void testIndirectDeclarators() throws Exception { - parse("void (*x)( int );"); + parse("void (*x)(int);"); } public void testBug39532() throws Exception { @@ -1143,7 +1120,7 @@ public class QuickParser2Tests extends TestCase { code.write("template struct SuperSubclass {\n"); code.write("enum { value = (::Loki::Conversion::exists && \n"); code.write("!::Loki::Conversion::sameType) }; };"); - } catch (IOException ioe) { + } catch (IOException e) { } parse(code.toString()); } @@ -1210,7 +1187,7 @@ public class QuickParser2Tests extends TestCase { code.write(" catch (...)\n"); code.write(" { if (c != 3) r |= 1; }\n"); code.write("};\n"); - } catch (IOException ioe) { + } catch (IOException e) { } parse(code.toString()); } @@ -1266,64 +1243,64 @@ public class QuickParser2Tests extends TestCase { } public void testBug43110() throws Exception { - parse("void x( int y, ... );"); + parse("void x(int y, ...);"); } // public void testBug44370() throws Exception // { - // parse( "#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); + // parse("#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); // Iterator macros = quickParseCallback.getMacros(); // assertNotNull(macros); - // assertTrue( macros.hasNext()); + // assertTrue(macros.hasNext()); // IASTMacro swap = (IASTMacro) macros.next(); - // assertFalse( macros.hasNext() ); - // assertEquals( swap.getName(), "SWAP"); - // assertEquals( swap.getMacroType(), - // IMacroDescriptor.MacroType.FUNCTION_LIKE ); - // String [] params = swap.getParameters(); - // assertEquals( params.length, 2 ); - // assertEquals( params[0], "x"); - // assertEquals( params[1], "y"); + // assertFalse(macros.hasNext()); + // assertEquals(swap.getName(), "SWAP"); + // assertEquals(swap.getMacroType(), + // IMacroDescriptor.MacroType.FUNCTION_LIKE); + // String[] params = swap.getParameters(); + // assertEquals(params.length, 2); + // assertEquals(params[0], "x"); + // assertEquals(params[1], "y"); // String completeSignature = swap.getCompleteSignature().trim(); - // assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); + // assertEquals(completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); // - // assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); + // assertEquals(swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); // - // IToken [] tokens = swap.getTokenizedExpansion(); - // validateToken( tokens[0], IToken.tLBRACE); - // validateIdentifier( tokens[1], "x"); - // validateToken( tokens[2], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[3], "y"); - // validateToken( tokens[4], IToken.tSEMI ); - // validateIdentifier( tokens[5], "y"); - // validateToken( tokens[6], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[7], "x"); - // validateToken( tokens[8], IToken.tSEMI ); - // validateIdentifier( tokens[9], "x"); - // validateToken( tokens[10], IToken.tBITORASSIGN ); - // validateIdentifier( tokens[11], "y"); - // validateToken( tokens[12], IToken.tSEMI ); - // validateToken( tokens[13], IToken.tRBRACE ); + // IToken[] tokens = swap.getTokenizedExpansion(); + // validateToken(tokens[0], IToken.tLBRACE); + // validateIdentifier(tokens[1], "x"); + // validateToken(tokens[2], IToken.tBITORASSIGN); + // validateIdentifier(tokens[3], "y"); + // validateToken(tokens[4], IToken.tSEMI); + // validateIdentifier(tokens[5], "y"); + // validateToken(tokens[6], IToken.tBITORASSIGN); + // validateIdentifier(tokens[7], "x"); + // validateToken(tokens[8], IToken.tSEMI); + // validateIdentifier(tokens[9], "x"); + // validateToken(tokens[10], IToken.tBITORASSIGN); + // validateIdentifier(tokens[11], "y"); + // validateToken(tokens[12], IToken.tSEMI); + // validateToken(tokens[13], IToken.tRBRACE); // } // /** // * @param token // * @param string // */ - // private void validateIdentifier(IToken token, String identifierName ) { - // validateToken( token, IToken.tIDENTIFIER); - // assertEquals( token.getImage(), identifierName ); + // private void validateIdentifier(IToken token, String identifierName) { + // validateToken(token, IToken.tIDENTIFIER); + // assertEquals(token.getImage(), identifierName); // } // /** // * @param token // * @param i // */ // private void validateToken(IToken token, int signal) { - // assertEquals( token.getType(), signal ); + // assertEquals(token.getType(), signal); // } public void testBug47752() throws Exception { //TODO requires CPPVisitor - parse("void func( cFoo bar ) try { } catch ( const char * error ){ }"); + parse("void func(cFoo bar) try { } catch (const char * error){ }"); } public void testBug47628() throws Exception { @@ -1354,15 +1331,8 @@ public class QuickParser2Tests extends TestCase { parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, ParserLanguage.C, true); } - /** - * @param string - * @param b - * @param c - * @param d - */ protected void parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - FileContent codeReader = FileContent.create("", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); @@ -1373,8 +1343,7 @@ public class QuickParser2Tests extends TestCase { config = new GPPParserExtensionConfiguration(); else config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, - NULL_LOG, config); + parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, NULL_LOG, config); } else { ICParserExtensionConfiguration config = null; if (gcc) @@ -1382,23 +1351,18 @@ public class QuickParser2Tests extends TestCase { else config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE, - NULL_LOG, config); + parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE, NULL_LOG, config); } IASTTranslationUnit tu = parser2.parse(); if (parser2.encounteredError() && expectedToPass) throw new ParserException("FAILURE"); - if (expectedToPass) - { - if( lang == ParserLanguage.C ) - { - IASTProblem [] problems = CVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); - } - else if ( lang == ParserLanguage.CPP ) - { - IASTProblem [] problems = CPPVisitor.getProblems(tu); - assertEquals( problems.length, 0 ); + if (expectedToPass) { + if (lang == ParserLanguage.C) { + IASTProblem[] problems = CVisitor.getProblems(tu); + assertEquals(problems.length, 0); + } else if (lang == ParserLanguage.CPP) { + IASTProblem[] problems = CPPVisitor.getProblems(tu); + assertEquals(problems.length, 0); } } } @@ -1409,8 +1373,7 @@ public class QuickParser2Tests extends TestCase { public void testBug61431() throws Exception { for (int i = 0; i < 2; ++i) { - ParserLanguage language = (i == 0) ? ParserLanguage.C - : ParserLanguage.CPP; + ParserLanguage language = (i == 0) ? ParserLanguage.C : ParserLanguage.CPP; parse("int k[][] = { {0, {1}, {2,3}};", false, language); } } @@ -1458,14 +1421,14 @@ public class QuickParser2Tests extends TestCase { StringWriter writer = new StringWriter(); writer.write("#define __declspec(x) __attribute__((x))"); writer.write("__declspec (dllimport) int foo;"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug39704D() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define __declspec(x) __attribute__((x))"); writer.write("__declspec(dllexport) int func1 (int a) {}"); - parse( writer.toString() ); + parse(writer.toString()); } public void testBug39695() throws Exception { @@ -1510,8 +1473,7 @@ public class QuickParser2Tests extends TestCase { Writer code = new StringWriter(); code.write("__complex__ double x; // complex double\n"); code.write("__complex__ short int a; // complex short int\n"); - code - .write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); + code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); code.write("double v = __real__ x; // real part of expression\n"); code.write("double w = __imag__ x; // imaginary part of expression\n"); @@ -1532,7 +1494,7 @@ public class QuickParser2Tests extends TestCase { public void testBug39677() throws Exception { parse("B::B() : a(({ 1; })) {}", true, ParserLanguage.CPP, true); Writer writer = new StringWriter(); - writer.write("B::B() : a(( { int y = foo (); int z;\n"); + writer.write("B::B() : a(({ int y = foo (); int z;\n"); writer.write("if (y > 0) z = y;\n"); writer.write("else z = - y;\n"); writer.write("z; })) {}\n"); @@ -1562,5 +1524,4 @@ public class QuickParser2Tests extends TestCase { public void testBug39701C() throws Exception { parse("static template class Foo;", true, ParserLanguage.CPP, true); } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java index 760aedb62bc..e4d259c68bc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java @@ -90,7 +90,7 @@ public class SemanticsTests extends AST2BaseTest { // Test getDeclaredConversionOperators() BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ICPPClassType c= ba.assertNonProblem("X {", 1, ICPPClassType.class); - ICPPMethod[] cops= SemanticUtil.getDeclaredConversionOperators(c); + ICPPMethod[] cops= SemanticUtil.getDeclaredConversionOperators(c, null); assertEquals(2, cops.length); Set actual= new HashSet(); actual.add(cops[0].getName()); actual.add(cops[1].getName()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java index c050753140b..ceca33d73f1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/InclusionTests.java @@ -278,4 +278,31 @@ public class InclusionTests extends PreprocessorTestsBase { validateInteger("1"); validateEOF(); } + + // #include "test.h" + public void testSuppressingUseOfCurrentFileDirectory() throws Exception { + String content= getAboveComment(); + + importFolder("f1"); + IFolder inc = importFolder("f1/inc"); + importFile("f1/test.h", "1"); + importFile("f1/inc/test.h", "2"); + IFile base = importFile("f1/base.cpp", getAboveComment()); + + String[] path = {inc.getLocation().toFile().toString()}; + IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null); + FileContent reader= FileContent.create(base); + initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo); + + validateInteger("1"); + validateEOF(); + + path = new String[] {inc.getLocation().toFile().toString(), "-"}; // Suppress use of current file directory + scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null); + reader= FileContent.create(base); + initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo); + + validateInteger("2"); + validateEOF(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 64cb7063c1f..3a0308f3be5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Symbian Software Systems and others. + * Copyright (c) 2006, 2012 Symbian Software Systems 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 @@ -20,6 +20,7 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; @@ -59,30 +60,31 @@ import org.osgi.framework.Bundle; * is backed by the PDOM), it must be possible to resolve which binding a name * in the AST is referring to. If the binding is not defined in the AST fragment * then it is assumed to have come from a file which is already indexed. - * + * * This class is for testing the process by which bindings are looked up in * the PDOM purely from AST information (i.e. without a real binding from the DOM) */ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { private static final boolean DEBUG= false; + private static final int INDEXER_TIMEOUT_SEC = 300; protected ITestStrategy strategy; - + public void setStrategy(ITestStrategy strategy) { this.strategy = strategy; } - + @Override protected void setUp() throws Exception { super.setUp(); strategy.setUp(); } - + @Override protected void tearDown() throws Exception { strategy.tearDown(); super.tearDown(); } - + protected IASTName findName(String section, int len) { if (len == 0) len= section.length(); @@ -97,10 +99,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { return name; } } - + return null; } - + /** * Attempts to get an IBinding from the initial specified number of characters * from the specified code fragment. Fails the test if @@ -122,25 +124,25 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { IASTName name= findName(section, len); assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); - + IBinding binding = name.resolveBinding(); assertNotNull("No binding for " + name.getRawSignature(), binding); assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); assertInstance(binding, clazz, cs); return clazz.cast(binding); } - + /* * @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int) */ protected T getBindingFromASTName(String section, int len) { if (len <= 0) len += section.length(); - + IASTName name= findName(section, len); assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); - + IBinding binding = name.resolveBinding(); assertNotNull("No binding for " + name.getRawSignature(), binding); assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); @@ -157,17 +159,17 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { IASTName name= findName(section, len); assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); - + IBinding binding = name.resolveBinding(); assertNotNull("No binding for " + name.getRawSignature(), binding); assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); return name.resolveBinding(); } - + protected static void assertQNEquals(String expectedQN, IBinding b) { assertInstance(b, IBinding.class); if (b instanceof ICPPBinding) { - assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding)b)); + assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding) b)); } else { assertEquals(expectedQN, b.getName()); } @@ -175,7 +177,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { protected IType getVariableType(IBinding binding) throws DOMException { assertTrue(binding instanceof IVariable); - return ((IVariable)binding).getType(); + return ((IVariable) binding).getType(); } protected IType getPtrType(IBinding binding) throws DOMException { @@ -195,8 +197,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { // assert function is IFunctionType IFunctionType ft = (IFunctionType) function; assertTrue(ICPPClassType.class.isInstance((ft.getParameterTypes()[index]))); - assertEquals(compositeTypeKey, ((ICPPClassType)ft.getParameterTypes()[index]).getKey()); - assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType)ft.getParameterTypes()[index])); + assertEquals(compositeTypeKey, ((ICPPClassType) ft.getParameterTypes()[index]).getKey()); + assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType) ft.getParameterTypes()[index])); } protected static T assertInstance(Object o, Class clazz, Class ... cs) { @@ -207,7 +209,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { } return clazz.cast(o); } - + protected String readTaggedComment(final String tag) throws IOException { return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag); } @@ -216,6 +218,63 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { return strategy.getIndex(); } + protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) { + assertInstance(b, IVariable.class); + IVariable variable = (IVariable) b; + assertQNEquals(qn, variable); + assertInstance(variable.getType(), expType); + if (expTypeQN != null) { + IType type= variable.getType(); + assertInstance(type, IBinding.class); + assertQNEquals(expTypeQN, (IBinding) type); + } + } + + protected static void assertTypeContainer(IType conType, String expQN, Class containerType, Class expContainedType, String expContainedTypeQN) { + assertInstance(conType, ITypeContainer.class); + assertInstance(conType, containerType); + IType containedType= ((ITypeContainer) conType).getType(); + assertInstance(containedType, expContainedType); + if (expContainedTypeQN != null) { + assertInstance(containedType, IBinding.class); + assertQNEquals(expContainedTypeQN, (IBinding) containedType); + } + } + + final protected void checkBindings() throws Exception { + for (int i = 0; i < strategy.getAstCount(); i++) { + IASTTranslationUnit ast = strategy.getAst(i); + CNameCollector col = new CNameCollector(); + ast.accept(col); + for (IASTName n : col.nameList) { + assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding); + } + } + } + + static protected class CNameCollector extends ASTVisitor { + { + shouldVisitNames = true; + } + public List nameList = new ArrayList(); + + @Override + public int visit(IASTName name) { + nameList.add(name); + return PROCESS_CONTINUE; + } + + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) + return null; + return nameList.get(idx); + } + + public int size() { + return nameList.size(); + } + } + interface ITestStrategy { IIndex getIndex(); void setUp() throws Exception; @@ -227,30 +286,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public ICProject getCProject(); public boolean isCompositeIndex(); } - - protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) { - assertInstance(b, IVariable.class); - IVariable variable = (IVariable) b; - assertQNEquals(qn, variable); - assertInstance(variable.getType(), expType); - if (expTypeQN != null) { - IType type= variable.getType(); - assertInstance(type, IBinding.class); - assertQNEquals(expTypeQN, (IBinding) type); - } - } - - protected static void assertTypeContainer(IType conType, String expQN, Class containerType, Class expContainedType, String expContainedTypeQN) { - assertInstance(conType, ITypeContainer.class); - assertInstance(conType, containerType); - IType containedType= ((ITypeContainer)conType).getType(); - assertInstance(containedType, expContainedType); - if (expContainedTypeQN != null) { - assertInstance(containedType, IBinding.class); - assertQNEquals(expContainedTypeQN, (IBinding) containedType); - } - } - + class SinglePDOMTestFirstASTStrategy implements ITestStrategy { private IIndex index; private ICProject cproject; @@ -266,7 +302,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public ICProject getCProject() { return cproject; } - + @Override public StringBuilder[] getTestData() { return testData; @@ -293,8 +329,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { @Override public void setUp() throws Exception { - cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject = cpp ? + CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b = CTestPlugin.getDefault().getBundle(); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); @@ -302,11 +339,11 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { return; IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), testData[0].toString()); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); if (DEBUG) { System.out.println("Project PDOM: " + getName()); - ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); + ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -330,7 +367,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public IIndex getIndex() { return index; } - + @Override public boolean isCompositeIndex() { return false; @@ -379,21 +416,22 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { @Override public void setUp() throws Exception { - cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject = cpp ? + CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b = CTestPlugin.getDefault().getBundle(); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), testData[0].toString()); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString()); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); + if (DEBUG) { System.out.println("Project PDOM: " + getName()); - ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); + ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } index= CCorePlugin.getIndexManager().getIndex(cproject); @@ -416,7 +454,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public IIndex getIndex() { return index; } - + @Override public boolean isCompositeIndex() { return false; @@ -472,8 +510,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { @Override public void setUp() throws Exception { - cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject = cpp ? + CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b = CTestPlugin.getDefault().getBundle(); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0); @@ -498,8 +537,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { } } CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); + if (DEBUG) { System.out.println("Project PDOM: " + getName()); ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); @@ -527,7 +566,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public IIndex getIndex() { return index; } - + @Override public boolean isCompositeIndex() { return false; @@ -549,7 +588,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public ICProject getCProject() { return cproject; } - + @Override public void tearDown() throws Exception { if (index != null) { @@ -565,8 +604,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { @Override public void setUp() throws Exception { - cproject= cpp ? CProjectHelper.createCCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject= cpp ? + CProjectHelper.createCCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject("OnlineContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b= CTestPlugin.getDefault().getBundle(); testData= TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); referenced = createReferencedContent(); @@ -581,11 +621,11 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().reindex(cproject); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); + if (DEBUG) { System.out.println("Online: "+getName()); - ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); + ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } index= CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES); @@ -594,21 +634,22 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { } protected ICProject createReferencedContent() throws CoreException { - ICProject referenced = cpp ? CProjectHelper.createCCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + ICProject referenced = cpp ? + CProjectHelper.createCCProject("ReferencedContent" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject("ReferencedContent" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); String content = testData[0].toString(); IFile file = TestSourceReader.createFile(referenced.getProject(), new Path("header.h"), content); - + IndexerPreferences.set(referenced.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().reindex(referenced); - - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - + + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, new NullProgressMonitor())); + if (DEBUG) { System.out.println("Referenced: "+getName()); - ((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter()); + ((PDOM) CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter()); } - + return referenced; } @@ -640,7 +681,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { public StringBuilder[] getTestData() { return testData; } - + @Override public boolean isCompositeIndex() { return true; @@ -650,7 +691,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { /** * When a test is failing only for the strategy where the test data is split over * multiple index fragments, we artificially fail the single fragment strategy also. - * This is not ideal, but as both strategies behavior are typically the same, is + * This is not ideal, but as both strategies behavior are typically the same, is * quite rare. */ protected void fakeFailForSingle() { @@ -662,7 +703,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { /** * When a test is failing only for the strategy where the test data is not split over * multiple index fragments, we artificially fail the single fragment strategy also. - * This is not ideal, but as both strategies behavior are typically the same, is + * This is not ideal, but as both strategies behavior are typically the same, is * quite rare. */ protected void fakeFailForMultiProject() { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index a0f00014261..e4d0bdfdb64 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -108,7 +108,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; public class IndexBugsTests extends BaseTestCase { - private static final int INDEX_WAIT_TIME = 800000; //XXX + private static final int INDEXER_TIMEOUT_SEC = 20; private ICProject fCProject; protected IIndex fIndex; @@ -305,13 +305,13 @@ public class IndexBugsTests extends BaseTestCase { private void waitForIndexer() throws InterruptedException { final IIndexManager indexManager = CCorePlugin.getIndexManager(); - assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, npm())); + assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm())); long waitms= 1; while (waitms < 2000 && indexManager.isIndexerSetupPostponed(fCProject)) { Thread.sleep(waitms); waitms *= 2; } - assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, npm())); + assertTrue(indexManager.joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm())); } protected Pattern[] getPattern(String qname) { @@ -385,7 +385,7 @@ public class IndexBugsTests extends BaseTestCase { String[] content= getContentsForTest(2); IFile file= createFile(getProject(), "header.h", content[0]); - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject); index.acquireReadLock(); @@ -399,7 +399,7 @@ public class IndexBugsTests extends BaseTestCase { } file= createFile(getProject(), "header.h", content[1]); - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); index= CCorePlugin.getIndexManager().getIndex(fCProject); index.acquireReadLock(); @@ -425,10 +425,10 @@ public class IndexBugsTests extends BaseTestCase { content.append("unsigned int arrayDataSize = sizeof(arrayData);\n"); int indexOfDecl = content.indexOf(varName); - assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, npm())); + assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm())); IFile file= createFile(getProject(), fileName, content.toString()); // must be done in a reasonable amount of time - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { IIndexBinding[] bindings= fIndex.findBindings(getPattern("arrayDataSize"), true, IndexFilter.ALL, npm()); @@ -451,7 +451,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test156671.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -469,7 +469,7 @@ public class IndexBugsTests extends BaseTestCase { TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()}; TestScannerProvider.sIncludeFiles= new String[]{include.getName()}; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_1.cpp", ""); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -493,7 +493,7 @@ public class IndexBugsTests extends BaseTestCase { TestScannerProvider.sIncludes= new String[]{include.getLocation().removeLastSegments(1).toString()}; TestScannerProvider.sMacroFiles= new String[]{include.getName()}; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test160281_2.cpp", "int X;"); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -528,7 +528,7 @@ public class IndexBugsTests extends BaseTestCase { int indexOfDecl = content.indexOf(funcName); int indexOfDef = content.indexOf(funcName, indexOfDecl+1); IFile file= createFile(getProject(), fileName, content); - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); // make sure the ast is correct ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path(fileName)); @@ -569,7 +569,7 @@ public class IndexBugsTests extends BaseTestCase { IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", ""); TestScannerProvider.sIncludeFiles= new String[] { include.getLocation().toOSString() }; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", ""); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -592,7 +592,7 @@ public class IndexBugsTests extends BaseTestCase { IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", ""); TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()}; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", ""); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -618,7 +618,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -655,7 +655,7 @@ public class IndexBugsTests extends BaseTestCase { String[] testData = getContentsForTest(3); IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0]); IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1]); - TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEXER_TIMEOUT_SEC * 1000); index.acquireReadLock(); try { @@ -670,7 +670,7 @@ public class IndexBugsTests extends BaseTestCase { InputStream in = new ByteArrayInputStream(testData[2].getBytes()); header.setContents(in, IResource.FORCE, null); - TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, header, INDEXER_TIMEOUT_SEC * 1000); index.acquireReadLock(); try { @@ -695,7 +695,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.c", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -728,7 +728,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -762,7 +762,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -781,7 +781,7 @@ public class IndexBugsTests extends BaseTestCase { long timestamp= file.getLocalTimeStamp(); content= "int UPDATED20070213;\n" + content.replaceFirst("int", "float"); file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -814,7 +814,7 @@ public class IndexBugsTests extends BaseTestCase { String[] content= getContentsForTest(2); IFile file= createFile(getProject(), "header.h", content[0]); - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); IIndex index= CCorePlugin.getIndexManager().getIndex(fCProject); index.acquireReadLock(); @@ -829,7 +829,7 @@ public class IndexBugsTests extends BaseTestCase { } file= createFile(getProject(), "header.h", content[1]); - waitUntilFileIsIndexed(file, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(file, INDEXER_TIMEOUT_SEC * 1000); index= CCorePlugin.getIndexManager().getIndex(fCProject); index.acquireReadLock(); @@ -971,7 +971,7 @@ public class IndexBugsTests extends BaseTestCase { IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); CProjectHelper.delete(cproject); cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER); @@ -997,7 +997,7 @@ public class IndexBugsTests extends BaseTestCase { IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); // move the project to a random new location File newLocation = CProjectHelper.freshDir(); @@ -1030,7 +1030,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFBWP.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -1063,7 +1063,7 @@ public class IndexBugsTests extends BaseTestCase { String content= getContentsForTest(1)[0]; IFile file= TestSourceReader.createFile(fCProject.getProject(), "testFilterFindBindingsFQCharArray.cpp", content); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEXER_TIMEOUT_SEC * 1000); fIndex.acquireReadLock(); try { @@ -1186,7 +1186,7 @@ public class IndexBugsTests extends BaseTestCase { String[] contents= getContentsForTest(2); final IIndexManager indexManager = CCorePlugin.getIndexManager(); IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]); - waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(f1, INDEXER_TIMEOUT_SEC * 1000); IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]); waitForIndexer(); @@ -1212,7 +1212,7 @@ public class IndexBugsTests extends BaseTestCase { String[] contents= getContentsForTest(2); final IIndexManager indexManager = CCorePlugin.getIndexManager(); IFile f1= TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0]); - waitUntilFileIsIndexed(f1, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(f1, INDEXER_TIMEOUT_SEC * 1000); IFile f2= TestSourceReader.createFile(fCProject.getProject(), "src.cpp", contents[1]); waitForIndexer(); @@ -2303,7 +2303,7 @@ public class IndexBugsTests extends BaseTestCase { } s= TestSourceReader.createFile(src, "source.cpp", "#include \"../h/a.h\""); - waitUntilFileIsIndexed(s, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(s, INDEXER_TIMEOUT_SEC * 1000); index.acquireReadLock(); try { r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null); @@ -2313,7 +2313,7 @@ public class IndexBugsTests extends BaseTestCase { } s= TestSourceReader.createFile(h, "a.h", "int version3;"); - waitUntilFileIsIndexed(s, INDEX_WAIT_TIME); + waitUntilFileIsIndexed(s, INDEXER_TIMEOUT_SEC * 1000); index.acquireReadLock(); try { r = index.findBindings("version2".toCharArray(), IndexFilter.ALL_DECLARED, null); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index bcb559c0bf8..de0b1a2065f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Andrew Ferguson (Symbian) + * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -55,7 +56,8 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.core.runtime.CoreException; @@ -226,10 +228,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(b1, ICPPInstanceCache.class); ICPPInstanceCache ct= (ICPPInstanceCache) b1; - ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateArgument((IType)b0)}); + ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateTypeArgument((IType)b0)}); assertInstance(inst, ICPPClassType.class); ICPPClassType c2t= (ICPPClassType) inst; - ICPPBase[] bases= c2t.getBases(); + ICPPBase[] bases= ClassTypeHelper.getBases(c2t, null); assertEquals(1, bases.length); assertInstance(bases[0].getBaseClass(), ICPPClassType.class); } @@ -998,74 +1000,74 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // class template instance ct= getBindingFromASTName("CT", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template instance ct= getBindingFromASTName("CT", 8); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // class specialization ct= getBindingFromASTName("C spec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // class template specialization ct= getBindingFromASTName("CT spect", 2); assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class); - assertBindings(new String[] {"B"}, ct.getBases()); - assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"g"}, ct.getDeclaredFields()); - assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"f", "g"}, ct.getFields()); - assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"O"}, ct.getNestedClasses()); + assertBindings(new String[] {"B"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"n", "m", "B", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"g"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"n", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"f", "g"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"O"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class specialization ct= getBindingFromASTName("C espec", 1); assertInstance(ct, ICPPClassSpecialization.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "C", "C"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"C", "C", "C"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "C", "C"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "C", "C"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"C", "C", "C"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "C", "C"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); // explicit class template specialization ct= getBindingFromASTName("CT espect", 7); assertInstance(ct, ICPPTemplateInstance.class); - assertBindings(new String[] {"A"}, ct.getBases()); - assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods()); - assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors()); - assertBindings(new String[] {"h"}, ct.getDeclaredFields()); - assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods()); - assertBindings(new String[] {"e", "h"}, ct.getFields()); - assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods()); - assertBindings(new String[] {"P"}, ct.getNestedClasses()); + assertBindings(new String[] {"A"}, ClassTypeHelper.getBases(ct, null)); + assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ClassTypeHelper.getAllDeclaredMethods(ct, null)); + assertBindings(new String[] {"CT", "CT", "CT"}, ClassTypeHelper.getConstructors(ct, null)); + assertBindings(new String[] {"h"}, ClassTypeHelper.getDeclaredFields(ct, null)); + assertBindings(new String[] {"o", "CT", "CT"}, ClassTypeHelper.getDeclaredMethods(ct, null)); + assertBindings(new String[] {"e", "h"}, ClassTypeHelper.getFields(ct, null)); + assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ClassTypeHelper.getMethods(ct, null)); + assertBindings(new String[] {"P"}, ClassTypeHelper.getNestedClasses(ct, null)); } // void func(const int* x) {} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index d49b31b5520..ac479f76372 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -3,20 +3,21 @@ * 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 + * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; + import java.util.ArrayList; import java.util.List; import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; @@ -56,35 +57,36 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.core.runtime.CoreException; - /** * Tests for exercising resolution of template bindings against IIndex */ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBase { + public static class SingleProject extends IndexCPPTemplateResolutionTest { public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} public static TestSuite suite() {return suite(SingleProject.class);} } - + public static class ProjectWithDepProj extends IndexCPPTemplateResolutionTest { public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} public static TestSuite suite() {return suite(ProjectWithDepProj.class);} - + @Override public void testDefaultTemplateArgInHeader_264988() throws Exception { // Not supported across projects (the composite index does not merge // default values of template parameters). } } - - public static void addTests(TestSuite suite) { + + public static void addTests(TestSuite suite) { suite.addTest(SingleProject.suite()); suite.addTest(ProjectWithDepProj.suite()); } @@ -92,7 +94,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public IndexCPPTemplateResolutionTest() { setStrategy(new ReferencedProject(true)); } - + // template // struct Allocator { // typedef _TpAllocator& alloc_reference; @@ -145,7 +147,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(type, IBasicType.class); assertEquals("int", ASTTypeUtil.getType(type)); } - + // template // class Allocator; // @@ -251,17 +253,17 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("C1 c1", 8); IBinding b1= getBindingFromASTName("m1(\"aaa\")", 2); IBinding b2= getBindingFromASTName("m2(\"aaa\")", 2); - + assertEquals(1, getIndex().findNames(b1, IIndex.FIND_REFERENCES).length); assertEquals(1, getIndex().findNames(b2, IIndex.FIND_REFERENCES).length); } - - + + // template // class X { // public: static void foo() {} // }; - + // class A{}; // void bar() { // X::foo(); @@ -270,12 +272,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("foo()", 3); assertInstance(b0, ICPPMethod.class); } - + // template // class StrT { // public: void assign(const T* s) {} // }; - + // #include "header.h" // void main() { // StrT x; @@ -291,7 +293,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // template // class X {}; - + // class A{}; // void bar() { // X xa= new X(); @@ -316,7 +318,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // public: // void m2(T t) {} // }; - + // class A {}; // void foo() { // C1< StrT > c1a; @@ -329,7 +331,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b3= getBindingFromASTName("c1a;", 3); IBinding b4= getBindingFromASTName("m2(*", 2); } - + // class Str1 { // public: // Str1(const char* s) { @@ -366,11 +368,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testUnindexedConstructorInstanceImplicitReference() throws Exception { IBinding b0= getBindingFromASTName("m1(\"aaa\")", 2); IBinding b1= getBindingFromASTName("m2(\"aaa\")", 2); - + assertEquals(1, getIndex().findNames(b0, IIndex.FIND_REFERENCES).length); assertEquals(1, getIndex().findNames(b1, IIndex.FIND_REFERENCES).length); } - + // // Bryan W.'s example from bugzilla#167098 // template // class D { //CPPClassTemplate @@ -395,35 +397,35 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testCPPConstructorTemplateSpecialization() throws Exception { IBinding b0= getBindingFromASTName("D *var", 1); IBinding b1= getBindingFromASTName("D *var", 6); - - assertInstance(b0, ICPPClassTemplate.class); - assertInstance(b0, ICPPClassType.class); + + assertInstance(b0, ICPPClassTemplate.class); + assertInstance(b0, ICPPClassType.class); assertInstance(b1, ICPPTemplateInstance.class); - assertInstance(b1, ICPPClassType.class); - + assertInstance(b1, ICPPClassType.class); + // ICPPClassType _ct= (ICPPClassType) b1; // ICPPConstructor[] _ctcs= _ct.getConstructors(); // assertEquals(3, _ctcs.length); // two implicit plus the constructor template - + IBinding b2= getBindingFromASTName("D(", 1); IBinding b3= getBindingFromASTName("D(", 6); - + assertInstance(b2, ICPPClassTemplate.class); // *D*(5, 6) assertInstance(b2, ICPPClassType.class); // *D*(5, 6) assertInstance(b3, ICPPTemplateInstance.class); // *D*(5, 6) assertInstance(b3, ICPPConstructor.class); // *D*(5, 6) - - // + + // // ICPPClassType ct= (ICPPClassType) b2; // ICPPConstructor[] ctcs= ct.getConstructors(); // assertEquals(3, ctcs.length); // two implicit plus the constructor template - + IBinding tidSpc= ((ICPPTemplateInstance)b3).getSpecializedBinding(); assertInstance(tidSpc, ICPPConstructor.class); assertInstance(tidSpc, ICPPSpecialization.class); assertInstance(tidSpc, ICPPFunctionTemplate.class); } - + // class B {}; // // template @@ -444,7 +446,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b0, ICPPFunction.class); assertInstance(b0, ICPPSpecialization.class); } - + // template class S> // class Foo { // public: @@ -457,7 +459,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // // class A {}; - + // void qux() { // Foo f; // f.s.foo(*new A()); @@ -468,22 +470,22 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b2= getBindingFromASTName("f.s.foo", 1); IBinding b3= getBindingFromASTName("s.foo", 1); IBinding b4= getBindingFromASTName("foo(*", 3); - + assertInstance(b0, ICPPClassTemplate.class); assertInstance(b0, ICPPClassType.class); ICPPTemplateParameter[] ps= ((ICPPClassTemplate)b0).getTemplateParameters(); assertEquals(2, ps.length); assertInstance(ps[0], ICPPTemplateTypeParameter.class); assertInstance(ps[1], ICPPTemplateTemplateParameter.class); - + assertInstance(b1, ICPPTemplateInstance.class); assertInstance(b1, ICPPClassType.class); - + IType[] type= ((ICPPTemplateInstance)b1).getArguments(); assertInstance(type[0], ICPPClassType.class); assertInstance(type[1], ICPPClassTemplate.class); assertInstance(type[1], ICPPClassType.class); - + ObjectMap om= ((ICPPTemplateInstance)b1).getArgumentMap(); assertEquals(2, om.size()); assertInstance(om.keyAt(0), ICPPTemplateTypeParameter.class); @@ -491,14 +493,14 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(om.keyAt(1), ICPPTemplateTemplateParameter.class); assertInstance(om.getAt(1), ICPPClassType.class); assertInstance(om.getAt(1), ICPPClassTemplate.class); - + IBinding b1_spcd= ((ICPPTemplateInstance)b1).getSpecializedBinding(); assertInstance(b1_spcd, ICPPClassTemplate.class); assertInstance(b1_spcd, ICPPClassType.class); assertTrue(((IType)b1_spcd).isSameType((IType)b0)); } - - + + // template // class Foo { // public: @@ -516,7 +518,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // // class AA {}; // class BB {}; - // + // // class Z : public Foo {}; // // X x; @@ -528,7 +530,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa getBindingFromASTName("Y y;", 1), getBindingFromASTName("Z z;", 1) }; - + for (IBinding b : bs) { assertInstance(b, ICPPClassType.class); ICPPClassType c= (ICPPClassType) b; @@ -565,10 +567,10 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // class A {}; class B {}; class C {}; // template // class D {}; - // + // // template // class D {}; - + // #include "header.h" // template class D; // harmless declaration for test purposes // template class D {}; @@ -578,20 +580,20 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b1= getBindingFromASTName("D", 8); IBinding b2= getBindingFromASTName("D", 8); IBinding b3= getBindingFromASTName("D // class A {}; - // + // // template // class B : public A { // public: @@ -615,7 +617,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // // B bb; // make sure the instance is in the pdom - + // template // class X : public B {}; // @@ -629,27 +631,27 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b2, ICPPClassType.class); assertInstance(b2, ICPPTemplateInstance.class); ICPPClassType ct2= (ICPPClassType) b2; - ICPPBase[] bss2= ct2.getBases(); + ICPPBase[] bss2= ClassTypeHelper.getBases(ct2, null); assertEquals(1, bss2.length); assertInstance(bss2[0].getBaseClass(), ICPPClassType.class); ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass(); assertInstance(ct2b, ICPPTemplateInstance.class); - + IBinding b0= getBindingFromASTName("B", 6); assertInstance(b0, ICPPClassType.class); ICPPClassType ct= (ICPPClassType) b0; - ICPPBase[] bss= ct.getBases(); + ICPPBase[] bss= ClassTypeHelper.getBases(ct, null); assertEquals(1, bss.length); - assertInstance(bss[0].getBaseClass(), ICPPClassType.class); - + assertInstance(bss[0].getBaseClass(), ICPPClassType.class); + IBinding b1= getBindingFromASTName("B", 7); assertInstance(b1, ICPPClassType.class); ICPPClassType ct1= (ICPPClassType) b1; - ICPPBase[] bss1= ct1.getBases(); + ICPPBase[] bss1= ClassTypeHelper.getBases(ct1, null); assertEquals(1, bss1.length); assertInstance(bss1[0].getBaseClass(), ICPPClassType.class); } - + // class B {}; // // template @@ -666,48 +668,48 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // B foo(B t) { B x= *new B(); return x; } // void bar(B t, int& x) { x++; } // }; - + // A ab; public void testClassSpecializationMethods() throws Exception { IBinding b0= getBindingFromASTName("A ab", 4); assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPSpecialization.class); - + ICPPClassType ct= (ICPPClassType) b0; - ICPPMethod[] dms= ct.getDeclaredMethods(); + ICPPMethod[] dms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(2, dms.length); // if the specialization was used, we have 2 fields. - ICPPField[] fs= ct.getDeclaredFields(); + ICPPField[] fs= ClassTypeHelper.getDeclaredFields(ct, null); assertEquals(2, fs.length); ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1]; ICPPMethod bar= dms[0].getName().equals("bar") ? dms[0] : dms[1]; - + assertEquals(foo.getName(), "foo"); assertEquals(bar.getName(), "bar"); - + assertInstance(foo.getType().getReturnType(), ICPPClassType.class); assertEquals(((ICPPClassType)foo.getType().getReturnType()).getName(), "B"); assertEquals(foo.getType().getParameterTypes().length, 1); assertInstance(foo.getType().getParameterTypes()[0], ICPPClassType.class); assertEquals(((ICPPClassType)foo.getType().getParameterTypes()[0]).getName(), "B"); - + assertInstance(bar.getType().getReturnType(), ICPPBasicType.class); assertEquals(((ICPPBasicType)bar.getType().getReturnType()).getType(), IBasicType.t_void); } - + // template class A { // public: // typedef T TD; // }; - // + // // class B {}; // A::TD foo; - + // class C {}; // A::TD bar; - // + // // void qux() { // A::TD foo2= foo; // A::TD bar2= bar; @@ -777,20 +779,20 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b7= getBindingFromASTName("foo(", 3); IBinding b8= getBindingFromASTName("foo(", 3); } - + // class A {}; class B{}; class C {}; // // template - // void foo(T1 t1, T2 t2) {} // (0) + // void foo(T1 t1, T2 t2) {} // (0) // // template<> // void foo(C c, A a) {} // (1) - + // void bar() { // A a; // B b; // C c; - // foo(a,b); // function instance of function template (0) + // foo(a,b); // function instance of function template (0) // foo(c,a); // function specialization (1) // } public void testFunctionInstanceSpecializationsParameters() throws Exception { @@ -805,25 +807,25 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b0_ptypes[1], ICPPClassType.class); assertEquals("A", ((ICPPClassType)b0_ptypes[0]).getName()); assertEquals("B", ((ICPPClassType)b0_ptypes[1]).getName()); - + IParameter[] b0_pms= ((ICPPFunction)b0).getParameters(); assertEquals(2, b0_pms.length); assertInstance(b0_pms[0].getType(), ICPPClassType.class); assertInstance(b0_pms[1].getType(), ICPPClassType.class); assertEquals("A", ((ICPPClassType)b0_pms[0].getType()).getName()); assertEquals("B", ((ICPPClassType)b0_pms[1].getType()).getName()); - + IBinding b0_spcd= ((ICPPTemplateInstance)b0).getSpecializedBinding(); assertInstance(b0_spcd, ICPPFunction.class); assertInstance(b0_spcd, ICPPTemplateDefinition.class); - + IParameter[] b0_spcd_pms= ((ICPPFunction)b0_spcd).getParameters(); assertEquals(2, b0_spcd_pms.length); assertInstance(b0_spcd_pms[0].getType(), ICPPTemplateTypeParameter.class); assertInstance(b0_spcd_pms[1].getType(), ICPPTemplateTypeParameter.class); assertEquals("T1", ((ICPPTemplateTypeParameter)b0_spcd_pms[0].getType()).getName()); assertEquals("T2", ((ICPPTemplateTypeParameter)b0_spcd_pms[1].getType()).getName()); - + ObjectMap b0_am= ((ICPPSpecialization)b0).getArgumentMap(); assertEquals(2, b0_am.size()); assertInstance(b0_am.getAt(0), ICPPClassType.class); @@ -834,7 +836,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertEquals("T2", ((ICPPTemplateTypeParameter)b0_am.keyAt(1)).getName()); assertEquals("A", ((ICPPClassType)b0_am.getAt(0)).getName()); assertEquals("B", ((ICPPClassType)b0_am.getAt(1)).getName()); - + ICPPFunctionType b0_spcd_type= ((ICPPFunction)b0_spcd).getType(); assertInstance(b0_spcd_type.getReturnType(), ICPPBasicType.class); IType[] b0_spcd_ptypes= b0_spcd_type.getParameterTypes(); @@ -843,7 +845,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b0_spcd_ptypes[1], ICPPTemplateTypeParameter.class); assertEquals("T1", ((ICPPTemplateTypeParameter)b0_spcd_ptypes[0]).getName()); assertEquals("T2", ((ICPPTemplateTypeParameter)b0_spcd_ptypes[1]).getName()); - + IBinding b1= getBindingFromASTName("foo(c,a)", 3); assertInstance(b1, ICPPFunction.class); ICPPFunctionType b1type= ((ICPPFunction)b1).getType(); @@ -854,20 +856,20 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b1_ptypes[1], ICPPClassType.class); assertEquals("C", ((ICPPClassType)b1_ptypes[0]).getName()); assertEquals("A", ((ICPPClassType)b1_ptypes[1]).getName()); - + IParameter[] b1_pms= ((ICPPFunction)b1).getParameters(); assertEquals(2, b1_pms.length); assertInstance(b1_pms[0].getType(), ICPPClassType.class); assertInstance(b1_pms[1].getType(), ICPPClassType.class); assertEquals("C", ((ICPPClassType)b1_pms[0].getType()).getName()); assertEquals("A", ((ICPPClassType)b1_pms[1].getType()).getName()); - + assertInstance(b1, ICPPSpecialization.class); ICPPSpecialization b1s= (ICPPSpecialization) b1; IBinding b1_spcd= b1s.getSpecializedBinding(); assertInstance(b1_spcd, ICPPFunction.class); assertInstance(b1_spcd, ICPPTemplateDefinition.class); - + ICPPFunctionType b1_spcd_type= ((ICPPFunction)b1_spcd).getType(); assertInstance(b1_spcd_type.getReturnType(), ICPPBasicType.class); IType[] b1_spcd_ptypes= b1_spcd_type.getParameterTypes(); @@ -876,14 +878,14 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b1_spcd_ptypes[1], ICPPTemplateTypeParameter.class); assertEquals("T1", ((ICPPTemplateTypeParameter)b1_spcd_ptypes[0]).getName()); assertEquals("T2", ((ICPPTemplateTypeParameter)b1_spcd_ptypes[1]).getName()); - + IParameter[] b1_spcd_pms= ((ICPPFunction)b1_spcd).getParameters(); assertEquals(2, b1_spcd_pms.length); assertInstance(b1_spcd_pms[0].getType(), ICPPTemplateTypeParameter.class); assertInstance(b1_spcd_pms[1].getType(), ICPPTemplateTypeParameter.class); assertEquals("T1", ((ICPPTemplateTypeParameter)b1_spcd_pms[0].getType()).getName()); assertEquals("T2", ((ICPPTemplateTypeParameter)b1_spcd_pms[1].getType()).getName()); - + ObjectMap b1_am= b1s.getArgumentMap(); assertEquals(2, b1_am.size()); assertInstance(b1_am.keyAt(0), ICPPTemplateTypeParameter.class); @@ -895,12 +897,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertEquals("C", ((ICPPClassType)b1_am.getAt(0)).getName()); assertEquals("A", ((ICPPClassType)b1_am.getAt(1)).getName()); } - + // class A {}; // // template // void foo(T t) {} - + // void bar() { // A a; // foo(a); @@ -909,17 +911,17 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("foo(a)", 3); assertInstance(b0, ICPPTemplateInstance.class); assertInstance(b0, ICPPFunction.class); - + ICPPFunction f= (ICPPFunction) b0; ICPPFunctionType type= f.getType(); IType rt= type.getReturnType(); IType[] pts= type.getParameterTypes(); - + IParameter[] ps= f.getParameters(); assertEquals(1, ps.length); ICPPParameter param= (ICPPParameter) ps[0]; assertInstance(param, ICPPSpecialization.class); - + IType paramType= param.getType(); assertInstance(paramType, ICPPClassType.class); ICPPParameter paramSpec= (ICPPParameter) ((ICPPSpecialization) param).getSpecializedBinding(); @@ -927,13 +929,13 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPTemplateTypeParameter ttp= (ICPPTemplateTypeParameter) paramSpec.getType(); assertEquals("T", ttp.getName()); assertNull(ttp.getDefault()); - + ICPPTemplateInstance inst= (ICPPTemplateInstance) b0; IBinding sp= inst.getSpecializedBinding(); assertInstance(sp, ICPPFunction.class); assertInstance(sp, ICPPTemplateDefinition.class); } - + // template // void func(T1* obj, R (T2::*member)()) { // } @@ -941,7 +943,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // struct A { // void m(); // }; - + // void test() { // A a; // func(&a, &A::m); @@ -958,7 +960,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // template // void func(U& u, const typename U::t& v) { // } - + // template class A { // typedef T t; // }; @@ -978,10 +980,10 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // // class B {}; // - // template<> + // template<> // class Foo {}; - - // Foo b1; + + // Foo b1; // // class A {}; // @@ -992,10 +994,10 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testClassSpecializations_180738() { IBinding b1a = getBindingFromASTName("Foo b1;", 3); IBinding b1b = getBindingFromASTName("Foo b1;", 6); - + assertInstance(b1a, ICPPClassType.class); assertInstance(b1a, ICPPClassTemplate.class); - + assertInstance(b1b, ICPPClassType.class); assertInstance(b1b, ICPPSpecialization.class); ICPPSpecialization b1spc= (ICPPSpecialization) b1b; @@ -1004,13 +1006,13 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(b1om.getAt(0), ICPPClassType.class); ICPPClassType b1pct= (ICPPClassType) b1om.getAt(0); assertEquals("B", b1pct.getName()); - + IBinding b2a = getBindingFromASTName("Foo b2;", 3); IBinding b2b = getBindingFromASTName("Foo b2;", 6); - + assertInstance(b2a, ICPPClassType.class); assertInstance(b2a, ICPPClassTemplate.class); - + assertInstance(b2b, ICPPClassType.class); assertInstance(b2b, ICPPSpecialization.class); ICPPSpecialization b2spc= (ICPPSpecialization) b2b; @@ -1020,7 +1022,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType b2pct= (ICPPClassType) b2om.getAt(0); assertEquals("B", b2pct.getName()); } - + // // header file // template // T left(T a, T b) { @@ -1028,7 +1030,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // } // void sanity() {} // int d; - + // void foo() { sanity(); } // class Int {}; // Int a,b; @@ -1043,11 +1045,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b5 = getBindingFromASTName("left(a,b)", 4); IBinding b6 = getBindingFromASTName("left(a,b)", 4); } - + // class A {}; // template class D {}; // template class D {}; - + // D daa; public void testClassPartialSpecializations_199572() throws Exception { IBinding b0= getBindingFromASTName("D", 6); @@ -1085,7 +1087,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertEquals("int", ASTTypeUtil.getType(type)); } - // class A {}; class B {}; class X {}; + // class A {}; class B {}; class X {}; // template // class C { // public: @@ -1102,7 +1104,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // X t; // operator B() {B b; return b;} // }; - + // class F : public C {}; // void refs() { // C c; @@ -1120,29 +1122,29 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding ca= getBindingFromASTName("C", 4); assertInstance(ca, ICPPClassType.class); assertInstance(ca, ICPPTemplateInstance.class); - + IBinding foo1= getBindingFromASTName("foo(c)", 3); - + IBinding da= getBindingFromASTName("D", 4); assertInstance(da, ICPPClassType.class); assertInstance(da, ICPPTemplateInstance.class); - + IBinding foo2= getBindingFromASTName("foo(d)", 3); IBinding foo3= getBindingFromASTName("foo(e)", 3); IBinding foo4= getBindingFromASTName("foo(cx)", 3); - + assertEquals(foo1, foo2); assertEquals(foo2, foo3); assertEquals(foo3, foo4); } - + // template // class A {}; // // class B {}; - // + // // template<> // class A {}; - + // class C {}; // // A ab; @@ -1150,15 +1152,15 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testEnclosingScopes_a() throws Exception { ICPPSpecialization b0= getBindingFromASTName("A", 4, ICPPSpecialization.class, ICPPClassType.class); ICPPTemplateInstance b1= getBindingFromASTName("A", 4, ICPPTemplateInstance.class, ICPPClassType.class); - + ICPPClassType sc0= assertInstance(b0.getSpecializedBinding(), ICPPClassType.class); ICPPClassType sc1= assertInstance(b1.getSpecializedBinding(), ICPPClassType.class); assertTrue(sc0.isSameType(sc1)); - + assertNull(sc0.getScope()); assertNull(b0.getScope()); } - + // template // class A { // public: @@ -1172,7 +1174,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // public: // class B {}; // }; - + // #include "header.h" // void refs() { // A::B acb; @@ -1182,7 +1184,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType b0= getBindingFromASTName("B acb", 1, ICPPClassType.class); ICPPClassType b1= getBindingFromASTName("B adb", 1, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType b2= getBindingFromASTName("A", 4, ICPPClassType.class, ICPPSpecialization.class); - + IIndexBinding[] sr = getIndex().findBindings("A".toCharArray(), new IndexFilter() { @Override public boolean acceptBinding(IBinding binding) throws CoreException { @@ -1191,7 +1193,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa }, npm()); assertTrue(sr.length == 1); ICPPClassType b3= (ICPPClassType) sr[0]; - + sr = getIndex().findBindings(new char[][] {"A".toCharArray(), "B".toCharArray()}, new IndexFilter() { @Override public boolean acceptBinding(IBinding binding) throws CoreException { @@ -1200,21 +1202,21 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa }, npm()); assertTrue(sr.length == 1); ICPPClassType b4= (ICPPClassType) sr[0]; - + assertFalse(b0 instanceof ICPPSpecialization); - + IIndexScope s0= (IIndexScope) b0.getScope(), s4= (IIndexScope) b4.getScope(); IScope s1= b1.getScope(); - + assertTrue(((IType)s0.getScopeBinding()).isSameType((IType)((IIndexScope)b2.getCompositeScope()).getScopeBinding())); ICPPClassScope cs1= assertInstance(s1, ICPPClassScope.class); assertInstance(cs1.getClassType(), ICPPClassType.class); assertInstance(cs1.getClassType(), ICPPTemplateInstance.class); assertTrue(((IType)((ICPPClassSpecialization) s4.getScopeBinding()).getSpecializedBinding()).isSameType( (IType) ((IIndexScope)b3.getCompositeScope()).getScopeBinding() )); } - + // class A {}; - // + // // template // class X { // public: @@ -1223,23 +1225,23 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // class Z {}; // }; // }; - + // X::Y::Z xayz; public void testEnclosingScopes_c() throws Exception { ICPPClassType b0= getBindingFromASTName("Y::Z x", 1, ICPPClassType.class); ICPPClassType b1= getBindingFromASTName("Z xayz", 1, ICPPClassType.class); - + IScope s0= b0.getScope(), s1= b1.getScope(); - + ICPPClassScope cs0= assertInstance(s0, ICPPClassScope.class); assertInstance(cs0.getClassType(), ICPPClassType.class); assertInstance(cs0.getClassType(), ICPPSpecialization.class); - + ICPPClassScope cs1= assertInstance(s1, ICPPClassScope.class); assertInstance(cs1.getClassType(), ICPPClassType.class); - assertInstance(cs1.getClassType(), ICPPSpecialization.class); + assertInstance(cs1.getClassType(), ICPPSpecialization.class); } - + // class A {}; class B {}; // // template @@ -1250,21 +1252,21 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // public: // class N {}; // }; - + // X::N n; public void testEnclosingScopes_d() throws Exception { ICPPClassType b0= getBindingFromASTName("N n", 1, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType b1= assertInstance(((ICPPSpecialization) b0).getSpecializedBinding(), ICPPClassType.class); - + ICPPClassScope s0= assertInstance(b0.getScope(), ICPPClassScope.class); assertInstance(s0.getClassType(), ICPPTemplateInstance.class); - + ICPPClassScope s1= assertInstance(b1.getScope(), ICPPClassScope.class); assertInstance(s1.getClassType(), ICPPTemplateDefinition.class); - + assertNull(s1.getClassType().getScope()); } - + // typedef signed int SI; // // template @@ -1280,16 +1282,16 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(args.keyAt(0), ICPPTemplateNonTypeParameter.class); assertEquals(1, args.size()); } - - // template class A { - // class B { T t; }; - // B b; - // }; - - // void f() { - // A a; - // a.b.t; - // } + + // template class A { + // class B { T t; }; + // B b; + // }; + + // void f() { + // A a; + // a.b.t; + // } public void testNestedClassTypeSpecializations() throws Exception { ICPPField t2 = getBindingFromASTName("t;", 1, ICPPField.class); @@ -1298,7 +1300,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertTrue(type instanceof IBasicType); assertEquals(((IBasicType)type).getType(), IBasicType.t_int); } - + // template struct iterator_traits { // typedef typename _Iterator::pointer pointer; // }; @@ -1310,7 +1312,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // template class normal_iterator { // protected: // _Iterator _M_current; - // + // // public: // typedef typename iterator_traits<_Iterator>::pointer pointer; // normal_iterator() : _M_current(_Iterator()) { } @@ -1347,12 +1349,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPField t2 = getBindingFromASTName("member; // it->member", 6, ICPPField.class); ICPPClassType ct= t2.getClassOwner(); assertEquals("MyStruct", ct.getName()); - + final IType type = t2.getType(); assertTrue(type instanceof IBasicType); assertEquals(((IBasicType)type).getType(), IBasicType.t_int); } - + // template // class C { // public: @@ -1366,7 +1368,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // void foo(aRef& aRefence) {} // void bar(C<_256>& aRefence) {} // void baz(void) {} - + // int main (void) { // C<256> t; // foo(t); @@ -1375,22 +1377,22 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // } public void testClassInstanceWithNonTypeArgument_207871() throws Exception { ICPPTemplateInstance c256 = getBindingFromASTName("C<256>", 6, ICPPTemplateInstance.class, ICPPClassType.class); - ObjectMap args= c256.getArgumentMap(); - assertEquals(1, args.size()); - assertInstance(args.keyAt(0), ICPPTemplateNonTypeParameter.class); - ICPPBasicType bt= assertInstance(args.getAt(0), ICPPBasicType.class); - IASTExpression val= bt.getValue(); - + ICPPTemplateParameterMap paramMap = c256.getTemplateParameterMap(); + assertEquals(1, paramMap.getAllParameterPositions().length); + ICPPTemplateArgument arg = paramMap.getArgument(0); + assertEquals(Long.valueOf(256), arg.getNonTypeValue().numericalValue()); + assertInstance(arg.getTypeOfNonTypeValue(), ICPPBasicType.class); + ICPPFunction foo = getBindingFromASTName("foo(t)", 3, ICPPFunction.class); ICPPFunction bar = getBindingFromASTName("bar(t)", 3, ICPPFunction.class); } - + // template class A {public: class X {};}; // template class A {public: class Y {};}; // template class A {public: class Z {};}; // // class B {}; - + // A::X x; // A::Y y; // A::Z z; @@ -1398,25 +1400,25 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType b2= getBindingFromASTName("A", 9, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b3= getBindingFromASTName("A", 9, ICPPClassType.class, ICPPTemplateInstance.class); ICPPClassType b4= getBindingFromASTName("A", 9, ICPPClassType.class, ICPPTemplateInstance.class); - + assertTrue(!b2.isSameType(b3)); assertTrue(!b3.isSameType(b4)); assertTrue(!b4.isSameType(b2)); - + ICPPClassType X= getBindingFromASTName("X x", 1, ICPPClassType.class); ICPPClassType Y= getBindingFromASTName("Y y", 1, ICPPClassType.class); ICPPClassType Z= getBindingFromASTName("Z z", 1, ICPPClassType.class); - + assertTrue(!X.isSameType(Y)); assertTrue(!Y.isSameType(Z)); assertTrue(!Z.isSameType(X)); } - + // template class A {public: class X {};}; // template class A {public: class Y {};}; // // class B {}; - + // A::X x; //1 // A::Y y; //2 // @@ -1427,10 +1429,10 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType Y= getBindingFromASTName("Y y; //2", 1, ICPPClassType.class); getProblemFromASTName("X x; //3", 1); getProblemFromASTName("Y y; //4", 1); - + assertTrue(!X.isSameType(Y)); } - + // template class A {}; // template<> class A<5> {public: class B{};}; // @@ -1451,18 +1453,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType a5c= getBindingFromASTName("A", 7, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType a5d= getBindingFromASTName("A<5>", 4, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType a1= getBindingFromASTName("A<1>", 4, ICPPClassType.class, ICPPTemplateInstance.class); - + assertTrue(a5a.isSameType(a5b)); assertTrue(a5b.isSameType(a5c)); assertTrue(a5c.isSameType(a5d)); assertTrue(a5d.isSameType(a5a)); - + assertTrue(!a1.isSameType(a5a)); assertTrue(!a1.isSameType(a5b)); assertTrue(!a1.isSameType(a5c)); assertTrue(!a1.isSameType(a5d)); } - + // template // class That { // public: @@ -1474,7 +1476,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // public: // inline This(); // }; - + // template // inline This::This() : That(I) { // } @@ -1487,12 +1489,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPConstructor th1sCtor= ba.assertNonProblem("This() :", 4, ICPPConstructor.class); assertFalse(th1sCtor instanceof ICPPSpecialization);ICPPTemplateNonTypeParameter np= ba.assertNonProblem("I)", 1, ICPPTemplateNonTypeParameter.class); */ - + ICPPTemplateNonTypeParameter np= getBindingFromASTName("I>(I)", 1, ICPPTemplateNonTypeParameter.class); ICPPConstructor clazz= getBindingFromASTName("That(I)", 4, ICPPConstructor.class); ICPPConstructor ctor= getBindingFromASTName("That(I)", 7, ICPPConstructor.class); } - + // template // class That { // public: @@ -1504,7 +1506,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // public: // inline This(); // }; - + // template // inline This::This() : That() { // } @@ -1513,59 +1515,59 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertFalse(tid instanceof ICPPSpecialization); ICPPConstructor th1sCtor= getBindingFromASTName("This() :", 4, ICPPConstructor.class); assertFalse(th1sCtor instanceof ICPPSpecialization); - + ICPPTemplateTypeParameter np= getBindingFromASTName("I>()", 1, ICPPTemplateTypeParameter.class); ICPPConstructor clazz= getBindingFromASTName("That()", 4, ICPPConstructor.class); ICPPConstructor ctor= getBindingFromASTName("That()", 7, ICPPConstructor.class); } - - + + // template class CT { // public: int field; // }; - + // CT v1; public void testUniqueSpecializations_Bug241641() throws Exception { ICPPVariable v1= getBindingFromASTName("v1", 2, ICPPVariable.class); ICPPVariable v2= getBindingFromASTName("v1", 2, ICPPVariable.class); - + IType t1= v1.getType(); assertInstance(t1, ICPPClassType.class); - + ICPPClassType ct= (ICPPClassType) t1; IBinding f1= ct.getCompositeScope().find("field")[0]; IBinding f2= ct.getCompositeScope().find("field")[0]; - + assertSame(f1, f2); } - + // template class CT { // public: int field; // }; - + // CT v1; public void testUniqueInstance_Bug241641() throws Exception { IASTName name= findName("v1", 2); ICPPVariable v1= getBindingFromASTName("v1", 2, ICPPVariable.class); - + IType t1= v1.getType(); assertInstance(t1, ICPPTemplateInstance.class); - + ICPPTemplateInstance inst= (ICPPTemplateInstance) t1; final ICPPClassTemplate tmplDef = (ICPPClassTemplate) inst.getTemplateDefinition(); IBinding inst2= CPPTemplates.instantiate(tmplDef, inst.getTemplateArguments(), name); assertSame(inst, inst2); - - IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))}, name); - IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))}, name); + + IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateTypeArgument(new CPPBasicType(Kind.eChar, 0))}, name); + IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateTypeArgument(new CPPBasicType(Kind.eChar, 0))}, name); assertSame(charInst1, charInst2); } - + // template class XT { // public: void method() {}; // }; // XT x; - + // void test() { // x.method(); // } @@ -1574,26 +1576,26 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(m, ICPPSpecialization.class); ICPPClassType ct= m.getClassOwner(); assertInstance(ct, ICPPTemplateInstance.class); - ICPPMethod[] ms= ct.getDeclaredMethods(); + ICPPMethod[] ms= ClassTypeHelper.getDeclaredMethods(ct, null); assertEquals(1, ms.length); assertEquals(m, ms[0]); } - - // template class A {}; - // template class A { - // void foo(T t); - // }; - // template void A::foo(T t) {} + // template class A {}; + // template class A { + // void foo(T t); + // }; + + // template void A::foo(T t) {} public void testBug177418() throws Exception { ICPPMethod m= getBindingFromASTName("foo", 3, ICPPMethod.class); ICPPClassType owner= m.getClassOwner(); assertInstance(owner, ICPPClassTemplatePartialSpecialization.class); } - - + + // template class XT { - // int f; + // int f; // void m(); // }; @@ -1603,26 +1605,26 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // this->m(); // 2 // this->f; // 2 // }; - public void testUnknownBindings_Bug264988() throws Exception { + public void testUnknownBindings_Bug264988() throws Exception { ICPPMethod m= getBindingFromASTName("m(); // 1", 1, ICPPMethod.class); assertFalse(m instanceof ICPPUnknownBinding); m= getBindingFromASTName("m(); // 2", 1, ICPPMethod.class); assertFalse(m instanceof ICPPUnknownBinding); - + ICPPField f= getBindingFromASTName("f; // 1", 1, ICPPField.class); assertFalse(f instanceof ICPPUnknownBinding); f= getBindingFromASTName("f; // 2", 1, ICPPField.class); assertFalse(f instanceof ICPPUnknownBinding); } - + // template class XT; - + // #include "header.h" // template class XT {}; // void test() { // XT<> x; // }; - public void testDefaultTemplateArgInHeader_264988() throws Exception { + public void testDefaultTemplateArgInHeader_264988() throws Exception { ICPPTemplateInstance ti= getBindingFromASTName("XT<>", 4, ICPPTemplateInstance.class); } @@ -1630,11 +1632,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // template class XT { // void m(); // }; - + // template<> void XT::m() { // TInt t; // } - public void testParentScopeOfSpecialization_267013() throws Exception { + public void testParentScopeOfSpecialization_267013() throws Exception { ITypedef ti= getBindingFromASTName("TInt", 4, ITypedef.class); } @@ -1704,10 +1706,10 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // vector v; // f(v.begin()); // } - public void testTemplateMetaprogramming_284686() throws Exception { + public void testTemplateMetaprogramming_284686() throws Exception { getBindingFromASTName("f(v.begin())", 1, ICPPFunction.class); } - + // template class op { // public: // inline static int DO(T key, T key2) { @@ -1723,11 +1725,11 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // Noder1 f; // Noder2 g; // } - public void testInstantiationOfValue_284683() throws Exception { + public void testInstantiationOfValue_284683() throws Exception { getBindingFromASTName("Noder1", 11, ICPPClassSpecialization.class); getBindingFromASTName("Noder2", 11, ICPPClassSpecialization.class); } - + // template struct CT; // template struct CT { @@ -1739,9 +1741,9 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // void test() { // CT p; - // p.f.x; + // p.f.x; // } - public void testTemplateParameterWithoutName_300978() throws Exception { + public void testTemplateParameterWithoutName_300978() throws Exception { getBindingFromASTName("x;", 1, ICPPField.class); ICPPClassSpecialization ctx = getBindingFromASTName("CT", 5, ICPPClassSpecialization.class); ICPPClassTemplate ct= (ICPPClassTemplate) ctx.getSpecializedBinding(); @@ -1761,13 +1763,13 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // f(1); // g(1); // } - public void testExplicitSpecializations_296427() throws Exception { + public void testExplicitSpecializations_296427() throws Exception { ICPPTemplateInstance inst; inst= getBindingFromASTName("X", 0); assertFalse(inst.isExplicitSpecialization()); inst = getBindingFromASTName("Y", 0); assertTrue(inst.isExplicitSpecialization()); - + inst = getBindingFromASTName("f(1)", 1); assertFalse(inst.isExplicitSpecialization()); inst = getBindingFromASTName("g(1)", 1); @@ -1782,7 +1784,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // void test() { // OutStream out; // out << endl; - // } + // } public void testInstantiationOfEndl_297457() throws Exception { final IBinding reference = getBindingFromASTName("<< endl", 2); assertTrue(reference instanceof ICPPSpecialization); @@ -1817,7 +1819,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // int main() { // A a; - // a.f(0); + // a.f(0); // return 0; // } public void testPartialSpecializationsOfClassTemplateSpecializations_332884() throws Exception { @@ -1836,32 +1838,32 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // struct Nested {}; // }; // struct TXT : XT {}; - + // TXT x; public void testClassSpecialization_Bug354086() throws Exception { ICPPClassType ct= getBindingFromASTName("TXT", 0, ICPPClassType.class); ICPPMethod[] methods = ct.getAllDeclaredMethods(); assertEquals(2, methods.length); - + methods= ct.getConstructors(); assertEquals(2, methods.length); methods= ct.getMethods(); assertEquals(14, methods.length); - - ICPPBase[] bases = ct.getBases(); + + ICPPBase[] bases = ClassTypeHelper.getBases(ct, null); assertEquals(1, bases.length); - + IField field = ct.findField("bfield"); assertNotNull(field); - IField[] fields = ct.getFields(); + IField[] fields = ClassTypeHelper.getFields(ct, null); assertEquals(2, fields.length); - IBinding[] friends = ct.getFriends(); + IBinding[] friends = ClassTypeHelper.getFriends(ct, null); assertEquals(0, friends.length); // not yet supported } - + // struct A { // void f() { } // }; @@ -1875,7 +1877,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // B b; // C c; - + // #include "header.h" // void test() { // b.f(); @@ -1903,7 +1905,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testUsageOfClassTemplateOutsideOfClassBody_357320() throws Exception { getBindingFromASTName("m1", 0, ICPPMethod.class); } - + // template struct foo; // template <> struct foo { // typedef int type; @@ -1931,7 +1933,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public void testSpecializationInIndex_367563b() throws Exception { getBindingFromASTName("type type", 4, ITypedef.class); } - + // template struct remove_const_impl {}; // template struct remove_const_impl { // typedef T type; @@ -1952,4 +1954,84 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class); assertEquals("int", ASTTypeUtil.getType(tdef, true)); } + + // template + // struct integral_constant { + // static constexpr T value = v; + // typedef T value_type; + // typedef integral_constant type; + // }; + // + // typedef integral_constant true_type; + // + // typedef integral_constant false_type; + // + // template + // class helper { + // typedef char one; + // typedef struct { char arr[2]; } two; + // template struct Wrap_type {}; + // template static one test(Wrap_type*); + // template static two test(...); + // public: static const bool value = sizeof(test(0)) == 1; + // }; + // + // template + // struct has_category : integral_constant::value> {}; + // + // template::value> + // struct traits {}; + // + // template + // struct traits { + // typedef typename Iterator::value_type value_type; + // }; + // + // struct tag {}; + + // struct C { + // typedef int value_type; + // typedef tag category; + // }; + // + // template::value_type> + // class A { + // }; + // + // typedef A type; + public void testSFINAE_a() throws Exception { + checkBindings(); + } + + // template struct enable_if { typedef T type; }; + // template struct enable_if {}; + // + // template struct is_int { static const bool value = false; }; + // template <> struct is_int { static const bool value = true; }; + // + // template struct is_double { static const bool value = false; }; + // template <> struct is_double { static const bool value = true; }; + // + // template + // struct A { + // static int get() { return 0; } + // }; + // + // template + // struct A::value>::type> { + // static int get() { return 1; } + // }; + // + // template + // struct A::value>::type> { + // static int get() { return 2; } + // }; + + // void test() { + // A::get(); + // A::get(); + // } + public void testSFINAE_b() throws Exception { + checkBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java index 808169ddf87..e06d3cb350b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; @@ -34,6 +35,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; @@ -237,9 +239,10 @@ public class CPPClassTemplateTests extends PDOMTestBase { ICPPVariable var= (ICPPVariable) bs[0]; assertInstance(var.getType(), ICPPClassType.class); ICPPClassType ct= (ICPPClassType) var.getType(); - assertEquals(1, ct.getFields().length); - assertInstance(ct.getFields()[0].getType(), IPointerType.class); - IPointerType pt= (IPointerType) ct.getFields()[0].getType(); + IField[] fields = ClassTypeHelper.getFields(ct, null); + assertEquals(1, fields.length); + assertInstance(fields[0].getType(), IPointerType.class); + IPointerType pt= (IPointerType) fields[0].getType(); assertInstance(pt.getType(), IFunctionType.class); IFunctionType ft= (IFunctionType) pt.getType(); assertInstance(ft.getReturnType(), ICPPClassType.class); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 5e7b2090906..3e999a48886 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -62,12 +62,19 @@ public class AutomatedIntegrationSuite extends TestSuite { public static Test suite() throws Exception { final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite(); - // Add all success tests + // Add all success tests + + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { suite.addTest(CDescriptorTests.suite()); + } suite.addTest(CDescriptorOldTests.suite()); suite.addTest(IEnvironmentVariableManagerTests.suite()); suite.addTest(ErrorParserTests.suite()); + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { suite.addTest(ParserTestSuite.suite()); + } suite.addTest(AllCoreTests.suite()); suite.addTest(ElementDeltaTests.suite()); suite.addTest(WorkingCopyTests.suite()); @@ -84,9 +91,12 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTest(EFSExtensionTests.suite()); suite.addTest(ByteUtilsTest.suite()); + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // Add in PDOM tests suite.addTest(PDOMTests.suite()); suite.addTest(IndexTests.suite()); + } suite.addTest(RefreshScopeTests.suite()); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index b9767eed4f2..26debd1fd69 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexFile; +import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; @@ -315,18 +316,21 @@ public class TestSourceReader { * @since 4.0 */ public static void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception { + long fileTimestamp = file.getLocalTimeStamp(); + IIndexFileLocation indexFileLocation = IndexLocationFactory.getWorkspaceIFL(file); + long endTime= System.currentTimeMillis() + maxmillis; int timeLeft= maxmillis; while (timeLeft >= 0) { Assert.assertTrue(CCorePlugin.getIndexManager().joinIndexer(timeLeft, new NullProgressMonitor())); index.acquireReadLock(); try { - IIndexFile[] files= index.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file)); - if (files.length > 0 && areAllFilesNotOlderThan(files, file.getLocalTimeStamp())) { + IIndexFile[] files= index.getFiles(ILinkage.CPP_LINKAGE_ID, indexFileLocation); + if (files.length > 0 && areAllFilesNotOlderThan(files, fileTimestamp)) { return; } - files= index.getFiles(ILinkage.C_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(file)); - if (files.length > 0 && areAllFilesNotOlderThan(files, file.getLocalTimeStamp())) { + files= index.getFiles(ILinkage.C_LINKAGE_ID, indexFileLocation); + if (files.length > 0 && areAllFilesNotOlderThan(files, fileTimestamp)) { return; } } finally { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java index 304265ca32c..e7089f419e1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/settings/providers/LanguageSettingsScannerInfoProvider.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICMacroEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages; import org.eclipse.core.resources.IProject; @@ -224,14 +225,21 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider for (ICLanguageSettingEntry entry : entriesPath) { ACPathEntry entryPath = (ACPathEntry)entry; if (entryPath.isValueWorkspacePath()) { - IPath loc = entryPath.getLocation(); - if (loc!=null) { - if (checkBit(entryPath.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) { - // handle frameworks, see IScannerInfo.getIncludePaths() - locations.add(loc.append(FRAMEWORK_HEADERS_INCLUDE).toOSString()); - locations.add(loc.append(FRAMEWORK_PRIVATE_HEADERS_INCLUDE).toOSString()); - } else { - locations.add(loc.toOSString()); + ICLanguageSettingEntry[] entries = new ICLanguageSettingEntry[] {entry}; + if (!entry.isResolved()) { + entries = CDataUtil.resolveEntries(entries, cfgDescription); + } + + for (ICLanguageSettingEntry resolved : entries) { + IPath loc = ((ACPathEntry) resolved).getLocation(); + if (loc != null) { + if (checkBit(resolved.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) { + // handle frameworks, see IScannerInfo.getIncludePaths() + locations.add(loc.append(FRAMEWORK_HEADERS_INCLUDE).toOSString()); + locations.add(loc.append(FRAMEWORK_PRIVATE_HEADERS_INCLUDE).toOSString()); + } else { + locations.add(loc.toOSString()); + } } } } else { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java index 06ecc55e5a2..b7d37b494cd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java @@ -945,6 +945,7 @@ public class ASTStringUtil { // need to add a space to the unary expression if it is a specific operator switch (expression.getOperator()) { case IASTUnaryExpression.op_sizeof: + case ICPPASTUnaryExpression.op_noexcept: case ICPPASTUnaryExpression.op_throw: case ICPPASTUnaryExpression.op_typeid: buffer.append(SPACE); @@ -986,6 +987,8 @@ public class ASTStringUtil { public static char[] getUnaryOperatorString(IASTUnaryExpression ue) { int op = ue.getOperator(); switch (op) { + case IASTUnaryExpression.op_noexcept: + return Keywords.cNOEXCEPT; case IASTUnaryExpression.op_throw: return Keywords.cTHROW; case IASTUnaryExpression.op_typeid: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java index 7be75b33a5f..4754e8f09e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java @@ -48,7 +48,6 @@ import org.eclipse.cdt.internal.core.model.ASTStringUtil; */ @Deprecated public class ASTSignatureUtil { - private static final String COMMA_SPACE = ", "; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String SPACE = " "; //$NON-NLS-1$ @@ -1044,9 +1043,10 @@ public class ASTSignatureUtil { if (!postOperator && !primaryBracketed) buffer.append(getUnaryOperatorString(expression)); - // need to add a space to the unary expression if it is a specific operator + // Need to add a space to the unary expression if it is a specific operator switch (expression.getOperator()) { case IASTUnaryExpression.op_sizeof: + case ICPPASTUnaryExpression.op_noexcept: case ICPPASTUnaryExpression.op_throw: case ICPPASTUnaryExpression.op_typeid: buffer.append(SPACE); @@ -1117,6 +1117,9 @@ public class ASTSignatureUtil { if (ue instanceof ICPPASTUnaryExpression) { switch (op) { + case ICPPASTUnaryExpression.op_noexcept: + opString = Keywords.NOEXCEPT; + break; case ICPPASTUnaryExpression.op_throw: opString = Keywords.THROW; break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java index 4b4634c6251..e6bcf447a89 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Doug Schaefer (IBM) - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -18,7 +18,6 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTForStatement extends IASTStatement { - /** * CONDITION represents the relationship between a * IASTForStatement and its IASTExpression @@ -40,7 +39,8 @@ public interface IASTForStatement extends IASTStatement { * IASTForStatement and its IASTStatement * body. */ - public static final ASTNodeProperty BODY = new ASTNodeProperty("IASTForStatement.BODY - IASTStatement body of IASTForStatement"); //$NON-NLS-1$ + public static final ASTNodeProperty BODY = new ASTNodeProperty( + "IASTForStatement.BODY - IASTStatement body of IASTForStatement"); //$NON-NLS-1$ /** * INITIALIZER represents the relationship between a diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java index af81f5d4580..f2f0e0a4fb5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java @@ -120,7 +120,7 @@ public interface IASTTypeIdExpression extends IASTExpression { * Built-in type trait of g++. * @since 5.3 */ - public static final int op_is_polymorphic=17; + public static final int op_is_polymorphic= 17; /** * Built-in type trait of g++. @@ -128,6 +128,24 @@ public interface IASTTypeIdExpression extends IASTExpression { */ public static final int op_is_union= 18; + /** + * Built-in type trait of g++. + * @since 5.5 + */ + public static final int op_is_literal_type= 19; + + /** + * Built-in type trait of g++. + * @since 5.5 + */ + public static final int op_is_standard_layout= 20; + + /** + * Built-in type trait of g++. + * @since 5.5 + */ + public static final int op_is_trivial= 21; + /** * @deprecated constants should be declared here, to avoid using the same constant in different * interfaces. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java index b17b1667a35..919ac7a9814 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java @@ -106,17 +106,23 @@ public interface IASTUnaryExpression extends IASTExpression { public static final int op_typeof = 14; /** - * for gnu parsers, only. op_alignOf is used for __alignOf( unaryExpression ) type + * For gnu parsers, only. op_alignOf is used for __alignOf( unaryExpression ) type * expressions. */ public static final int op_alignOf = 15; /** - * For c++, only: 'sizeof...(parameterPack)' + * For c++, only: 'sizeof... ( parameterPack )' * @since 5.2 */ public static final int op_sizeofParameterPack = 16; + /** + * For c++, only: noexcept ( expression ) + * @since 5.5 + */ + public static final int op_noexcept = 17; + /** * op_last is made available for subclasses. * @deprecated all constants must be defined in this interface diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java index 2170c807cf1..cae0573c04a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBasicType.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.core.dom.ast; /** * Interface for basic types. - * + * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ @@ -22,10 +22,10 @@ public interface IBasicType extends IType { * @since 5.2 */ enum Kind { - eUnspecified, eVoid, eChar, eWChar, eInt, eFloat, eDouble, eBoolean, eChar16, eChar32, + eUnspecified, eVoid, eChar, eWChar, eInt, eFloat, eDouble, eBoolean, eChar16, eChar32, /** @since 5.4 */ eNullPtr } - + /** * @since 5.2 */ @@ -45,15 +45,15 @@ public interface IBasicType extends IType { /** * @since 5.2 */ - final int IS_COMPLEX = 1 << 4; + final int IS_COMPLEX = 1 << 4; /** * @since 5.2 */ - final int IS_IMAGINARY = 1 << 5; + final int IS_IMAGINARY = 1 << 5; /** * @since 5.2 */ - final int IS_LONG_LONG = 1 << 6; + final int IS_LONG_LONG = 1 << 6; /** @@ -62,13 +62,13 @@ public interface IBasicType extends IType { * @since 5.2 */ Kind getKind(); - + /** * This returns the combination of modifier bits for this type. * @since 5.2 */ int getModifiers(); - + public boolean isSigned(); public boolean isUnsigned(); public boolean isShort(); @@ -84,7 +84,7 @@ public interface IBasicType extends IType { * @since 5.2 */ public boolean isComplex(); - + /** * Is imaginary number? e.g. _Imaginr * @return true if it is an imaginary number, false otherwise @@ -97,13 +97,13 @@ public interface IBasicType extends IType { */ @Deprecated public int getType() throws DOMException; - + /** * @deprecated, types don't have values. */ @Deprecated public IASTExpression getValue() throws DOMException; - + /** * @deprecated, use the type-safe version getKind(), instead. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java index a18e169e89d..7f5d36472d4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IProblemBinding.java @@ -4,7 +4,7 @@ * 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 Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) @@ -13,7 +13,7 @@ package org.eclipse.cdt.core.dom.ast; /** * Interface for problem bindings. - * + * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. */ @@ -22,12 +22,12 @@ public interface IProblemBinding extends IBinding, IScope, IType, ISemanticProbl * Returns the AST node that this problem was created for */ public IASTNode getASTNode(); - + /** - * Returns the file name this problem occurred in, or null if it is unknown. + * Returns the file name this problem occurred in, or {@code null} if it is unknown. */ public String getFileName(); - + /** * Returns the line number for this problem, or -1 if it is unknown. */ @@ -37,10 +37,8 @@ public interface IProblemBinding extends IBinding, IScope, IType, ISemanticProbl * Returns bindings that were considered when resolving the node corresponding * to this problem binding, but rejected for some reason. * @return an array of candidate bindings. - * - * This method is experimental. Clients calling this method should expect - * possible changes. - * @since 5.1 experimental + * + * @since 5.1 */ public IBinding[] getCandidateBindings(); @@ -70,6 +68,4 @@ public interface IProblemBinding extends IBinding, IScope, IType, ISemanticProbl */ @Deprecated public static final int LAST_PROBLEM = 0x00E; - - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java index a713a581698..388ca388670 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 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 @@ -109,8 +109,8 @@ public interface IScope { private final IASTTranslationUnit fTu; private final boolean fLookupPointIsName; private boolean fResolve= true; - private boolean fPrefixLookup= false; - private boolean fIgnorePointOfDeclaration= false; + private boolean fPrefixLookup; + private boolean fIgnorePointOfDeclaration; public ScopeLookupData(IASTName name, boolean resolve, boolean prefixLookup) { if (name == null) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java index 2f8a2f46b99..c1e8b2b8223 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java @@ -7,9 +7,12 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; + /** * Models a value of a variable, enumerator or expression. * @@ -19,27 +22,33 @@ package org.eclipse.cdt.core.dom.ast; */ public interface IValue { /** - * Returns the value as a number, or null if this is not possible. + * Returns the value as a number, or {@code null} if it is not possible. */ Long numericalValue(); - + /** - * Returns an internal representation of the expression that builds up - * the value. It is suitable for instantiating dependent values but may not be - * used for the purpose of displaying values. + * Returns the evaluation object if this value is dependent, or {@code null} otherwise. + * If {@link #numericalValue()} returns {@code null}, {@link #getEvaluation()} returns + * not {@code null} and vice versa. + * @noreference This method is not intended to be referenced by clients. */ - char[] getInternalExpression(); - + ICPPEvaluation getEvaluation(); + /** - * A value may be dependent on template parameters, in which case a list - * of unknown bindings is maintained for later instantiation. - */ - IBinding[] getUnknownBindings(); - - /** - * Returns a signature containing both the internal representation and - * the unknown bindings. The representation is sufficient to distinguish values - * for the purpose of instantiation, it may not be used to display the value. + * Returns a signature uniquely identifying the value. Two values with identical + * signatures are guaranteed to be equal. */ char[] getSignature(); + + /** + * @deprecated Returns an empty character array. + */ + @Deprecated + char[] getInternalExpression(); + + /** + * @deprecated Returns an empty array. + */ + @Deprecated + IBinding[] getUnknownBindings(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTArraySubscriptExpression.java index d0e61fa0ba3..8d7ab479586 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTArraySubscriptExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTArraySubscriptExpression.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 IBM Corporation and others. + * Copyright (c) 2009, 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Mike Kucera (IBM) - Initial API and implementation + * Mike Kucera (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -19,8 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface ICPPASTArraySubscriptExpression extends IASTArraySubscriptExpression, ICPPASTExpression, IASTImplicitNameOwner { - +public interface ICPPASTArraySubscriptExpression + extends IASTArraySubscriptExpression, ICPPASTExpression, IASTImplicitNameOwner { @Override public ICPPASTArraySubscriptExpression copy(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTExpression.java index 1805ce597a1..44f6cc5bd26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTExpression.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -20,5 +19,4 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; * @since 5.5 */ public interface ICPPASTExpression extends IASTExpression, ICPPASTInitializerClause { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java index f2ad2f402e9..d9f1542c734 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java @@ -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 @@ -8,12 +8,15 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.parser.Keywords; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; /** * C++ adds a few things to function declarators. @@ -28,9 +31,19 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato */ public static final IASTTypeId[] NO_EXCEPTION_SPECIFICATION = {}; + /** + * Represents a 'noexcept' specification without an expression. + * @since 5.5 + */ + public static final ICPPASTLiteralExpression NOEXCEPT_DEFAULT = + new CPPASTLiteralExpression(ICPPASTLiteralExpression.lk_true, Keywords.cTRUE); + public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty( "ICPPASTFunctionDeclarator.EXCEPTION_TYPEID [IASTTypeId]"); //$NON-NLS-1$ - /** @since 5.2*/ + /** @since 5.5 */ + public static final ASTNodeProperty NOEXCEPT_EXPRESSION = new ASTNodeProperty( + "ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION [ICPPASTExpression]"); //$NON-NLS-1$ + /** @since 5.2 */ public static final ASTNodeProperty TRAILING_RETURN_TYPE = new ASTNodeProperty( "ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE [IASTTypeId]"); //$NON-NLS-1$ @@ -40,7 +53,7 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato public boolean isConst(); /** - * Set the method to be const or not. + * Sets the method to be const or not. */ public void setConst(boolean value); @@ -50,7 +63,7 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato public boolean isVolatile(); /** - * Set the method to be volatile or not. + * Sets the method to be volatile or not. */ public void setVolatile(boolean value); @@ -72,7 +85,7 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato public boolean isPureVirtual(); /** - * Set this method to be pure virtual. + * Sets this method to be pure virtual. */ public void setPureVirtual(boolean isPureVirtual); @@ -101,6 +114,20 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato */ public void setEmptyExceptionSpecification(); + /** + * Returns the noexcept expression, {@link #NOEXCEPT_DEFAULT} if the noexcept specification + * does not contain an expression, or {@code null} the noexcept specification is not present. + * See C++11 5.4.1. + * @since 5.5 + */ + public ICPPASTExpression getNoexceptExpression(); + + /** + * Sets the noexcept expression. + * @since 5.5 + */ + public void setNoexceptExpression(ICPPASTExpression expression); + /** * Returns the trailing return type as in auto f() -> int , or null. * @since 5.2 @@ -114,8 +141,8 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato public void setTrailingReturnType(IASTTypeId typeId); /** - * Get function scope this node represents. Returns null, if this declarator does not - * declare a function-prototype or function-definition. + * Get function scope this node represents. Returns null, if this declarator + * does not declare a function-prototype or function-definition. */ @Override public ICPPFunctionScope getFunctionScope(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java index 00453b7d61d..1a8dd4c6ace 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPASTFunctionDefinition extends IASTFunctionDefinition { - /** * MEMBER_INITIALIZER is the role of a member initializer in the function definition. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java index 21edb4e56be..a91a814f66d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTInitializerList.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerList; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPASTInitializerList extends IASTInitializerList, ICPPASTInitializerClause, ICPPASTPackExpandable { - @Override ICPPASTInitializerList copy(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java index 6938527c524..fbe1ea328e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassScope.java @@ -1,17 +1,16 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; - /** * Interface for class scopes. * @@ -20,17 +19,15 @@ package org.eclipse.cdt.core.dom.ast.cpp; */ public interface ICPPClassScope extends ICPPScope { /** - * Get the binding for the class this scope is associated with - * + * Returns the binding for the class this scope is associated with. */ ICPPClassType getClassType(); /** * Returns an array of methods that were implicitly added to this class - * scope. These methods may or may not have been explicitly declared in the - * code. The methods that will be implicitly declared are: the default + * scope. These methods may or may not have been explicitly declared in + * the code. The methods that will be implicitly declared are: the default * constructor, copy constructor, copy assignment operator, and destructor - * */ public ICPPMethod[] getImplicitMethods(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java index 0a9d97a11b7..5bef68a2aec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -1,17 +1,19 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IField; /** * Specializations of all sorts of class types. @@ -21,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassType { - @Override ICPPClassType getSpecializedBinding(); @@ -37,4 +38,67 @@ public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassTy * @since 5.5 */ IBinding specializeMember(IBinding binding, IASTNode point); + + /** + * Similar to {@link ICPPClassType#getBases()} but a accepts a starting point for template + * instantiation. + * @since 5.5 + */ + ICPPBase[] getBases(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getConstructors()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPConstructor[] getConstructors(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getDeclaredFields()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPField[] getDeclaredFields(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getAllDeclaredMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getAllDeclaredMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getDeclaredMethods()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPMethod[] getDeclaredMethods(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getFriends()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IBinding[] getFriends(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getFriends()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + IField[] getFields(IASTNode point); + + /** + * Similar to {@link ICPPClassType#getNestedClasses()} but a accepts a starting point + * for template instantiation. + * @since 5.5 + */ + ICPPClassType[] getNestedClasses(IASTNode point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java index 27e0e81beb0..107ce9e6183 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java @@ -6,12 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; - /** * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java index 16bfa987063..1fc4b2daffa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java @@ -25,10 +25,8 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding { public static final int k_class = ICPPASTCompositeTypeSpecifier.k_class; /** - * Returns a list of base class relationships. The list is empty if there + * Returns an array of base class relationships. The returned array is empty if there * are none. - * - * @return List of ICPPBase */ public ICPPBase[] getBases(); @@ -88,18 +86,17 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding { * Returns an array of ICPPConstructor objects representing the constructors * for this class. This list includes both declared and implicit * constructors. - * */ public ICPPConstructor[] getConstructors(); /** - * return an array of bindings for those classes/functions declared as + * Returns an array of bindings for those classes/functions declared as * friends of this class. */ public IBinding[] getFriends(); /** - * return an array of nested classes/structures + * Returns an array of nested classes/structures */ public ICPPClassType[] getNestedClasses(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java new file mode 100644 index 00000000000..1066543e477 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethodSpecialization.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * Specialization of a method. + * @since 5.5 + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ICPPMethodSpecialization extends ICPPSpecialization, ICPPMethod { + /** + * Similar to {@link ICPPFunction#getExceptionSpecification()} but a accepts a starting point + * for template instantiation. + */ + IType[] getExceptionSpecification(IASTNode point); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateArgument.java index 17e08457afa..a4aa4fb9c77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateArgument.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IValue; */ public interface ICPPTemplateArgument { ICPPTemplateArgument[] EMPTY_ARGUMENTS = {}; - + /** * Returns whether this is an integral value, suitable for a template non-type parameter. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index 451c0604a5a..dbeeadf4140 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2004, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: - * IBM - Initial API and implementation - * Ed Swartz (Nokia) - * Anton Leherbauer (Wind River Systems) - * Markus Schorn (Wind River Systems) - * Sergey Prigogin (Google) + * Contributors: + * IBM - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; @@ -27,16 +27,16 @@ import org.eclipse.cdt.core.parser.Keywords; * Configures the preprocessor for c++-sources as accepted by g++. */ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { - - private static final int VERSION_4_3 = version(4,3); + private static final int VERSION_4_3 = version(4, 3); + private static final int VERSION_4_6 = version(4, 6); private static GPPScannerExtensionConfiguration CONFIG= new GPPScannerExtensionConfiguration(); private static GPPScannerExtensionConfiguration CONFIG_4_3= new GPPScannerExtensionConfiguration(VERSION_4_3); + private static GPPScannerExtensionConfiguration CONFIG_4_6= new GPPScannerExtensionConfiguration(VERSION_4_6); private static int version(int major, int minor) { return (major << 16) + minor; } - public static GPPScannerExtensionConfiguration getInstance() { return CONFIG; } @@ -51,6 +51,9 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu int major= Integer.valueOf(definedSymbols.get("__GNUC__")); //$NON-NLS-1$ int minor= Integer.valueOf(definedSymbols.get("__GNUC_MINOR__")); //$NON-NLS-1$ int version= version(major, minor); + if (version >= VERSION_4_6) { + return CONFIG_4_6; + } if (version >= VERSION_4_3) { return CONFIG_4_3; } @@ -94,6 +97,11 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic); addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union); } + if (version >= VERSION_4_6) { + addKeyword(GCCKeywords.cp__is_literal_type, IGCCToken.tTT_is_literal_type); + addKeyword(GCCKeywords.cp__is_standard_layout, IGCCToken.tTT_is_standard_layout); + addKeyword(GCCKeywords.cp__is_trivial, IGCCToken.tTT_is_trivial); + } } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java index 254059fb287..6283e41a767 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/TypeHelper.java @@ -29,7 +29,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; * @since 5.4 */ public class TypeHelper { - // Do not instantiate - all methods are static. private TypeHelper() { } @@ -49,8 +48,8 @@ public class TypeHelper { if (type instanceof ICompositeType) { if (type instanceof ICPPClassType) { ICPPClassType classType = ((ICPPClassType) type); - if (!ClassTypeHelper.hasTrivialCopyCtor(classType) || - !ClassTypeHelper.hasTrivialDestructor(classType)) { + if (!ClassTypeHelper.hasTrivialCopyCtor(classType, ast) || + !ClassTypeHelper.hasTrivialDestructor(classType, ast)) { return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java index f2688361d2e..269a05bb526 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java @@ -1,14 +1,15 @@ /******************************************************************************* - * Copyright (c) 2002, 2011 IBM Corporation and others. + * Copyright (c) 2002, 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Ed Swartz (Nokia) - * Markus Schorn (Wind River Systems) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Ed Swartz (Nokia) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.parser; @@ -23,7 +24,7 @@ public class GCCKeywords { public static final String __ATTRIBUTE__ = "__attribute__"; public static final String __DECLSPEC = "__declspec"; - public static final char [] + public static final char[] cpTYPEOF = TYPEOF.toCharArray(), cp__ALIGNOF__ = __ALIGNOF__.toCharArray(), cp__ATTRIBUTE__ = __ATTRIBUTE__.toCharArray(), @@ -48,7 +49,7 @@ public class GCCKeywords { /** * @since 5.3 */ - public static final char [] + public static final char[] cp__has_nothrow_assign= "__has_nothrow_assign".toCharArray(), cp__has_nothrow_copy= "__has_nothrow_copy".toCharArray(), cp__has_nothrow_constructor= "__has_nothrow_constructor".toCharArray(), @@ -65,4 +66,12 @@ public class GCCKeywords { cp__is_pod= "__is_pod".toCharArray(), cp__is_polymorphic= "__is_polymorphic".toCharArray(), cp__is_union= "__is_union".toCharArray(); + + /** + * @since 5.5 + */ + public static final char[] + cp__is_literal_type= "__is_literal_type".toCharArray(), + cp__is_standard_layout= "__is_standard_layout".toCharArray(), + cp__is_trivial= "__is_trivial".toCharArray(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IExtendedScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IExtendedScannerInfo.java index 097d1c90c4f..8918ada67b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IExtendedScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IExtendedScannerInfo.java @@ -6,13 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * John Camelon, IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; /** - * @author jcamelon - * + * Extension to {@link IScannerInfo}, allows for providing additional preprocessor options. */ public interface IExtendedScannerInfo extends IScannerInfo { @@ -31,6 +31,10 @@ public interface IExtendedScannerInfo extends IScannerInfo { /** * Return an array of paths that is searched after the current directory, when an include directive * with double-quotes is processed. + *

+ * In order to suppress the use of the directory of the current file (side effect of gcc option + * -I-) you can pass '-' as one of the include paths. Other than that, the '-' will not have an + * effect, in particular it will not split the include path as the -I- option would do. */ public String [] getLocalIncludePath(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IGCCToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IGCCToken.java index af472746f36..6eb92f22f9c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IGCCToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IGCCToken.java @@ -6,11 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Ed Swartz (Nokia) - * Markus Schorn (Wind River Systems) + * John Camelon (IBM Rational Software) - Initial API and implementation + * Ed Swartz (Nokia) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ - package org.eclipse.cdt.core.parser; /** @@ -41,4 +41,7 @@ public interface IGCCToken extends IToken { /** @since 5.3 */ int tTT_is_pod= FIRST_RESERVED_IGCCToken + 19; /** @since 5.3 */ int tTT_is_polymorphic= FIRST_RESERVED_IGCCToken + 20; /** @since 5.3 */ int tTT_is_union= FIRST_RESERVED_IGCCToken + 21; + /** @since 5.5 */ int tTT_is_literal_type= FIRST_RESERVED_IGCCToken + 22; + /** @since 5.5 */ int tTT_is_standard_layout= FIRST_RESERVED_IGCCToken + 23; + /** @since 5.5 */ int tTT_is_trivial= FIRST_RESERVED_IGCCToken + 24; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java index 294c2d4fdfe..2ae97cfd6e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScannerInfo.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; @@ -19,11 +19,10 @@ import java.util.Map; */ public interface IScannerInfo { /** - * Returns a Map containing all the defined preprocessor - * symbols and their values. + * Returns a {@link Map} containing all the defined preprocessor symbols and their values. * Symbols defined without values have an empty string for a value. For - * example,-Dsymbol=value would have a map entry (symbol,value). A symbol - * defined as -Dsymbol= would have a map entry of (symbol,""). + * example, -Dsymbol=value would have a map entry (symbol, value). A symbol + * defined as -Dsymbol= would have a map entry of (symbol, ""). */ public Map getDefinedSymbols(); @@ -31,14 +30,20 @@ public interface IScannerInfo { * Returns an array of paths that are searched when processing an include directive. * see {@link IExtendedScannerInfo#getLocalIncludePath()} *

+ * In order to suppress the use of the directory of the current file (side effect of gcc option + * -I-) you can pass '-' as one of the include paths. Other than that, the '-' will not have an + * effect, in particular it will not split the include path as the -I- option would do. To achieve + * that, use {@link IExtendedScannerInfo#getLocalIncludePath()}. + *

* In order to handle framework includes used on Apple Computers you can make use of * the two variables: '__framework__' and '__header__'. *
E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__header__, * /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__header__ * would handle the framework search for '/System/Library/Frameworks' - *
The variables are handled only, if a search path element makes use of both of the variables. - * The __framework__ variable will receive the first segment of the include, the __header__ variable - * the rest. Such a search path element is not used for directives with a single segment (e.g. 'header.h') + *
The variables are handled only, if a search path element makes use of both of + * the variables. The __framework__ variable will receive the first segment of the include, + * the __header__ variable the rest. Such a search path element is not used for directives + * with a single segment (e.g. 'header.h') */ public String[] getIncludePaths(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java index e4182f46133..f231a2f82fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISignificantMacros.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.parser; import org.eclipse.cdt.core.parser.util.CharArrayUtils; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java index b3d27ee7b3d..330878bb36c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java @@ -329,7 +329,7 @@ public class CharArrayUtils { } /** - * Find an array of chars in an array of arrays of chars. + * Finds an array of chars in an array of arrays of chars. * @return offset where the array was found or -1 */ public static int indexOf(final char[] searchFor, final char[][] searchIn) { @@ -340,4 +340,15 @@ public class CharArrayUtils { } return -1; } + + /** + * Converts a {@link StringBuilder} to a character array. + * @since 5.5 + */ + public static char[] extractChars(StringBuilder buf) { + final int len = buf.length(); + char[] result= new char[len]; + buf.getChars(0, len, result, 0); + return result; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java new file mode 100644 index 00000000000..ba5a8b312c2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/IntArray.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * 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.core.parser.util; + +import java.util.Arrays; + +/** + * Automatically growing integer array. + * + * @since 5.5 + */ +public class IntArray { + private static final int INITIAL_CAPACITY = 10; + private static final int[] EMPTY_ARRAY = {}; + + private int[] buffer = EMPTY_ARRAY; + private int size; + + public IntArray() { + } + + public IntArray(int initialCapacity) { + this.buffer = new int[initialCapacity]; + } + + public int size() { + return size; + } + + public boolean isEmpty() { + return size == 0; + } + + public void add(int value) { + grow(size + 1); + buffer[size++] = value; + } + + public void add(int index, int value) { + checkBounds(index); + grow(size + 1); + System.arraycopy(buffer, index, buffer, index + 1, size - index); + buffer[index] = value; + size++; + } + + public void addAll(IntArray other) { + grow(size + other.size()); + System.arraycopy(other.buffer, 0, buffer, size, other.size); + size += other.size; + return; + } + + public void addAll(int[] array) { + grow(size + array.length); + System.arraycopy(array, 0, buffer, size, array.length); + size += array.length; + return; + } + + public int remove(int index) { + checkBounds(index); + int old = buffer[index]; + int n = size - index - 1; + if (n > 0) { + System.arraycopy(buffer, index + 1, buffer, index, n); + } + return old; + } + + public void remove(int from, int to) { + checkBounds(from); + checkBounds(to); + System.arraycopy(buffer, to, buffer, from, size - to); + } + + public void clear() { + size = 0; + } + + public int get(int index) { + checkRange(index); + return buffer[index]; + } + + public int set(int index, int value) { + checkBounds(index); + int old = buffer[index]; + buffer[index] = value; + return old; + } + + public int[] toArray() { + return size == 0 ? EMPTY_ARRAY : Arrays.copyOf(buffer, size); + } + + public void trimToSize() { + if (size == 0) { + buffer = EMPTY_ARRAY; + } else if (size < buffer.length) { + buffer = Arrays.copyOf(buffer, size); + } + } + + public void ensureCapacity(int minCapacity) { + if (minCapacity > 0) { + grow(minCapacity); + } + } + + private void grow(int minCapacity) { + if (minCapacity < 0) // Overflow + throw new OutOfMemoryError(); + + int capacity = buffer.length; + if (minCapacity > capacity) { + int newCapacity = capacity == 0 ? INITIAL_CAPACITY : capacity + (capacity >> 1); + // newCapacity may be negative due to overflow. + if (newCapacity < minCapacity) + newCapacity = minCapacity; + // newCapacity is guaranteed to be non negative. + try { + buffer = Arrays.copyOf(buffer, newCapacity); + } catch (OutOfMemoryError e) { + // Try again it case we were too aggressive in reserving capacity. + buffer = Arrays.copyOf(buffer, minCapacity); + } + } + } + + private void checkBounds(int index) { + if (index < 0) { + throw new IndexOutOfBoundsException("Negative index: " + index); //$NON-NLS-1$ + } + checkRange(index); + } + + private void checkRange(int index) { + if (index >= size) { + throw new IndexOutOfBoundsException("Index: " + index + ", size: " + size); //$NON-NLS-1$//$NON-NLS-2$ + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java index 485e092db80..4414f2d530a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java @@ -33,7 +33,7 @@ public class Linkage implements ILinkage { } public static String getLinkageName(int linkageID) throws CoreException { - switch(linkageID) { + switch (linkageID) { case NO_LINKAGE_ID: return NO_LINKAGE_NAME; case C_LINKAGE_ID: return C_LINKAGE_NAME; case CPP_LINKAGE_ID: return CPP_LINKAGE_NAME; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 0f1a4b7c758..d01186b5027 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -109,11 +109,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { fDeclarator= d; } } - + protected static class Decl extends Exception { public Decl() { } - + public IASTDeclSpecifier fDeclSpec1; public IASTDeclSpecifier fDeclSpec2; @@ -139,7 +139,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return this; } } - + private static final ASTVisitor MARK_INACTIVE = new ASTGenericVisitor(true) { { shouldVisitAmbiguousNodes= true; @@ -149,7 +149,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { ((ASTNode) node).setInactive(); return PROCESS_CONTINUE; } - + @Override public int visit(ASTAmbiguousNode node) { node.setInactive(); @@ -161,10 +161,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return PROCESS_CONTINUE; } }; - + /** - * Information about the context in which a cast-expression is parsed: - * in a binary expression, in a binary expression in a template-id, or elsewhere. + * Information about the context in which a cast-expression is parsed: + * in a binary expression, in a binary expression in a template-id, or elsewhere. */ protected static enum CastExprCtx {eDirectlyInBExpr, eInBExpr, eNotInBExpr} protected static enum ExprKind {eExpression, eAssignment, eConstant} @@ -184,12 +184,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final boolean supportDeclspecSpecifiers; protected boolean supportParameterInfoBlock; protected boolean supportFunctionStyleAsm; - protected boolean supportExtendedSizeofOperator; + protected boolean supportExtendedSizeofOperator; protected final IBuiltinBindingsProvider builtinBindingsProvider; - + protected boolean functionCallCanBeLValue= false; - protected boolean skipTrivialExpressionsInAggregateInitializers= false; - + protected boolean skipTrivialExpressionsInAggregateInitializers= false; + /** * Marks the beginning of the current declaration. It is important to clear the mark whenever we * enter a nested declaration, in order to avoid holding on to all the tokens. @@ -203,19 +203,19 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected boolean parsePassed = true; protected int backtrackCount = 0; protected BacktrackException backtrack = new BacktrackException(); - + protected ASTCompletionNode completionNode; - + private final INodeFactory nodeFactory; private boolean fActiveCode= true; - + protected AbstractGNUSourceCodeParser(IScanner scanner, IParserLogService logService, ParserMode parserMode, INodeFactory nodeFactory, boolean supportStatementsInExpressions, boolean supportTypeOfUnaries, boolean supportAlignOfUnaries, boolean supportKnRC, boolean supportAttributeSpecifiers, - boolean supportDeclspecSpecifiers, + boolean supportDeclspecSpecifiers, IBuiltinBindingsProvider builtinBindingsProvider) { this.scanner = scanner; this.log = wrapLogService(logService); @@ -229,7 +229,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { this.builtinBindingsProvider= builtinBindingsProvider; this.nodeFactory = nodeFactory; } - + /** * Instructs the parser not to create ast nodes for expressions within aggregate initializers * when they do not contain names. @@ -288,12 +288,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { throw olre; } } - + private final IToken nextToken(boolean skipInactive) throws EndOfFileException { final IToken t= nextToken; - if (t != null) + if (t != null) return t; - + final IToken tn= fetchToken(skipInactive); nextToken= tn; return tn; @@ -307,12 +307,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IToken t= nextToken(skipInactive); for (; i > 1; --i) { t = t.getNext(); - if (t == null) + if (t == null) t = fetchToken(skipInactive); } return t; } - + /** * Returns the next token without advancing. Same as {@code LA(1)}. */ @@ -338,7 +338,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final IToken consume() throws EndOfFileException { IToken t= nextToken(true); checkForEOI(t); - + nextToken= t.getNext(); return t; } @@ -346,7 +346,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Tests whether we are looking at a change from active to inactive code at this point. If so, the change * is accepted. - * + * * @param nesting * the nesting level of the code branch we have to stay within * @return false if an inactive code branch was rejected because of its nesting level, @@ -362,7 +362,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IInactiveCodeToken it = (IInactiveCodeToken) t; if (it.getNewNesting() < nesting || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { return false; - } + } fActiveCode= false; nextToken= t.getNext(); // consume the token continue; @@ -370,7 +370,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { it = (IInactiveCodeToken) t; if (it.getNewNesting() < nesting || (it.getNewNesting() == nesting && it.getOldNesting() == nesting)) { return false; - } + } fActiveCode= true; nextToken= t.getNext(); // consume the token continue; @@ -382,7 +382,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } return true; } - + protected final void skipInactiveCode() throws OffsetLimitReachedException { IToken t= nextToken; if (fActiveCode && (t == null || t.getType() != IToken.tINACTIVE_CODE_START)) @@ -391,7 +391,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { fActiveCode= true; while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) t= t.getNext(); - + if (t != null) { nextToken= t.getNext(); } else { @@ -403,13 +403,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { createCompletionNode(olre.getFinalToken()); throw olre; } - } + } } - + protected final boolean isActiveCode() { return fActiveCode; } - + protected final int getCodeBranchNesting() { return scanner.getCodeBranchNesting(); } @@ -446,7 +446,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return null; } } - + /** * Look ahead in the token list and return the token type. * @param i number of tokens to look ahead, must be greater or equal to 0. @@ -455,7 +455,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final int LT(int i) throws EndOfFileException { return LA(i).getType(); } - + /** * Same as {@link #LT(int)}, but returns 0 when eof is reached. */ @@ -466,10 +466,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return 0; } } - + /** - * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} - * is thrown if the type does not match the expected one. + * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} + * is thrown if the type does not match the expected one. * @param type the expected type of the next token. */ protected final IToken consume(int type) throws EndOfFileException, BacktrackException { @@ -480,7 +480,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } /** - * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} + * The next token is consumed. Afterwards its type is checked and a {@link BacktrackException} * is thrown if the type neither matches type1 nor type2. */ protected final IToken consume(int type1, int type2) throws EndOfFileException, BacktrackException { @@ -494,7 +494,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Consume the next token available only if the type is as specified. In case we reached * the end of completion, no token is consumed and the eoc-token returned. - * + * * @param type * The type of token that you are expecting. * @return the token that was consumed and removed from our buffer. @@ -508,7 +508,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (lt1 == IToken.tEOC) return la1; throwBacktrack(la1); - } + } return consume(); } @@ -539,7 +539,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { ((ASTNode) n).setOffsetAndLength(offset, endOffset-offset); return n; } - + protected final void adjustLength(IASTNode n, IASTNode endNode) { final int endOffset= calculateEndOffset(endNode); adjustEndOffset(n, endOffset); @@ -571,7 +571,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Parses an identifier. - * + * * @throws BacktrackException request a backtrack */ protected abstract IASTName identifier() throws EndOfFileException, BacktrackException; @@ -596,11 +596,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { ((ASTNode) result).setOffsetAndLength(offset, length); return result; } - + protected void logThrowable(String methodName, Throwable e) { if (e != null) { if (log.isTracing()) { - String message = + String message = String.format("Parser: Unexpected throwable in %s:%s::%s. w/%s", //$NON-NLS-1$ methodName, e.getClass().getName(), e.getMessage(), scanner); log.traceLog(message); @@ -608,10 +608,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { log.traceException(e); } } - + @Override public String toString() { - return scanner.toString(); + return scanner.toString(); } /** @@ -621,7 +621,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected void logException(String methodName, Exception e) { if (!(e instanceof EndOfFileException) && e != null) { if (log.isTracing()) { - String message = + String message = String.format("Parser: Unexpected exception in %s:%s::%s. w/%s", //$NON-NLS-1$ methodName, e.getClass().getName(), e.getMessage(), scanner); log.traceLog(message); @@ -635,7 +635,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backtrack.initialize(problem, node); throw backtrack; } - + protected final void throwBacktrack(IASTProblem problem) throws BacktrackException { ++backtrackCount; backtrack.initialize(problem); @@ -680,7 +680,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // speed up the parser by skipping the body, simply look for matching brace and return final boolean isActive = isActiveCode(); final int codeBranchNesting= getCodeBranchNesting(); - + consume(IToken.tLBRACE); IToken result = null; int depth = 1; @@ -691,7 +691,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (lt == IToken.tINACTIVE_CODE_SEPARATOR || lt == IToken.tINACTIVE_CODE_END || lt == IToken.tINACTIVE_CODE_START) { if (!acceptInactiveCodeBoundary(codeBranchNesting)) throw new EndOfFileException(t.getOffset(), true); - } + } } result = consume(); switch (result.getType()) { @@ -715,7 +715,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); return buildProblemDeclaration(problem); } - + protected IASTProblemStatement skipProblemStatement(int offset) { failParse(); declarationMark= null; @@ -729,7 +729,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { final int endOffset= skipToSemiOrClosingBrace(offset, true); return createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); } - + private int skipToSemiOrClosingBrace(int offset, boolean eatBrace) { failParse(); declarationMark= null; @@ -744,7 +744,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break loop; case IToken.tSEMI: if (depth == 0) { - endOffset= consume().getEndOffset(); + endOffset= consume().getEndOffset(); break loop; } break; @@ -795,7 +795,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { compExpr= depth; } consume(); - } + } break; case IToken.tRPAREN: if (--depth < 0) { @@ -838,12 +838,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { try { if (next.getType() == IToken.tEOC) break; - + if (next.getType() == IToken.tRBRACE) { endOffset= consume().getEndOffset(); break; } - + final int nextOffset = next.getOffset(); declarationMark= next; next= null; // don't hold on to the token while parsing namespaces, class bodies, etc. @@ -957,7 +957,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { public IASTInitializerClause getExpression() { return fExpression; } - + public BinaryOperator getNext() { return fNext; } @@ -966,20 +966,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { fNext = next; } } - + public final IASTExpression buildExpression(BinaryOperator leftChain, IASTInitializerClause expr) { BinaryOperator rightChain= null; for (;;) { if (leftChain == null) { if (rightChain == null) return (IASTExpression) expr; - + expr= buildExpression((IASTExpression) expr, rightChain); rightChain= rightChain.fNext; } else if (rightChain != null && leftChain.fRightPrecedence < rightChain.fLeftPrecedence) { expr= buildExpression((IASTExpression) expr, rightChain); rightChain= rightChain.fNext; - } else { + } else { BinaryOperator op= leftChain; leftChain= leftChain.fNext; expr= op.exchange(expr); @@ -1007,7 +1007,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { adjustLength(conditionalEx, negative); } return conditionalEx; - + case IToken.tCOMMA: IASTExpressionList list; if (left instanceof IASTExpressionList) { @@ -1020,7 +1020,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { list.addExpression((IASTExpression) right); adjustLength(list, right); return list; - + case IToken.tASSIGN: op= IASTBinaryExpression.op_assign; break; @@ -1124,17 +1124,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { case IToken.tARROWSTAR: op = IASTBinaryExpression.op_pmarrow; break; - + default: assert false; return null; } - + IASTExpression result= buildBinaryExpression(op, left, right, calculateEndOffset(right)); final CastAmbiguityMarker am = operator.fAmbiguityMarker; if (am != null) { if (unaryOp != 0) { - result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, + result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, am.getTypeIdForCast(), unaryOp, am.getUnaryOperatorOffset()); } else { assert false; @@ -1148,7 +1148,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected abstract IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException; protected abstract IASTExpression primaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException; protected abstract IASTTypeId typeId(DeclarationOptions option) throws EndOfFileException, BacktrackException; - + private final static class CastAmbiguityMarker extends ASTNode implements IASTExpression { private IASTExpression fExpression; private final IASTTypeId fTypeIdForCast; @@ -1176,7 +1176,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { public int getUnaryOperatorOffset() { return fUnaryOperatorOffset; } - + @Override public IASTExpression copy() { throw new UnsupportedOperationException(); @@ -1195,8 +1195,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { @Override public boolean isLValue() { throw new UnsupportedOperationException(); - } - + } + @Override public ValueCategory getValueCategory() { throw new UnsupportedOperationException(); @@ -1222,7 +1222,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (ctx == CastExprCtx.eDirectlyInBExpr) { switch (LT(1)) { // ambiguity with unary operator - case IToken.tPLUS: case IToken.tMINUS: + case IToken.tPLUS: case IToken.tMINUS: case IToken.tSTAR: case IToken.tAMPER: final int operatorOffset = LA(1).getOffset(); IToken markEnd= mark(); @@ -1234,7 +1234,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backup(markEnd); unaryFailed= true; } - } + } } try { boolean couldBeFunctionCall= LT(1) == IToken.tLPAREN; @@ -1304,7 +1304,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { setRange(tu, offset, endOffset); return; } - + final int endOffset = getEndOffset(); setRange(tu, offset, endOffset); if (lt1 == IToken.tEOC || (lt1 == 0 && tu instanceof IASTCompositeTypeSpecifier)) { @@ -1312,17 +1312,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } throwBacktrack(createProblem(IProblem.SYNTAX_ERROR, endOffset, 0), tu); } - + private final void declarationList(final IASTDeclarationListOwner tu, DeclarationOptions options, boolean upToBrace, int codeBranchNesting) { final boolean wasActive= isActiveCode(); while (true) { final boolean ok= acceptInactiveCodeBoundary(codeBranchNesting); if (!ok) { // we left to an enclosing code branch. If we started in inactive code, it's time to leave. - if (!wasActive) + if (!wasActive) return; - - // if we started in active code, we need to skip the outer and therefore unrelated + + // if we started in active code, we need to skip the outer and therefore unrelated // inactive branches until we hit active code again. try { skipInactiveCode(); @@ -1330,11 +1330,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return; } codeBranchNesting= Math.min(getCodeBranchNesting()+1, codeBranchNesting); - + // we could be at the start of inactive code so restart the loop - continue; + continue; } - + final boolean active= isActiveCode(); IToken next= LAcatchEOF(1); if (next == null || next.getType() == IToken.tEOC) @@ -1343,7 +1343,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (upToBrace && next.getType() == IToken.tRBRACE && active == wasActive) { return; } - + final int offset = next.getOffset(); declarationMark= next; next= null; // don't hold on to the token while parsing namespaces, class bodies, etc. @@ -1393,7 +1393,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected IASTExpression unaryExpression(int operator, CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { final IToken operatorToken= consume(); IASTExpression operand= castExpression(ctx, strat); - + CastAmbiguityMarker ca= null; if (operand instanceof CastAmbiguityMarker) { ca= (CastAmbiguityMarker) operand; @@ -1413,19 +1413,19 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { throwBacktrack(operatorToken); } } - + IASTExpression result= buildUnaryExpression(operator, operand, operatorToken.getOffset(), calculateEndOffset(operand)); return ca == null ? result : ca.updateExpression(result); } protected IASTExpression buildUnaryExpression(int operator, IASTExpression operand, int offset, int lastOffset) { - IASTUnaryExpression result = nodeFactory.newUnaryExpression(operator, operand); + IASTUnaryExpression result = nodeFactory.newUnaryExpression(operator, operand); setRange(result, offset, lastOffset); return result; } protected IASTStatement handleFunctionBody() throws BacktrackException, EndOfFileException { - declarationMark= null; + declarationMark= null; if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { int offset = LA(1).getOffset(); IToken last = skipOverCompoundStatement(); @@ -1440,7 +1440,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); setRange(cs, offset, last.getEndOffset()); return cs; - } + } // full parse return functionBody(); @@ -1448,7 +1448,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Parses a function body. - * + * * @return the compound statement representing the function body. * @throws BacktrackException * request a backtrack @@ -1457,24 +1457,23 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return compoundStatement(); } - protected abstract IASTDeclarator initDeclarator(IASTDeclSpecifier declSpec, DeclarationOptions option) + protected abstract IASTDeclarator initDeclarator(IASTDeclSpecifier declSpec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer; - /** * Parse an enumeration specifier, as according to the ANSI specs in C & * C++. enumSpecifier: "enum" (name)? "{" (enumerator-list) "}" * enumerator-list: enumerator-definition enumerator-list , * enumerator-definition enumerator-definition: enumerator enumerator = * constant-expression enumerator: identifier - * + * * @throws BacktrackException request a backtrack */ protected IASTEnumerationSpecifier enumSpecifier() throws BacktrackException, EndOfFileException { final IToken mark= mark(); final int offset= consume().getOffset(); - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); IASTName name; @@ -1483,7 +1482,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } else { name= nodeFactory.newName(); } - + if (LT(1) != IToken.tLBRACE) { backup(mark); throwBacktrack(mark); @@ -1523,7 +1522,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { problemOffset= LA(1).getOffset(); if (needComma) throw backtrack; - + final IASTName etorName= identifier(); final IASTEnumerator enumerator= nodeFactory.newEnumerator(etorName, null); endOffset= calculateEndOffset(etorName); @@ -1535,7 +1534,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { enumerator.setValue(value); adjustLength(enumerator, value); endOffset= calculateEndOffset(value); - } + } needComma= true; continue loop; default: @@ -1560,7 +1559,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IASTExpression expr= expression(); if (!followedByParenthesis) return expr; - + switch (LT(1)) { case IToken.tEOC: case IToken.tRPAREN: @@ -1580,15 +1579,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } protected abstract IASTDeclaration declaration(DeclarationOptions option) throws BacktrackException, EndOfFileException; - + /** * Parses for two alternatives of a declspec sequence. If there is a second alternative the token after the second alternative * is returned, such that the parser can continue after both variants. */ protected abstract Decl declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException; - + /** - * Parses for two alternatives of a declspec sequence followed by a initDeclarator. + * Parses for two alternatives of a declspec sequence followed by a initDeclarator. * A second alternative is accepted only, if it ends at the same point of the first alternative. Otherwise the * longer alternative is selected. */ @@ -1598,7 +1597,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { final int lt1 = LTcatchEOF(1); if (lt1 == IToken.tEOC) return result; - + // support simple declarations without declarators final boolean acceptEmpty = acceptCompoundWithoutDtor && isLegalWithoutDtor(result.fDeclSpec1); if (acceptEmpty) { @@ -1609,7 +1608,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return result; } } - + final IToken dtorMark1= mark(); final IToken dtorMark2= result.fDtorToken1; final IASTDeclSpecifier declspec1= result.fDeclSpec1; @@ -1632,7 +1631,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { dtor2= initDeclarator(declspec2, option); return result.set(declspec2, dtor2, dtorMark2); } - + // first variant was a success. If possible, try second one. if (dtorMark2 == null) { return result.set(declspec1, dtor1, dtorMark1); @@ -1646,7 +1645,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backup(end1); return result.set(declspec1, dtor1, dtorMark1); } - + final IToken end2= mark(); if (end1 == end2) { return result.set(declspec1, dtor1, declspec2, dtor2); @@ -1655,10 +1654,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backup(end1); return result.set(declspec1, dtor1, dtorMark1); } - + return result.set(declspec2, dtor2, dtorMark2); } - + protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTCompositeTypeSpecifier) return true; @@ -1666,14 +1665,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return true; if (declSpec instanceof IASTEnumerationSpecifier) return true; - + return false; } protected IASTDeclaration[] problemDeclaration(int offset, BacktrackException bt, DeclarationOptions option) { failParse(); IASTProblem origProblem= createProblem(bt); - + // a node was detected by assuming additional tokens (e.g. missing semicolon) IASTNode n= bt.getNodeBeforeProblem(); if (n instanceof IASTDeclaration) { @@ -1682,12 +1681,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { declarationMark= null; return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)}; } - } - + } + if (declarationMark != null && isActiveCode()) { IASTDeclaration trailingProblem= null; offset= declarationMark.getOffset(); - + // try to skip identifiers (undefined macros?) IASTDeclaration decl= null; int endOffset= 0; @@ -1712,7 +1711,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { decl= (IASTDeclaration) n; trailingProblem= buildProblemDeclaration(bt2.getProblem()); break; - } + } } catch (EndOfFileException e) { endOffset= getEndOffset(); break; @@ -1720,7 +1719,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } } declarationMark= null; - + if (decl != null) { IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); IASTDeclaration pd= buildProblemDeclaration(problem); @@ -1738,11 +1737,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (LT(1) == IToken.t_volatile) { consume(); } - + if (supportFunctionStyleAsm && LT(1) != IToken.tLPAREN) { return functionStyleAsmDeclaration(); } - + StringBuilder buffer= new StringBuilder(); asmExpression(buffer); int lastOffset = consume(IToken.tSEMI).getEndOffset(); @@ -1810,7 +1809,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break; case IToken.tEOC: throw new EndOfFileException(t.getOffset()); - + default: if (content != null) { if (needspace) { @@ -1837,7 +1836,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); return result; } - + /** * There are many ambiguities in C and C++ between expressions and declarations. * This method will attempt to parse a statement as both an expression and a declaration, @@ -1856,7 +1855,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { expressionStatement = nodeFactory.newExpressionStatement(expression); setRange(expressionStatement, expression); afterExpression= LA(); - + IToken semi= consumeOrEOC(IToken.tSEMI); foundSemicolon= true; adjustEndOffset(expressionStatement, semi.getEndOffset()); @@ -1886,10 +1885,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } if (ds == null) { - backup(afterExpression); + backup(afterExpression); if (foundSemicolon) return expressionStatement; - + throwBacktrack(createProblem(IProblem.MISSING_SEMICOLON, calculateEndOffset(expressionStatement)-1, 1), expressionStatement); return null; // Hint for java-compiler } @@ -1897,10 +1896,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (expressionStatement == null || !foundSemicolon) { return ds; } - + // At this point we know we have an ambiguity. // Attempt to resolve some ambiguities that are easy to detect. - + // A * B = C; // A*B cannot be a lvalue. // foo() = x; // foo() cannot be a lvalue in c, in c++ it can. if (expressionStatement.getExpression() instanceof IASTBinaryExpression) { @@ -1924,7 +1923,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (declspec instanceof IASTNamedTypeSpecifier) { final IASTDeclarator[] declarators = simpleDecl.getDeclarators(); - // x; + // x; // can be parsed as a named declaration specifier without a declarator if (declarators.length == 0) { backup(afterExpression); @@ -1939,8 +1938,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { statement.addStatement(ds); return setRange(statement, ds); } - - + /** * Returns true if the given declaration has unspecified type, * in this case the type defaults to int and is know as "implicit int". @@ -1948,7 +1946,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected static boolean isImplicitInt(IASTDeclaration declaration) { if (declaration instanceof IASTSimpleDeclaration) { IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)declaration).getDeclSpecifier(); - if (declSpec instanceof IASTSimpleDeclSpecifier && + if (declSpec instanceof IASTSimpleDeclSpecifier && ((IASTSimpleDeclSpecifier)declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified) { return true; } @@ -1956,7 +1954,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return false; } - protected abstract IASTAmbiguousStatement createAmbiguousStatement(); protected IASTStatement parseLabelStatement() throws EndOfFileException, BacktrackException { @@ -1965,8 +1962,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { consume(IToken.tCOLON); // tCOLON IASTStatement nestedStatement = statement(); int lastOffset = calculateEndOffset(nestedStatement); - - + IASTLabelStatement label_statement = nodeFactory.newLabelStatement(name, nestedStatement); setRange(label_statement, offset, lastOffset); return label_statement; @@ -2003,10 +1999,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IASTStatement stmt= null; if (LT(1) != IToken.tEOC) stmt= statement(); - - if (!(stmt instanceof IASTCaseStatement) && !(stmt instanceof IASTDefaultStatement)) + + if (!(stmt instanceof IASTCaseStatement) && !(stmt instanceof IASTDefaultStatement)) return stmt; - + // bug 105334, switch without compound statement IASTCompoundStatement comp= nodeFactory.newCompoundStatement(); ((ASTNode) comp).setOffsetAndLength((ASTNode) stmt); @@ -2054,7 +2050,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { consume(IToken.tLPAREN); do_condition = condition(true); } - + int lastOffset; switch (LT(1)) { case IToken.tRPAREN: @@ -2064,7 +2060,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { default: throw backtrack; } - + switch (LT(1)) { case IToken.tSEMI: case IToken.tEOC: @@ -2073,7 +2069,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { default: throw backtrack; } - + IASTDoStatement do_statement = nodeFactory.newDoStatement(do_body, do_condition); ((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); return do_statement; @@ -2186,7 +2182,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { throwBacktrack(token.getOffset(), token.getLength()); } - protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis, + protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis, int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { IASTTypeId typeid; @@ -2227,7 +2223,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } else { expressionList.addExpression(expr2); } - + return buildUnaryExpression(unaryExprKind, expressionList, offset, endOffset1); } typeid= null; @@ -2237,10 +2233,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break; } } - } catch (BacktrackException e) { + } catch (BacktrackException e) { typeid= null; } - + CastAmbiguityMarker ca= null; backup(mark); try { @@ -2249,7 +2245,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { expr= expression(); endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset(); } else { - expr= unaryExpression(ctx, strat); + expr= unaryExpression(ctx, strat); if (expr instanceof CastAmbiguityMarker) { ca= (CastAmbiguityMarker) expr; expr= ca.getExpression(); @@ -2257,7 +2253,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } endOffset2= calculateEndOffset(expr); } - } catch (BacktrackException bte) { + } catch (BacktrackException bte) { if (typeid == null) throw bte; } @@ -2268,19 +2264,18 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { setRange(typeIdExpression, offset, endOffset1); result1= typeIdExpression; backup(typeidLA); - + if (expr == null || endOffset1 > endOffset2) return result1; } - + IASTExpression result2= unaryExprKind == -1 ? expr : buildUnaryExpression(unaryExprKind, expr, offset, endOffset2); if (ca != null) result2= ca.updateExpression(result2); - + if (result1 == null) return result2; - IASTAmbiguousExpression ambExpr = createAmbiguousExpression(); ambExpr.addExpression(result1); ambExpr.addExpression(result2); @@ -2320,8 +2315,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Accepts a sequence of __attribute__ or __declspec. - * - * @param allowAttrib if true accept any number of __attribute__ + * + * @param allowAttrib if true accept any number of __attribute__ * @param allowDeclspec if true accept any number of __declspec * @return the list of attributes, or {@code null} if there are none * @throws BacktrackException @@ -2350,21 +2345,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @throws BacktrackException * @throws EndOfFileException */ - protected List __attribute__() throws BacktrackException, EndOfFileException { - if (LT(1) != IGCCToken.t__attribute__) + protected List __attribute__() throws BacktrackException, EndOfFileException { + if (LT(1) != IGCCToken.t__attribute__) return null; List result = null; consume(); if (LT(1) == IToken.tLPAREN) { - consume(); + consume(); consume(IToken.tLPAREN); for (;;) { - final int lt1= LT(1); - if (lt1 == IToken.tRPAREN || lt1 == IToken.tEOC) + final int lt1= LT(1); + if (lt1 == IToken.tRPAREN || lt1 == IToken.tEOC) break; - + // Allow empty attribute if (lt1 != IToken.tCOMMA) { IASTAttribute attribute = singleAttribute(); @@ -2374,7 +2369,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } // Require comma - if (LT(1) != IToken.tCOMMA) + if (LT(1) != IToken.tCOMMA) break; consume(); } @@ -2399,12 +2394,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { setRange(result, attributeName.getOffset(), getEndOffset()); return result; } - + private IToken identifierOrKeyword() throws EndOfFileException, BacktrackException { IToken t = LA(1); char[] image= t.getCharImage(); if (image.length == 0) - throw backtrack; + throw backtrack; char firstChar= image[0]; if (!Character.isLetter(firstChar) && firstChar != '_') throw backtrack; @@ -2426,11 +2421,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { case IToken.tLBRACKET: token = balancedTokenSeq(t.getOffset(), IToken.tRBRACKET); break; - + case IToken.tLBRACE: token = balancedTokenSeq(t.getOffset(), IToken.tRBRACE); break; - + default: token = nodeFactory.newToken(t.getType(), t.getCharImage()); setRange(token, t.getOffset(), t.getEndOffset()); @@ -2445,7 +2440,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * Parses sequence of tokens until encountering a token of a given type * @param offset the offset for the returned token node. * @param endType the type of the token to stop before - * @return a token sequence, possibly empty but never {@code null} + * @return a token sequence, possibly empty but never {@code null} */ private IASTToken balancedTokenSeq(int offset, int endType) throws EndOfFileException, BacktrackException { IASTToken token = balancedTokenSeq(endType); @@ -2458,7 +2453,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * Adds a token to a token sequence. - * + * * @param sequence the token sequence, may be {@code null} * @param token the token to add * @return the modified token sequence that is never {@code null} @@ -2486,12 +2481,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { skipBrackets(IToken.tLPAREN, IToken.tRPAREN, 0); } } - } + } /** * Hook method to support (skip) additional declspec modifiers. * @throws BacktrackException - * @throws EndOfFileException + * @throws EndOfFileException */ protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException { // default action: consume keyword plus optional parenthesized "something" @@ -2520,7 +2515,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected boolean canBeCompoundLiteral() throws EndOfFileException { IToken m= mark(); try { - // The parenthesis cannot be followed by a binary operator + // The parenthesis cannot be followed by a binary operator skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); return LTcatchEOF(1) == IToken.tLBRACE; } catch (BacktrackException bt) { @@ -2533,7 +2528,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected boolean canBeCastExpression() throws EndOfFileException { IToken m= mark(); try { - // The parenthesis cannot be followed by a binary operator + // The parenthesis cannot be followed by a binary operator skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); switch (LTcatchEOF(1)) { case IToken.tAMPERASSIGN: @@ -2580,7 +2575,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { backup(m); } } - + protected boolean canBeTypeSpecifier() throws EndOfFileException { final int lt1 = LT(1); switch (lt1) { @@ -2616,7 +2611,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // elaborated type specifier: (together with class, struct, union, enum) case IToken.t_typename: - + // cq-qualifiers case IToken.t_const: case IToken.t_volatile: @@ -2629,15 +2624,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // content assist case IToken.tCOMPLETION: return true; - + default: - if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) + if (lt1 >= IExtensionToken.t__otherDeclSpecModifierFirst && lt1 <= IExtensionToken.t__otherDeclSpecModifierLast) return true; return false; } } - + protected void skipBrackets(int left, int right, int terminator) throws EndOfFileException, BacktrackException { consume(left); int nesting= 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java index 4b0ebf003e7..6d859a6d450 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ITypeMarshalBuffer.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.core.runtime.CoreException; /** @@ -61,6 +62,7 @@ public interface ITypeMarshalBuffer { IValue unmarshalValue() throws CoreException; IBinding unmarshalBinding() throws CoreException; ISerializableEvaluation unmarshalEvaluation() throws CoreException; + ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException; int getByte() throws CoreException; int getShort() throws CoreException; int getInt() throws CoreException; @@ -71,6 +73,7 @@ public interface ITypeMarshalBuffer { void marshalValue(IValue value) throws CoreException; void marshalBinding(IBinding binding) throws CoreException; void marshalEvaluation(ISerializableEvaluation eval, boolean includeValue) throws CoreException; + void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException; void putByte(byte data); void putShort(short data); void putInt(int data); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index de2eeb7360c..300adbeeb28 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 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 @@ -42,13 +42,12 @@ import com.ibm.icu.text.MessageFormat; */ public class ProblemBinding extends PlatformObject implements IProblemBinding, IASTInternalScope { public static ProblemBinding NOT_INITIALIZED= new ProblemBinding(null, 0); - + protected final int id; protected char[] arg; protected IASTNode node; - private final String message = null; private IBinding[] candidateBindings; - + public ProblemBinding(IASTName name, int id) { this(name, id, null, null); } @@ -57,6 +56,37 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I this(name, id, null, candidateBindings); } + /** + * @param name the name that could not be resolved, may be {@code null} + * @param point the point in code where the problem was encountered + * @param id the ID of the problem, see {@link IProblemBinding} + */ + public ProblemBinding(IASTName name, IASTNode point, int id) { + this(name, point, id, null); + } + + /** + * @param name the name that could not be resolved, may be {@code null} + * @param point the point in code where the problem was encountered + * @param id the ID of the problem, see {@link IProblemBinding} + * @param candidateBindings candidate bindings that were rejected due to ambiguity or for other + * reasons, may be {@code null} + */ + public ProblemBinding(IASTName name, IASTNode point, int id, IBinding[] candidateBindings) { + this.id = id; + if (name != null && name.getTranslationUnit() != null) { + this.node = name; + } else { + this.node = point; + if (name != null) { + this.arg = name.getSimpleID(); + } else if (candidateBindings != null && candidateBindings.length != 0) { + this.arg = candidateBindings[0].getNameCharArray(); + } + } + this.candidateBindings = candidateBindings; + } + public ProblemBinding(IASTNode node, int id, char[] arg) { this(node, id, arg, null); } @@ -67,8 +97,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I this.node = node; this.candidateBindings = candidateBindings; } - - @Override + + @Override public EScopeKind getKind() { return EScopeKind.eLocal; } @@ -82,34 +112,30 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I public IBinding[] getCandidateBindings() { return candidateBindings != null ? candidateBindings : IBinding.EMPTY_BINDING_ARRAY; } - + public void setCandidateBindings(IBinding[] foundBindings) { candidateBindings= foundBindings; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IProblemBinding#getID() - */ @Override public int getID() { return id; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IProblemBinding#getMessage() - */ + @Override public String getMessage() { - if (message != null) - return message; - String msg = ParserMessages.getProblemPattern(this); if (msg == null) return ""; //$NON-NLS-1$ - - if (arg == null && node instanceof IASTName) - arg= ((IASTName) node).toCharArray(); - + + if (arg == null) { + if (node instanceof IASTName) { + arg= ((IASTName) node).toCharArray(); + } else if (candidateBindings != null && candidateBindings.length != 0) { + arg = candidateBindings[0].getNameCharArray(); + } + } + if (arg != null) { msg = MessageFormat.format(msg, new Object[] { new String(arg) }); } @@ -149,7 +175,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I return getASTNode(); } - + @Override public Object clone() { // Don't clone problems @@ -262,7 +288,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I public ILinkage getLinkage() { return Linkage.NO_LINKAGE; } - + @Override public String toString() { return getMessage(); @@ -291,7 +317,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I } @Override - public void removeNestedFromCache(IASTNode container) {} + public void removeNestedFromCache(IASTNode container) { + } // Dummy methods for derived classes public IType getType() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 52863030731..cdc024cd703 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; @@ -31,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** @@ -48,6 +50,8 @@ public class SizeofCalculator { } } + private static final SizeofCalculator defaultInstance = new SizeofCalculator(); + private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1); public final SizeAndAlignment size_2; @@ -67,7 +71,19 @@ public class SizeofCalculator { public final SizeAndAlignment sizeof_long_double; public final SizeAndAlignment sizeof_complex_long_double; + private final IASTTranslationUnit ast; + + /** + * Returns the default instance of sizeof calculator. The default instance is not aware + * of the parser configuration and can only calculate sizes that are the same across all + * C/C++ implementations. + */ + public static SizeofCalculator getDefault() { + return defaultInstance; + } + public SizeofCalculator(IASTTranslationUnit ast) { + this.ast = ast; int maxAlignment = 32; Map sizeofMacros = new HashMap(); for (IASTPreprocessorMacroDefinition macro : ast.getBuiltinMacroDefinitions()) { @@ -102,6 +118,26 @@ public class SizeofCalculator { sizeof_complex_long_double = getSizeOfPair(sizeof_long_double); } + private SizeofCalculator() { + size_2 = new SizeAndAlignment(2, 2); + size_4 = new SizeAndAlignment(4, 4); + size_8 = new SizeAndAlignment(8, 8); + sizeof_pointer = null; + sizeof_int = null; + sizeof_long = null; + sizeof_long_long = null; + sizeof_short = null; + sizeof_bool = null; + sizeof_wchar_t = null; + sizeof_float = null; + sizeof_complex_float = null; + sizeof_double = null; + sizeof_complex_double = null; + sizeof_long_double = null; + sizeof_complex_long_double = null; + ast = null; + } + /** * Calculates size and alignment for the given type. * @param type the type to get size and alignment for. @@ -109,7 +145,9 @@ public class SizeofCalculator { */ public SizeAndAlignment sizeAndAlignment(IType type) { type = SemanticUtil.getNestedType(type, SemanticUtil.CVTYPE | SemanticUtil.TDEF); - + if (type instanceof IFunctionType) { + return sizeAndAlignment(((IFunctionType) type).getReturnType()); + } if (type instanceof IBasicType) { return sizeAndAlignment((IBasicType) type); } @@ -213,7 +251,7 @@ public class SizeofCalculator { IField[] fields; if (type instanceof ICPPClassType) { ICPPClassType classType = (ICPPClassType) type; - for (ICPPBase base : classType.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(classType, ast)) { if (base.isVirtual()) return null; // Don't know how to calculate size when there are virtual bases. IBinding baseClass = base.getBaseClass(); @@ -225,14 +263,14 @@ public class SizeofCalculator { size += info.alignment - (size - 1) % info.alignment - 1 + info.size; if (maxAlignment < info.alignment) maxAlignment = info.alignment; - for (ICPPMethod method : classType.getDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, ast)) { if (method.isVirtual()) { // Don't know how to calculate size when there are virtual functions. return null; } } } - fields = classType.getDeclaredFields(); + fields = ClassTypeHelper.getDeclaredFields(classType, ast); } else { fields = type.getFields(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 41c7f5bb0b2..44e298d51fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,12 +11,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; @@ -24,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; -import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -32,13 +25,15 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +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.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.EvalBinding; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; import org.eclipse.cdt.internal.core.pdom.db.TypeMarshalBuffer; @@ -50,112 +45,64 @@ import org.eclipse.core.runtime.CoreException; */ public class Value implements IValue { public static final int MAX_RECURSION_DEPTH = 25; - public final static IValue UNKNOWN= new Value("".toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); //$NON-NLS-1$ - public final static IValue NOT_INITIALIZED= new Value("<__>".toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); //$NON-NLS-1$ - private static final int[] NO_INT = {}; + public static final Value UNKNOWN= new Value("".toCharArray(), null); //$NON-NLS-1$ + public static final Value NOT_INITIALIZED= new Value("<__>".toCharArray(), null); //$NON-NLS-1$ - private static final String SCOPE_OP = "::"; //$NON-NLS-1$ private static final char UNIQUE_CHAR = '_'; - private static final char TEMPLATE_PARAM_CHAR = '#'; - private static final char TEMPLATE_PARAM_PACK_CHAR = '`'; - private static final char REFERENCE_CHAR = '&'; - private static final char UNARY_OP_CHAR = '$'; - private static final char BINARY_OP_CHAR = '@'; - private static final char CONDITIONAL_CHAR= '?'; - - private static final char SEPARATOR = ','; private final static IValue[] TYPICAL= { - new Value(new char[] {'0'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'1'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'2'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'3'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'4'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'5'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY), - new Value(new char[] {'6'}, ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY)}; + new Value(new char[] {'0'}, null), + new Value(new char[] {'1'}, null), + new Value(new char[] {'2'}, null), + new Value(new char[] {'3'}, null), + new Value(new char[] {'4'}, null), + new Value(new char[] {'5'}, null), + new Value(new char[] {'6'}, null)}; - private static class Reevaluation { - public final char[] fExpression; - private final int fPackOffset; - public int pos= 0; - public final Map fUnknownSigs; - public final List fUnknowns; - public final IBinding[] fResolvedUnknown; - public final ICPPTemplateParameterMap fMap; - - public Reevaluation(char[] expr, int packOffset, Map unknownSigs, - List unknowns, IBinding[] resolvedUnknowns, ICPPTemplateParameterMap map) { - fExpression= expr; - fPackOffset= packOffset; - fUnknownSigs= unknownSigs; - fUnknowns= unknowns; - fResolvedUnknown= resolvedUnknowns; - fMap= map; - } - - public void nextSeparator() throws UnknownValueException { - final char[] expression = fExpression; - final int len = expression.length; - int idx = pos; - while (idx < len) { - if (expression[idx++] == SEPARATOR) - break; - } - pos= idx; - } - } - private static class UnknownValueException extends Exception {} private static UnknownValueException UNKNOWN_EX= new UnknownValueException(); private static int sUnique= 0; - private final char[] fExpression; - private final ICPPUnknownBinding[] fUnknownBindings; + // The following invariant always holds: (fFixedValue == null) != (fEvaluation == null) + private final char[] fFixedValue; + private final ICPPEvaluation fEvaluation; private char[] fSignature; - private Value(char[] rep, ICPPUnknownBinding[] unknown) { - assert rep != null; - fExpression= rep; - fUnknownBindings= unknown; + private Value(char[] fixedValue, ICPPEvaluation evaluation) { + assert (fixedValue == null) != (evaluation == null); + fFixedValue = fixedValue; + fEvaluation = evaluation; } @Override - public char[] getInternalExpression() { - return fExpression; + public Long numericalValue() { + return fFixedValue == null ? null : parseLong(fFixedValue); } @Override - public IBinding[] getUnknownBindings() { - return fUnknownBindings; + public ICPPEvaluation getEvaluation() { + return fEvaluation; } @Override public char[] getSignature() { if (fSignature == null) { - if (fUnknownBindings.length == 0) { - fSignature= fExpression; - } else { - StringBuilder buf= new StringBuilder(); - buf.append(fExpression); - buf.append('['); - for (int i = 0; i < fUnknownBindings.length; i++) { - if (i > 0) - buf.append(','); - buf.append(getSignatureForUnknown(fUnknownBindings[i])); - } - buf.append(']'); - final int end= buf.length(); - fSignature= new char[end]; - buf.getChars(0, end, fSignature, 0); - } + fSignature = fFixedValue != null ? fFixedValue : fEvaluation.getSignature(); } return fSignature; } + @Deprecated @Override - public Long numericalValue() { - return parseLong(fExpression); + public char[] getInternalExpression() { + return CharArrayUtils.EMPTY_CHAR_ARRAY; + } + + @Deprecated + @Override + public IBinding[] getUnknownBindings() { + return IBinding.EMPTY_BINDING_ARRAY; } public void marshall(ITypeMarshalBuffer buf) throws CoreException { @@ -174,11 +121,7 @@ public class Value implements IValue { } } else { buf.putByte((ITypeMarshalBuffer.VALUE)); - buf.putCharArray(fExpression); - buf.putShort((short) fUnknownBindings.length); - for (ICPPUnknownBinding b : fUnknownBindings) { - buf.marshalBinding(b); - } + fEvaluation.marshal(buf, true); } } } @@ -198,48 +141,26 @@ public class Value implements IValue { return Value.create(val); } - char[] expr = buf.getCharArray(); - final int len= buf.getShort(); - ICPPUnknownBinding[] unknowns= new ICPPUnknownBinding[len]; - for (int i = 0; i < unknowns.length; i++) { - final ICPPUnknownBinding unknown = (ICPPUnknownBinding) buf.unmarshalBinding(); - if (unknown == null) { - return Value.UNKNOWN; - } - unknowns[i]= unknown; - } - return new Value(expr, unknowns); + ISerializableEvaluation eval= buf.unmarshalEvaluation(); + if (eval instanceof ICPPEvaluation) + return new Value(null, (ICPPEvaluation) eval); + return Value.UNKNOWN; } @Override public int hashCode() { - return CharArrayUtils.hash(fExpression); + return CharArrayUtils.hash(getSignature()); } @Override public boolean equals(Object obj) { - if (!(obj instanceof IValue)) { + if (!(obj instanceof Value)) { return false; } - final IValue rhs = (IValue) obj; - if (!CharArrayUtils.equals(fExpression, rhs.getInternalExpression())) - return false; - - IBinding[] rhsUnknowns= rhs.getUnknownBindings(); - if (fUnknownBindings.length != rhsUnknowns.length) - return false; - - for (int i = 0; i < rhsUnknowns.length; i++) { - final IBinding rhsUnknown = rhsUnknowns[i]; - if (rhsUnknown instanceof ICPPUnknownBinding) { - if (!getSignatureForUnknown((ICPPUnknownBinding) rhsUnknown).equals(getSignatureForUnknown(fUnknownBindings[i]))) { - return false; - } - } else { - return false; - } - } - return true; + final Value rhs = (Value) obj; + if (fFixedValue != null) + return CharArrayUtils.equals(fFixedValue, rhs.fFixedValue); + return CharArrayUtils.equals(getSignature(), rhs.getSignature()); } @Override @@ -253,106 +174,79 @@ public class Value implements IValue { public static IValue create(long value) { if (value >=0 && value < TYPICAL.length) return TYPICAL[(int) value]; - return new Value(toCharArray(value), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); + return new Value(toCharArray(value), null); + } + + /** + * Creates a value object representing the given boolean value. + */ + public static IValue create(boolean value) { + return create(value ? 1 : 0); } /** * Creates a value representing the given template parameter. */ public static IValue create(ICPPTemplateNonTypeParameter tntp) { - final String expr = createTemplateParamExpression(tntp.getParameterID(), tntp.isParameterPack()); - return new Value(expr.toCharArray(), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); - } - - private static String createTemplateParamExpression(int id, boolean isPack) { - StringBuilder buf= new StringBuilder(); - buf.append(isPack ? TEMPLATE_PARAM_PACK_CHAR : TEMPLATE_PARAM_CHAR); - buf.append(Integer.toHexString(id)); - return buf.toString(); + EvalBinding eval = new EvalBinding(tntp, null); + return new Value(null, eval); } /** - * Tests whether the value is a template parameter (or parameter pack), - * returns the parameter id of the parameter, or -1 if it is not a template parameter. + * Create a value wrapping the given evaluation. + */ + public static IValue create(ICPPEvaluation eval) { + return new Value(null, eval); + } + + public static IValue evaluateBinaryExpression(final int op, final long v1, final long v2) { + try { + return create(combineBinary(op, v1, v2)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + public static IValue evaluateUnaryExpression(final int unaryOp, final long value) { + try { + return create(combineUnary(unaryOp, value)); + } catch (UnknownValueException e) { + } + return UNKNOWN; + } + + /** + * Tests whether the value is a template parameter (or a parameter pack). + * + * @return the parameter id of the parameter, or -1 if it is not a template + * parameter. */ public static int isTemplateParameter(IValue tval) { - final char[] rep= tval.getInternalExpression(); - if (rep.length > 0) { - final char c = rep[0]; - if (c == TEMPLATE_PARAM_CHAR || c == TEMPLATE_PARAM_PACK_CHAR) { - for (int i = 1; i < rep.length; i++) { - if (rep[i] == SEPARATOR) - return -1; - } - try { - return parseHex(rep, 1); - } catch (UnknownValueException e) { - } + ICPPEvaluation eval = tval.getEvaluation(); + if (eval instanceof EvalBinding) { + IBinding binding = ((EvalBinding) eval).getBinding(); + if (binding instanceof ICPPTemplateParameter) { + return ((ICPPTemplateParameter) binding).getParameterID(); } } return -1; } /** - * Tests whether the value directly references some template parameter. + * Tests whether the value references some template parameter. */ public static boolean referencesTemplateParameter(IValue tval) { - final char[] rep= tval.getInternalExpression(); - for (char element : rep) { - if (element == TEMPLATE_PARAM_CHAR || element == TEMPLATE_PARAM_PACK_CHAR) - return true; - } - return false; + ICPPEvaluation eval = tval.getEvaluation(); + if (eval == null) + return false; + return eval.referencesTemplateParameter(); } /** * Tests whether the value depends on a template parameter. */ public static boolean isDependentValue(IValue nonTypeValue) { - final char[] rep= nonTypeValue.getInternalExpression(); - for (final char c : rep) { - if (c == REFERENCE_CHAR || c == TEMPLATE_PARAM_CHAR || c == TEMPLATE_PARAM_PACK_CHAR) - return true; - } - return false; - } - - /** - * Collects all references to parameter packs. - */ - public static int[] getParameterPackReferences(IValue value) { - final char[] rep= value.getInternalExpression(); - int result= -1; - List array= null; - for (int i=0; i(2); - array.add(result); - } - array.add(ref); - } - } catch (UnknownValueException e) { - } - } - } - if (array != null) { - int[] ra= new int[array.size()]; - for (int i = 0; i < ra.length; i++) { - ra[i]= array.get(i); - } - return ra; - } - if (result != -1) - return new int[] {result}; - - return NO_INT; + return nonTypeValue.getEvaluation() != null; } /** @@ -360,19 +254,14 @@ public class Value implements IValue { */ public static IValue create(IASTExpression expr, int maxRecursionDepth) { try { - Map unknownSigs= new HashMap(); - List unknown= new ArrayList(); - Object obj= evaluate(expr, unknownSigs, unknown, maxRecursionDepth); - if (obj instanceof Number) - return create(((Number) obj).longValue()); + Object obj= evaluate(expr, maxRecursionDepth); + if (obj instanceof Long) + return create(((Long) obj).longValue()); - ICPPUnknownBinding[] ua; - if (unknown.isEmpty()) { - ua= ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY; - } else { - ua= unknown.toArray(new ICPPUnknownBinding[unknown.size()]); + if (expr instanceof ICPPASTInitializerClause) { + ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation(); + return new Value(null, evaluation); } - return new Value(((String)obj).toCharArray(), ua); } catch (UnknownValueException e) { } return UNKNOWN; @@ -381,15 +270,8 @@ public class Value implements IValue { /** * Creates a value off its canonical representation. */ - public static IValue fromInternalRepresentation(char[] rep, ICPPUnknownBinding[] unknown) { - if (CharArrayUtils.equals(rep, UNKNOWN.getInternalExpression())) - return UNKNOWN; - - Long l= parseLong(rep); - if (l != null) - return create(l.longValue()); - - return new Value(rep, unknown); + public static IValue fromInternalRepresentation(ICPPEvaluation evaluation) { + return new Value(null, evaluation); } /** @@ -399,67 +281,59 @@ public class Value implements IValue { StringBuilder buf= new StringBuilder(10); buf.append(UNIQUE_CHAR); buf.append(++sUnique); - return new Value(extractChars(buf), ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY); + return new Value(CharArrayUtils.extractChars(buf), null); } /** * Computes the canonical representation of the value of the expression. - * Returns a {@code Number} for numerical values or a {@code String}, otherwise. + * Returns a {@code Long} for numerical values or {@code null}, otherwise. * @throws UnknownValueException */ - private static Object evaluate(IASTExpression e, Map unknownSigs, - List unknowns, int maxdepth) throws UnknownValueException { - if (maxdepth < 0 || e == null) + private static Long evaluate(IASTExpression exp, int maxdepth) throws UnknownValueException { + if (maxdepth < 0 || exp == null) throw UNKNOWN_EX; - if (e instanceof IASTArraySubscriptExpression) { + if (exp instanceof IASTArraySubscriptExpression) { throw UNKNOWN_EX; } - if (e instanceof IASTBinaryExpression) { - return evaluateBinaryExpression((IASTBinaryExpression) e, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTBinaryExpression) { + return evaluateBinaryExpression((IASTBinaryExpression) exp, maxdepth); } - if (e instanceof IASTCastExpression) { // must be ahead of unary - return evaluate(((IASTCastExpression) e).getOperand(), unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTCastExpression) { // must be ahead of unary + return evaluate(((IASTCastExpression) exp).getOperand(), maxdepth); } - if (e instanceof IASTUnaryExpression) { - return evaluateUnaryExpression((IASTUnaryExpression) e, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTUnaryExpression) { + return evaluateUnaryExpression((IASTUnaryExpression) exp, maxdepth); } - if (e instanceof IASTConditionalExpression) { - IASTConditionalExpression cexpr= (IASTConditionalExpression) e; - Object o= evaluate(cexpr.getLogicalConditionExpression(), unknownSigs, unknowns, maxdepth); - if (o instanceof Number) { - Number v= (Number) o; - if (v.longValue() == 0) { - return evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth); - } - final IASTExpression pe = cexpr.getPositiveResultExpression(); - if (pe == null) // gnu-extension allows to omit the positive expression. - return o; - return evaluate(pe, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTConditionalExpression) { + IASTConditionalExpression cexpr= (IASTConditionalExpression) exp; + Long v= evaluate(cexpr.getLogicalConditionExpression(), maxdepth); + if (v == null) + return null; + if (v.longValue() == 0) { + return evaluate(cexpr.getNegativeResultExpression(), maxdepth); } - final IASTExpression pe = cexpr.getPositiveResultExpression(); - Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth); - Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth); - return "" + CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + //$NON-NLS-1$ - SEPARATOR + neg.toString(); + if (pe == null) // gnu-extension allows to omit the positive expression. + return v; + return evaluate(pe, maxdepth); } - if (e instanceof IASTIdExpression) { - IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding(); - return evaluateBinding(b, unknownSigs, unknowns, maxdepth); + if (exp instanceof IASTIdExpression) { + IBinding b= ((IASTIdExpression) exp).getName().resolvePreBinding(); + return evaluateBinding(b, maxdepth); } - if (e instanceof IASTLiteralExpression) { - IASTLiteralExpression litEx= (IASTLiteralExpression) e; + if (exp instanceof IASTLiteralExpression) { + IASTLiteralExpression litEx= (IASTLiteralExpression) exp; switch (litEx.getKind()) { case IASTLiteralExpression.lk_false: case IASTLiteralExpression.lk_nullptr: - return 0; + return Long.valueOf(0); case IASTLiteralExpression.lk_true: - return 1; + return Long.valueOf(1); case IASTLiteralExpression.lk_integer_constant: try { return ExpressionEvaluator.getNumber(litEx.getValue()); - } catch (EvalException e1) { + } catch (EvalException e) { throw UNKNOWN_EX; } case IASTLiteralExpression.lk_char_constant: @@ -468,18 +342,19 @@ public class Value implements IValue { if (image.length > 1 && image[0] == 'L') return ExpressionEvaluator.getChar(image, 2); return ExpressionEvaluator.getChar(image, 1); - } catch (EvalException e1) { + } catch (EvalException e) { throw UNKNOWN_EX; } } } - if (e instanceof IASTTypeIdExpression) { - IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) e; + if (exp instanceof IASTTypeIdExpression) { + IASTTypeIdExpression typeIdEx = (IASTTypeIdExpression) exp; switch (typeIdEx.getOperator()) { case IASTTypeIdExpression.op_sizeof: - final IType type; ASTTranslationUnit ast = (ASTTranslationUnit) typeIdEx.getTranslationUnit(); - type = ast.createType(typeIdEx.getTypeId()); + final IType type = ast.createType(typeIdEx.getTypeId()); + if (type instanceof ICPPUnknownType) + return null; SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); if (info == null) @@ -493,18 +368,16 @@ public class Value implements IValue { /** * Extract a value off a binding. */ - private static Object evaluateBinding(IBinding b, Map unknownSigs, - List unknowns, int maxdepth) throws UnknownValueException { + private static Long evaluateBinding(IBinding b, int maxdepth) throws UnknownValueException { if (b instanceof IType) { throw UNKNOWN_EX; } if (b instanceof ICPPTemplateNonTypeParameter) { - final ICPPTemplateNonTypeParameter tp = (ICPPTemplateNonTypeParameter) b; - return createTemplateParamExpression(tp.getParameterID(), tp.isParameterPack()); + return null; } if (b instanceof ICPPUnknownBinding) { - return createReference((ICPPUnknownBinding) b, unknownSigs, unknowns); + return null; } IValue value= null; @@ -515,78 +388,24 @@ public class Value implements IValue { } else if (b instanceof IEnumerator) { value= ((IEnumerator) b).getValue(); } - if (value != null) - return evaluateValue(value, unknownSigs, unknowns); + if (value != null && value != Value.UNKNOWN) { + return value.numericalValue(); + } throw UNKNOWN_EX; } - private static Object createReference(ICPPUnknownBinding unknown, - Map unknownSigs, List unknowns) { - String sig= getSignatureForUnknown(unknown); - Integer idx= unknownSigs.get(sig); - if (idx == null) { - idx= unknownSigs.size(); - unknownSigs.put(sig, idx); - unknowns.add(unknown); - } - return "" + REFERENCE_CHAR + idx.toString(); //$NON-NLS-1$ - } - - private static Object evaluateValue(IValue cv, Map unknownSigs, - List unknowns) throws UnknownValueException { - if (cv == Value.UNKNOWN) - throw UNKNOWN_EX; - - Long lv= cv.numericalValue(); - if (lv != null) - return lv; - - final IBinding[] oldUnknowns = cv.getUnknownBindings(); - final char[] expr= cv.getInternalExpression(); - if (oldUnknowns.length == 0) - return new String(expr); - - StringBuilder buf= new StringBuilder(expr.length); - boolean skipToSeparator= false; - for (int i = 0; i < expr.length; i++) { - final char c= expr[i]; - switch (c) { - case REFERENCE_CHAR: { - int idx= parseNonNegative(expr, i + 1); - if (idx >= oldUnknowns.length) - throw UNKNOWN_EX; - final IBinding old = oldUnknowns[idx]; - if (!(old instanceof ICPPUnknownBinding)) - throw UNKNOWN_EX; - - buf.append(createReference((ICPPUnknownBinding) old, unknownSigs, unknowns)); - skipToSeparator= true; - break; - } - case SEPARATOR: - skipToSeparator= false; - buf.append(c); - break; - default: - if (!skipToSeparator) - buf.append(c); - break; - } - } - return buf.toString(); - } - - private static Object evaluateUnaryExpression(IASTUnaryExpression ue, - Map unknownSigs, List unknowns, int maxdepth) + private static Long evaluateUnaryExpression(IASTUnaryExpression exp, int maxdepth) throws UnknownValueException { - final int unaryOp= ue.getOperator(); + final int unaryOp= exp.getOperator(); if (unaryOp == IASTUnaryExpression.op_sizeof) { - final IASTExpression operand = ue.getOperand(); + final IASTExpression operand = exp.getOperand(); if (operand != null) { IType type = operand.getExpressionType(); - ASTTranslationUnit ast = (ASTTranslationUnit) ue.getTranslationUnit(); + if (type instanceof ICPPUnknownType) + return null; + ASTTranslationUnit ast = (ASTTranslationUnit) exp.getTranslationUnit(); SizeofCalculator calculator = ast.getSizeofCalculator(); SizeAndAlignment info = calculator.sizeAndAlignment(type); if (info != null) @@ -600,338 +419,109 @@ public class Value implements IValue { throw UNKNOWN_EX; } - final Object value= evaluate(ue.getOperand(), unknownSigs, unknowns, maxdepth); + final Long value= evaluate(exp.getOperand(), maxdepth); + if (value == null) + return null; return combineUnary(unaryOp, value); } - private static Object combineUnary(final int unaryOp, final Object value) throws UnknownValueException { + private static long combineUnary(final int unaryOp, final long value) throws UnknownValueException { switch (unaryOp) { case IASTUnaryExpression.op_bracketedPrimary: case IASTUnaryExpression.op_plus: return value; } - if (value instanceof Number) { - long v= ((Number) value).longValue(); - switch (unaryOp) { - case IASTUnaryExpression.op_prefixIncr: - case IASTUnaryExpression.op_postFixIncr: - return ++v; - case IASTUnaryExpression.op_prefixDecr: - case IASTUnaryExpression.op_postFixDecr: - return --v; - case IASTUnaryExpression.op_minus: - return -v; - case IASTUnaryExpression.op_tilde: - return ~v; - case IASTUnaryExpression.op_not: - return v == 0 ? 1 : 0; - } - throw UNKNOWN_EX; - } - switch (unaryOp) { case IASTUnaryExpression.op_prefixIncr: case IASTUnaryExpression.op_postFixIncr: + return value + 1; case IASTUnaryExpression.op_prefixDecr: case IASTUnaryExpression.op_postFixDecr: + return value - 1; case IASTUnaryExpression.op_minus: + return -value; case IASTUnaryExpression.op_tilde: + return ~value; case IASTUnaryExpression.op_not: - return "" + UNARY_OP_CHAR + unaryOp + SEPARATOR + value.toString(); //$NON-NLS-1$ + return value == 0 ? 1 : 0; } throw UNKNOWN_EX; } - private static Object evaluateBinaryExpression(IASTBinaryExpression be, - Map unknownSigs, List unknowns, int maxdepth) + private static Long evaluateBinaryExpression(IASTBinaryExpression exp, int maxdepth) throws UnknownValueException { - final Object o1= evaluate(be.getOperand1(), unknownSigs, unknowns, maxdepth); - final Object o2= evaluate(be.getOperand2(), unknownSigs, unknowns, maxdepth); + final int op= exp.getOperator(); + switch (op) { + case IASTBinaryExpression.op_equals: + if (exp.getOperand1().equals(exp.getOperand2())) + return Long.valueOf(1); + break; + case IASTBinaryExpression.op_notequals: + if (exp.getOperand1().equals(exp.getOperand2())) + return Long.valueOf(0); + 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 int op= be.getOperator(); return combineBinary(op, o1, o2); } - private static Object combineBinary(final int op, final Object o1, final Object o2) + private static long combineBinary(final int op, final long v1, final long v2) throws UnknownValueException { - if (o1 instanceof Number && o2 instanceof Number) { - long v1= ((Number) o1).longValue(); - long v2= ((Number) o2).longValue(); - switch (op) { - case IASTBinaryExpression.op_multiply: - return v1 * v2; - case IASTBinaryExpression.op_divide: - if (v2 == 0) - throw UNKNOWN_EX; - return v1 / v2; - case IASTBinaryExpression.op_modulo: - if (v2 == 0) - throw UNKNOWN_EX; - return v1 % v2; - case IASTBinaryExpression.op_plus: - return v1 + v2; - case IASTBinaryExpression.op_minus: - return v1 - v2; - case IASTBinaryExpression.op_shiftLeft: - return v1 << v2; - case IASTBinaryExpression.op_shiftRight: - return v1 >> v2; - case IASTBinaryExpression.op_lessThan: - return v1 < v2 ? 1 : 0; - case IASTBinaryExpression.op_greaterThan: - return v1 > v2 ? 1 : 0; - case IASTBinaryExpression.op_lessEqual: - return v1 <= v2 ? 1 : 0; - case IASTBinaryExpression.op_greaterEqual: - return v1 >= v2 ? 1 : 0; - case IASTBinaryExpression.op_binaryAnd: - return v1 & v2; - case IASTBinaryExpression.op_binaryXor: - return v1 ^ v2; - case IASTBinaryExpression.op_binaryOr: - return v1 | v2; - case IASTBinaryExpression.op_logicalAnd: - return v1 != 0 && v2 != 0 ? 1 : 0; - case IASTBinaryExpression.op_logicalOr: - return v1 != 0 || v2 != 0 ? 1 : 0; - case IASTBinaryExpression.op_equals: - return v1 == v2 ? 1 : 0; - case IASTBinaryExpression.op_notequals: - return v1 != v2 ? 1 : 0; - case IASTBinaryExpression.op_max: - return Math.max(v1, v2); - case IASTBinaryExpression.op_min: - return Math.min(v1, v2); - } - throw UNKNOWN_EX; - } switch (op) { case IASTBinaryExpression.op_multiply: + return v1 * v2; case IASTBinaryExpression.op_divide: + if (v2 == 0) + throw UNKNOWN_EX; + return v1 / v2; case IASTBinaryExpression.op_modulo: + if (v2 == 0) + throw UNKNOWN_EX; + return v1 % v2; case IASTBinaryExpression.op_plus: + return v1 + v2; case IASTBinaryExpression.op_minus: + return v1 - v2; case IASTBinaryExpression.op_shiftLeft: + return v1 << v2; case IASTBinaryExpression.op_shiftRight: + return v1 >> v2; case IASTBinaryExpression.op_lessThan: + return v1 < v2 ? 1 : 0; case IASTBinaryExpression.op_greaterThan: + return v1 > v2 ? 1 : 0; case IASTBinaryExpression.op_lessEqual: + return v1 <= v2 ? 1 : 0; case IASTBinaryExpression.op_greaterEqual: + return v1 >= v2 ? 1 : 0; case IASTBinaryExpression.op_binaryAnd: + return v1 & v2; case IASTBinaryExpression.op_binaryXor: + return v1 ^ v2; case IASTBinaryExpression.op_binaryOr: + return v1 | v2; case IASTBinaryExpression.op_logicalAnd: + return v1 != 0 && v2 != 0 ? 1 : 0; case IASTBinaryExpression.op_logicalOr: - case IASTBinaryExpression.op_max: - case IASTBinaryExpression.op_min: - break; + return v1 != 0 || v2 != 0 ? 1 : 0; case IASTBinaryExpression.op_equals: - if (o1.equals(o2)) - return 1; - break; + return v1 == v2 ? 1 : 0; case IASTBinaryExpression.op_notequals: - if (o1.equals(o2)) - return 0; - break; - default: - throw UNKNOWN_EX; + return v1 != v2 ? 1 : 0; + case IASTBinaryExpression.op_max: + return Math.max(v1, v2); + case IASTBinaryExpression.op_min: + return Math.min(v1, v2); } - - return "" + BINARY_OP_CHAR + op + SEPARATOR + o1.toString() + SEPARATOR + o2.toString(); //$NON-NLS-1$ - } - - public static IValue reevaluate(IValue val, int packOffset, IBinding[] resolvedUnknowns, - ICPPTemplateParameterMap map, int maxdepth) { - try { - Map unknownSigs= new HashMap(); - List unknown= new ArrayList(); - Reevaluation reeval= new Reevaluation(val.getInternalExpression(), packOffset, - unknownSigs, unknown, - resolvedUnknowns, map); - Object obj= reevaluate(reeval, maxdepth); - if (reeval.pos != reeval.fExpression.length) - return UNKNOWN; - - if (obj instanceof Number) - return create(((Number) obj).longValue()); - - ICPPUnknownBinding[] ua; - if (unknown.isEmpty()) { - ua= ICPPUnknownBinding.EMPTY_UNKNOWN_BINDING_ARRAY; - } else { - ua= unknown.toArray(new ICPPUnknownBinding[unknown.size()]); - } - return new Value(((String)obj).toCharArray(), ua); - } catch (UnknownValueException e) { - } - return UNKNOWN; - } - - private static Object reevaluate(Reevaluation reeval, int maxdepth) - throws UnknownValueException { - if (maxdepth < 0) - throw UNKNOWN_EX; - - final int idx= reeval.pos; - final char[] buf= reeval.fExpression; - final int length = buf.length; - if (idx >= length) - throw UNKNOWN_EX; - - final char c= buf[idx]; - switch (c) { - case BINARY_OP_CHAR: - int op= parseNonNegative(buf, idx + 1); - reeval.nextSeparator(); - Object o1= reevaluate(reeval, maxdepth); - Object o2= reevaluate(reeval, maxdepth); - return combineBinary(op, o1, o2); - case UNARY_OP_CHAR: - op= parseNonNegative(buf, idx + 1); - reeval.nextSeparator(); - o1= reevaluate(reeval, maxdepth); - return combineUnary(op, o1); - case CONDITIONAL_CHAR: - reeval.nextSeparator(); - Object cond= reevaluate(reeval, maxdepth); - Object po= reevaluate(reeval, maxdepth); - Object neg= reevaluate(reeval, maxdepth); - if (cond instanceof Number) { - Number v= (Number) cond; - if (v.longValue() == 0) { - return neg; - } - return po; - } - return "" + CONDITIONAL_CHAR + SEPARATOR + cond.toString() + SEPARATOR + //$NON-NLS-1$ - po.toString() + SEPARATOR + neg.toString(); - case REFERENCE_CHAR: - int num= parseNonNegative(buf, idx + 1); - final IBinding[] resolvedUnknowns= reeval.fResolvedUnknown; - if (num >= resolvedUnknowns.length) - throw UNKNOWN_EX; - reeval.nextSeparator(); - return evaluateBinding(resolvedUnknowns[num], reeval.fUnknownSigs, reeval.fUnknowns, maxdepth); - - case TEMPLATE_PARAM_CHAR: - num= parseHex(buf, idx + 1); - reeval.nextSeparator(); - ICPPTemplateArgument arg = reeval.fMap.getArgument(num); - if (arg != null) { - IValue val= arg.getNonTypeValue(); - if (val == null) - throw UNKNOWN_EX; - return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); - } - return createTemplateParamExpression(num, false); - - case TEMPLATE_PARAM_PACK_CHAR: - num= parseHex(buf, idx + 1); - reeval.nextSeparator(); - arg= null; - if (reeval.fPackOffset >= 0) { - ICPPTemplateArgument[] args= reeval.fMap.getPackExpansion(num); - if (args != null && reeval.fPackOffset < args.length) { - arg= args[reeval.fPackOffset]; - } - } - if (arg != null) { - IValue val= arg.getNonTypeValue(); - if (val == null) - throw UNKNOWN_EX; - return evaluateValue(val, reeval.fUnknownSigs, reeval.fUnknowns); - } - return createTemplateParamExpression(num, true); - - default: - reeval.nextSeparator(); - return parseLong(buf, idx); - } - } - - /** - * Parses a non negative int. - */ - private static int parseNonNegative(char[] value, int offset) throws UnknownValueException { - final long maxvalue= Integer.MAX_VALUE/10; - final int len= value.length; - int result = 0; - boolean ok= false; - for (; offset < len; offset++) { - final int digit= (value[offset] - '0'); - if (digit < 0 || digit > 9) - break; - if (result > maxvalue) - return -1; - - result= result * 10 + digit; - ok= true; - } - if (!ok) - throw UNKNOWN_EX; - return result; - } - - /** - * Parses a a hex value. - */ - private static int parseHex(char[] value, int offset) throws UnknownValueException { - int result = 0; - boolean ok= false; - final int len= value.length; - for (; offset < len; offset++) { - int digit= (value[offset] - '0'); - if (digit < 0 || digit > 9) { - digit += '0' - 'a' + 10; - if (digit < 10 || digit > 15) { - digit += 'a' - 'A'; - if (digit < 10 || digit > 15) { - break; - } - } - } - if ((result & 0xf0000000) != 0) - throw UNKNOWN_EX; - - result= (result << 4) + digit; - ok= true; - } - if (!ok) - throw UNKNOWN_EX; - - return result; - } - - /** - * Parses a long. - */ - private static long parseLong(char[] value, int offset) throws UnknownValueException { - final long maxvalue= Long.MAX_VALUE / 10; - final int len= value.length; - boolean negative= false; - long result = 0; - - boolean ok= false; - if (offset < len && value[offset] == '-') { - negative = true; - offset++; - } - for (; offset < len; offset++) { - final int digit= (value[offset] - '0'); - if (digit < 0 || digit > 9) - break; - - if (result > maxvalue) - throw UNKNOWN_EX; - - result= result * 10 + digit; - ok= true; - } - if (!ok) - throw UNKNOWN_EX; - - return negative ? -result : result; + throw UNKNOWN_EX; } /** @@ -963,37 +553,12 @@ public class Value implements IValue { return negative ? -result : result; } - /** - * Computes a signature for an unknown binding. - */ - private static String getSignatureForUnknown(ICPPUnknownBinding binding) { - IBinding owner= binding.getOwner(); - if (owner instanceof IType) { - StringBuilder buf= new StringBuilder(); - ASTTypeUtil.appendType((IType) owner, true, buf); - return buf.append(SCOPE_OP).append(binding.getName()).toString(); - } - return binding.getName(); - } - /** * Converts long to a char array */ private static char[] toCharArray(long value) { StringBuilder buf= new StringBuilder(); buf.append(value); - return extractChars(buf); - } - - private static char[] extractChars(StringBuilder buf) { - final int len = buf.length(); - char[] result= new char[len]; - buf.getChars(0, len, result, 0); - return result; - } - - public static IValue create(ICPPEvaluation eval, IASTNode point) { - // Compute value of evaluation - return Value.UNKNOWN; + return CharArrayUtils.extractChars(buf); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index a90f9f3395a..d9869e70ddc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Devin Steffler (IBM Corporation) - initial API and implementation + * Devin Steffler (IBM Corporation) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -157,7 +157,6 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp return ASTTypeUtil.getType(this); } - @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { int firstByte= ITypeMarshalBuffer.ARRAY_TYPE; @@ -174,14 +173,13 @@ public class CArrayType implements ICArrayType, ITypeContainer, ISerializableTyp firstByte |= ITypeMarshalBuffer.FLAG1; } - val= getSize(); if (val != null) { firstByte |= ITypeMarshalBuffer.FLAG2; Long num= val.numericalValue(); if (num != null) { long l= num; - if (l>=0 && l <= Short.MAX_VALUE) { + if (l >= 0 && l <= Short.MAX_VALUE) { nval= (short) l; firstByte |= ITypeMarshalBuffer.FLAG3; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java index 560c545e08e..5b21be4b3a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 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,9 +10,11 @@ * Markus Schorn (Wind River Systems) * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; @@ -124,19 +126,19 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } @Override - public ICPPBase[] getBases() { + public ICPPBase[] getBases(IASTNode point) { if (fBases == null) { ICPPBase[] result = null; - ICPPBase[] bases = specialClass.getSpecializedBinding().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(specialClass.getSpecializedBinding(), point); if (bases.length == 0) { fBases= bases; } else { - IASTNode point= null; // Instantiation of dependent expression may not work. final ICPPTemplateParameterMap tpmap = specialClass.getTemplateParameterMap(); for (ICPPBase base : bases) { IBinding origClass = base.getBaseClass(); if (origClass instanceof ICPPTemplateParameter && ((ICPPTemplateParameter) origClass).isParameterPack()) { - IType[] specClasses= CPPTemplates.instantiateTypes(new IType[]{new CPPParameterPackType((IType) origClass)}, tpmap, -1, specialClass, point); + IType[] specClasses= CPPTemplates.instantiateTypes(new IType[] { new CPPParameterPackType((IType) origClass) }, + tpmap, -1, specialClass, point); if (specClasses.length == 1 && specClasses[0] instanceof ICPPParameterPackType) { result= ArrayUtil.append(ICPPBase.class, result, base); } else { @@ -182,15 +184,19 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat } @Override - public ICPPField[] getDeclaredFields() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPField[] fields= specialClass.getSpecializedBinding().getDeclaredFields(); + public ICPPField[] getDeclaredFields(IASTNode point) { + ICPPField[] fields= ClassTypeHelper.getDeclaredFields(specialClass.getSpecializedBinding(), point); return specializeMembers(fields, point); } - + @Override public ICPPMethod[] getImplicitMethods() { - IASTNode point= null; // Instantiation of dependent expression may not work. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); + } + + @Override + public ICPPMethod[] getImplicitMethods(IASTNode point) { ICPPClassScope origClassScope= (ICPPClassScope) specialClass.getSpecializedBinding().getCompositeScope(); if (origClassScope == null) { return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -208,30 +214,31 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat @Override public ICPPConstructor[] getConstructors() { - // mstodo need to pass the point of instantiation - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPConstructor[] ctors= specialClass.getSpecializedBinding().getConstructors(); - return specializeMembers(ctors, point); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override - public ICPPMethod[] getDeclaredMethods() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPMethod[] bindings = specialClass.getSpecializedBinding().getDeclaredMethods(); + public ICPPConstructor[] getConstructors(IASTNode point) { + ICPPConstructor[] ctors= ClassTypeHelper.getConstructors(specialClass.getSpecializedBinding(), point); + return specializeMembers(ctors, point); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { + ICPPMethod[] bindings = ClassTypeHelper.getDeclaredMethods(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override - public ICPPClassType[] getNestedClasses() { - IASTNode point= null; // Instantiation of dependent expression may not work. - ICPPClassType[] bindings = specialClass.getSpecializedBinding().getNestedClasses(); + public ICPPClassType[] getNestedClasses(IASTNode point) { + ICPPClassType[] bindings = ClassTypeHelper.getNestedClasses(specialClass.getSpecializedBinding(), point); return specializeMembers(bindings, point); } @Override - public IBinding[] getFriends() { - IASTNode point= null; // Instantiation of dependent expression may not work. - IBinding[] friends = specialClass.getSpecializedBinding().getFriends(); + public IBinding[] getFriends(IASTNode point) { + IBinding[] friends = ClassTypeHelper.getFriends(specialClass.getSpecializedBinding(), point); return specializeMembers(friends, point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java index a07965123db..60e3b2a1a4c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java @@ -35,6 +35,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * For example in the constructor definition
@@ -174,7 +175,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements IBinding method= fdef.getDeclarator().getName().resolveBinding(); if (method instanceof ICPPMethod) { ICPPClassType cls= ((ICPPMethod) method).getClassOwner(); - for (ICPPBase base : cls.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(cls, fdef)) { result.put(base.getBaseClassSpecifierName().getSimpleID()); } return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java index 8a2dff09a33..c2fb4dcb4b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFieldReference.java @@ -53,7 +53,7 @@ public class CPPASTFieldReference extends ASTNode private boolean isDeref; private IASTImplicitName[] implicitNames; private ICPPEvaluation fEvaluation; - + public CPPASTFieldReference() { } @@ -74,11 +74,7 @@ public class CPPASTFieldReference extends ASTNode copy.setFieldOwner(owner == null ? null : owner.copy(style)); copy.isTemplate = isTemplate; copy.isDeref = isDeref; - copy.setOffsetAndLength(this); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } @Override @@ -282,7 +278,7 @@ public class CPPASTFieldReference extends ASTNode if (n instanceof ICPPASTTemplateId) { args= CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) n); } - return new EvalID(ownerEval, qualifier, name.getSimpleID(), false, qualifier != null, args); + return new EvalID(ownerEval, qualifier, name.getSimpleID(), false, true, args); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java index 6ae3b430d93..25fb6187c7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java @@ -13,7 +13,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -40,6 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.LookupData; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; public class CPPASTFunctionCallExpression extends ASTNode implements ICPPASTFunctionCallExpression, IASTAmbiguityParent { @@ -163,7 +167,7 @@ public class CPPASTFunctionCallExpression extends ASTNode } } else { n1.computeOperatorOffsets(functionName, true); - n2.computeOperatorOffsets(fArguments[fArguments.length-1], true); + n2.computeOperatorOffsets(fArguments[fArguments.length - 1], true); } implicitNames = new IASTImplicitName[] { n1, n2 }; @@ -219,8 +223,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } } - - @Override @Deprecated public IASTExpression getParameterExpression() { @@ -269,7 +271,7 @@ public class CPPASTFunctionCallExpression extends ASTNode ICPPClassType cls= (ICPPClassType) t; LookupData data= CPPSemantics.createLookupData(((IASTIdExpression) functionName).getName()); try { - IBinding b= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + IBinding b= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, data.getLookupPoint()), true); if (b instanceof ICPPFunction) return (ICPPFunction) b; } catch (DOMException e) { @@ -296,10 +298,10 @@ public class CPPASTFunctionCallExpression extends ASTNode if (conversion != null) return conversion; - ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length+1]; + ICPPEvaluation[] args= new ICPPEvaluation[fArguments.length + 1]; args[0]= functionName.getEvaluation(); for (int i = 1; i < args.length; i++) { - args[i]= ((ICPPASTExpression) fArguments[i-1]).getEvaluation(); + args[i]= ((ICPPASTExpression) fArguments[i - 1]).getEvaluation(); } return new EvalFunctionCall(args); } @@ -318,7 +320,6 @@ public class CPPASTFunctionCallExpression extends ASTNode } return null; } - @Override public IType getExpressionType() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index 4e86529c2cc..649fdc88797 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -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 @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -17,6 +18,7 @@ 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.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; 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.ICPPASTParameterDeclaration; @@ -32,6 +34,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS IASTAmbiguityParent { private ICPPASTParameterDeclaration[] parameters; private IASTTypeId[] typeIds = NO_EXCEPTION_SPECIFICATION; + private ICPPASTExpression noexceptExpression; private IASTTypeId trailingReturnType; private boolean varArgs; @@ -64,10 +67,16 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS copy.isConst = isConst; copy.isMutable = isMutable; - for (IASTParameterDeclaration param : getParameters()) + for (IASTParameterDeclaration param : getParameters()) { copy.addParameterDeclaration(param == null ? null : param.copy(style)); - for (IASTTypeId typeId : getExceptionSpecification()) + } + for (IASTTypeId typeId : getExceptionSpecification()) { copy.addExceptionSpecificationTypeId(typeId == null ? null : typeId.copy(style)); + } + if (noexceptExpression != null) { + copy.setNoexceptExpression(noexceptExpression == NOEXCEPT_DEFAULT ? + noexceptExpression : (ICPPASTExpression) noexceptExpression.copy(style)); + } if (trailingReturnType != null) { copy.setTrailingReturnType(trailingReturnType.copy(style)); } @@ -160,8 +169,23 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS typeId.setPropertyInParent(EXCEPTION_TYPEID); } } - - @Override + + @Override + public ICPPASTExpression getNoexceptExpression() { + return noexceptExpression; + } + + @Override + public void setNoexceptExpression(ICPPASTExpression expression) { + assertNotFrozen(); + noexceptExpression = expression; + if (expression != null && expression != NOEXCEPT_DEFAULT) { + expression.setParent(this); + expression.setPropertyInParent(NOEXCEPT_EXPRESSION); + } + } + + @Override public IASTTypeId getTrailingReturnType() { return trailingReturnType; } @@ -244,6 +268,11 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS if (!ids[i].accept(action)) return false; } + + if (noexceptExpression != null && noexceptExpression != NOEXCEPT_DEFAULT) { + if (!noexceptExpression.accept(action)) + return false; + } if (trailingReturnType != null && !trailingReturnType.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 68a6a9938aa..b59a06e4189 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -271,14 +271,14 @@ public class CPPASTQualifiedName extends CPPASTNameBase IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces); if (namesPos > 0) { - IBinding binding = names[namesPos-1].resolveBinding(); + IBinding binding = names[namesPos - 1].resolveBinding(); if (binding instanceof ICPPClassType) { ICPPClassType classType = (ICPPClassType) binding; final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration; List filtered = filterClassScopeBindings(classType, bindings, isDeclaration); if (isDeclaration && nameMatches(classType.getNameCharArray(), n.getLookupKey(), isPrefix)) { - ICPPConstructor[] constructors = classType.getConstructors(); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, n); for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) { filtered.add(constructors[i]); @@ -303,7 +303,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase while(scope != null) { if (scope instanceof ICPPClassScope) { ICPPClassType classType = ((ICPPClassScope) scope).getClassType(); - if (SemanticUtil.calculateInheritanceDepth(classType, baseClass) >= 0) { + if (SemanticUtil.calculateInheritanceDepth(classType, baseClass, this) >= 0) { return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 801741e72df..1759cb2165e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -40,8 +40,8 @@ import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent; * C++-specific implementation of a translation-unit. */ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPASTTranslationUnit, IASTAmbiguityParent { - private CPPNamespaceScope fScope = null; - private ICPPNamespace fBinding = null; + private CPPNamespaceScope fScope; + private ICPPNamespace fBinding; private final CPPScopeMapper fScopeMapper= new CPPScopeMapper(this); public CPPASTTranslationUnit() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java index 592255ac337..56aa33d361f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBasicType.java @@ -13,26 +13,30 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.core.runtime.CoreException; /** * Built-in c++ type. */ public class CPPBasicType implements ICPPBasicType, ISerializableType { + private static final int FROM_STRING_LITERAL = 1 << 31; public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null); public static final CPPBasicType NULL_PTR = new CPPBasicType(Kind.eNullPtr, 0, null); private final Kind fKind; private final int fModifiers; - private IASTExpression fExpression; + private Long fAssociatedValue; public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) { if (kind == Kind.eUnspecified) { @@ -46,8 +50,14 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } else { fKind= kind; } + if (expression instanceof IASTLiteralExpression && + ((IASTLiteralExpression) expression).getKind() == IASTLiteralExpression.lk_string_literal) { + qualifiers |= FROM_STRING_LITERAL; + } fModifiers= qualifiers; - fExpression= expression; + if (expression instanceof ICPPASTInitializerClause) { + fAssociatedValue = Value.create(expression, Value.MAX_RECURSION_DEPTH).numericalValue(); + } } public CPPBasicType(Kind kind, int qualifiers) { @@ -113,11 +123,12 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { if (fKind != t.getKind()) return false; + int modifiers = getModifiers(); if (fKind == Kind.eInt) { - //signed int and int are equivalent - return (fModifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED); + // Signed int and int are equivalent. + return (modifiers & ~IS_SIGNED) == (t.getModifiers() & ~IS_SIGNED); } - return fModifiers == t.getModifiers(); + return modifiers == t.getModifiers(); } @Override @@ -161,30 +172,42 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { } @Override - public Object clone() { - IType t = null; + public CPPBasicType clone() { + CPPBasicType t = null; try { - t = (IType) super.clone(); + t = (CPPBasicType) super.clone(); } catch (CloneNotSupportedException e) { - //not going to happen + // Not going to happen. } return t; } - public void setFromExpression(IASTExpression val) { - fExpression = val; + /** + * Sets the numerical value this type was created for. + * + * @param value the numerical value of {@code null} + */ + public final void setAssociatedNumericalValue(Long value) { + fAssociatedValue = value; } /** - * Returns the expression the type was created for, or null. + * Returns the numerical value this type was created for, or {@code null}. */ - public IASTExpression getCreatedFromExpression() { - return fExpression; + public final Long getAssociatedNumericalValue() { + return fAssociatedValue; } - + + /** + * Returns {@code true} if the type was created for a string literal. + */ + public final boolean isFromStringLiteral() { + return (fModifiers & FROM_STRING_LITERAL) != 0; + } + @Override - public int getModifiers() { - return fModifiers; + public final int getModifiers() { + return fModifiers & ~FROM_STRING_LITERAL; } @Override @@ -211,7 +234,7 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { int modifiers= 0; int kind; if (dense) { - kind= (firstByte & (ITypeMarshalBuffer.FLAG4-1))/ITypeMarshalBuffer.FLAG1; + kind= (firstByte & (ITypeMarshalBuffer.FLAG4 - 1)) / ITypeMarshalBuffer.FLAG1; } else { kind= buffer.getByte(); modifiers= buffer.getByte(); @@ -260,6 +283,6 @@ public class CPPBasicType implements ICPPBasicType, ISerializableType { @Override @Deprecated public IASTExpression getValue() { - return fExpression; + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index c1e5df4ee23..58a39f498f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -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 @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.HashSet; import java.util.Set; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -86,7 +87,7 @@ public class CPPClassSpecialization extends CPPSpecialization fInProgress.set(set); } if (!set.add(original)) - return new RecursionResolvingBinding(null, null); + return new RecursionResolvingBinding(point, original.getNameCharArray()); } IBinding result= CPPTemplates.createSpecialization(this, original, point); @@ -122,61 +123,103 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); + } + + @Override + public ICPPBase[] getBases(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getBases(this); - return scope.getBases(); + return scope.getBases(point); } @Override public ICPPField[] getDeclaredFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); + } + + @Override + public ICPPField[] getDeclaredFields(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredFields(this); - return scope.getDeclaredFields(); + return scope.getDeclaredFields(point); } @Override public ICPPMethod[] getDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getDeclaredMethods(this); - return scope.getDeclaredMethods(); + return scope.getDeclaredMethods(point); } @Override public ICPPConstructor[] getConstructors() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); + } + + @Override + public ICPPConstructor[] getConstructors(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getConstructors(this); - return scope.getConstructors(); + return scope.getConstructors(point); } @Override public IBinding[] getFriends() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); + } + + @Override + public IBinding[] getFriends(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getFriends(this); - return scope.getFriends(); + return scope.getFriends(point); } @Override public ICPPClassType[] getNestedClasses() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { ICPPClassSpecializationScope scope= getSpecializationScope(); if (scope == null) return ClassTypeHelper.getNestedClasses(this); - return scope.getNestedClasses(); + return scope.getNestedClasses(point); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override @@ -186,12 +229,24 @@ public class CPPClassSpecialization extends CPPSpecialization @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } /* (non-Javadoc) @@ -226,7 +281,7 @@ public class CPPClassSpecialization extends CPPSpecialization if (getDefinition() != null) return null; - //implicit specialization: must specialize bindings in scope + // Implicit specialization: must specialize bindings in scope. if (specScope == null) { specScope = new CPPClassSpecializationScope(this); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index b03b19a2dd8..e3f11c51f09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index a7aa9075a67..b5093453da0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -159,7 +159,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -169,12 +169,12 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClass @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java index 443fc1218c8..8fbdd440b41 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecializationSpecialization.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -30,8 +30,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; */ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClassSpecialization implements ICPPClassTemplatePartialSpecializationSpecialization, ICPPInternalClassTemplate { - - private ObjectMap instances = null; + private ObjectMap instances; private ICPPDeferredClassInstance fDeferredInstance; private final ICPPClassTemplate fClassTemplate; private final ICPPTemplateArgument[] fArguments; @@ -70,7 +69,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas public synchronized ICPPTemplateInstance[] getAllInstances() { if (instances != null) { ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; - for (int i=0; i < instances.size(); i++) { + for (int i= 0; i < instances.size(); i++) { result[i]= (ICPPTemplateInstance) instances.getAt(i); } return result; @@ -142,7 +141,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas @Override public ICPPTemplateArgument getDefaultArgFromIndex(int paramPos) throws DOMException { - // no default arguments for partial specializations + // No default arguments for partial specializations return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 32e50325a8d..4bdd0ab55ab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -43,7 +43,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { if (fPartialSpecs == null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 08dfc43baae..b6a32c6a886 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -309,7 +309,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override @@ -319,12 +319,12 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 929451e7eff..39b4c496cd9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Niefer (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -23,8 +23,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; * Binding for a specialization of a field. */ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField { - private IType type = null; - private IValue value= null; + private final IType type; + private final IValue value; public CPPFieldSpecialization(IBinding orig, ICPPClassType owner, ICPPTemplateParameterMap tpmap, IType type, IValue value) { @@ -36,7 +36,7 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie private ICPPField getField() { return (ICPPField) getSpecializedBinding(); } - + @Override public int getVisibility() { return getField().getVisibility(); @@ -46,7 +46,7 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie public ICPPClassType getClassOwner() { return getField().getClassOwner(); } - + @Override public IType getType() { return type; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 229f129609a..bf44bc27797 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -194,6 +194,6 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod @Override public IType[] getExceptionSpecification() { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java index a8baca56672..988ae58bccd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -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) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,20 +21,27 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPMethodSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; /** * The specialization of a method in the context of a class-specialization. */ -public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethod { +public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethodSpecialization { - public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, ICPPFunctionType type, IType[] exceptionSpec ) { - super(orig, owner, argMap, type, exceptionSpec ); + public CPPMethodSpecialization(ICPPMethod orig, ICPPClassType owner, ICPPTemplateParameterMap argMap, + ICPPFunctionType type, IType[] exceptionSpec) { + super(orig, owner, argMap, type, exceptionSpec); + } + + @Override + public ICPPMethod getSpecializedBinding() { + return (ICPPMethod) super.getSpecializedBinding(); } @Override public boolean isVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isVirtual(); IASTNode definition = getDefinition(); @@ -58,7 +66,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public int getVisibility() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.getVisibility(); return 0; @@ -80,17 +88,17 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement @Override public boolean isExplicit() { - return ((ICPPMethod) getSpecializedBinding()).isExplicit(); + return getSpecializedBinding().isExplicit(); } @Override public boolean isImplicit() { - return ((ICPPMethod) getSpecializedBinding()).isImplicit(); + return getSpecializedBinding().isImplicit(); } @Override public boolean isPureVirtual() { - ICPPMethod f = (ICPPMethod) getSpecializedBinding(); + ICPPMethod f = getSpecializedBinding(); if (f != null) return f.isPureVirtual(); @@ -98,9 +106,9 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization implement } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index a3246049bbb..8cb4e502d3b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -184,7 +184,7 @@ abstract public class CPPScope implements ICPPASTInternalScope { @Override public IBinding[] getBindings(ScopeLookupData lookup) { IBinding[] result = getBindingsInAST(lookup); - final IASTTranslationUnit tu = lookup.getLookupPoint().getTranslationUnit(); + final IASTTranslationUnit tu = lookup.getTranslationUnit(); if (tu != null) { IIndex index = tu.getIndex(); if (index != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java new file mode 100644 index 00000000000..3c095d5db00 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeArgument.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; + +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalTypeId; +import org.eclipse.core.runtime.Assert; + +/** + * Implementation of non-type template argument, used by AST and index. + */ +public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument { + private final ICPPEvaluation fEvaluation; + + public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation) { + Assert.isNotNull(evaluation); + fEvaluation= evaluation; + } + + public CPPTemplateNonTypeArgument(IValue value, IType type) { + fEvaluation = new EvalFixed(type, PRVALUE, value); + } + + @Override + public boolean isTypeValue() { + return false; + } + + @Override + public boolean isNonTypeValue() { + return true; + } + + @Override + public IType getTypeValue() { + return null; + } + + @Override + public IValue getNonTypeValue() { + return fEvaluation.getValue(null); + } + + @Override + public IType getTypeOfNonTypeValue() { + return fEvaluation.getTypeOrFunctionSet(null); + } + + @Override + public boolean isPackExpansion() { + return fEvaluation.getTypeOrFunctionSet(null) instanceof ICPPParameterPackType; + } + + @Override + public ICPPTemplateArgument getExpansionPattern() { + IType type = fEvaluation.getTypeOrFunctionSet(null); + if (type instanceof ICPPParameterPackType) { + IType t= ((ICPPParameterPackType) type).getType(); + if (t != null) { + ICPPEvaluation evaluation; + if (fEvaluation instanceof EvalFixed) { + EvalFixed fixed = (EvalFixed) fEvaluation; + evaluation = new EvalFixed(t, fixed.getValueCategory(), fixed.getValue()); + } else { + evaluation = new EvalTypeId(t, fEvaluation); + } + return new CPPTemplateNonTypeArgument(evaluation); + } + } + return null; + } + + @Override + public boolean isSameValue(ICPPTemplateArgument arg) { + return getNonTypeValue().equals(arg.getNonTypeValue()); + } + + @Override + public String toString() { + return getNonTypeValue().toString(); + } + + public ICPPEvaluation getEvaluation() { + return fEvaluation; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java index 29f4703398b..a0280dd5359 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java @@ -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 @@ -32,10 +32,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * Binding for a non-type template parameter. */ -public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements - ICPPTemplateNonTypeParameter { - - private IType type = null; +public class CPPTemplateNonTypeParameter extends CPPTemplateParameter + implements ICPPTemplateNonTypeParameter { + private IType type; public CPPTemplateNonTypeParameter(IASTName name) { super(name); @@ -80,9 +79,9 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements d= (IASTExpression) dc; } else if (dc instanceof ICPPASTInitializerList) { ICPPASTInitializerList list= (ICPPASTInitializerList) dc; - switch(list.getSize()) { + switch (list.getSize()) { case 0: - return new CPPTemplateArgument(Value.create(0), getType()); + return new CPPTemplateNonTypeArgument(Value.create(0), getType()); case 1: dc= list.getClauses()[0]; if (dc instanceof IASTExpression) { @@ -96,7 +95,7 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements IValue val= Value.create(d, Value.MAX_RECURSION_DEPTH); IType t= getType(); - return new CPPTemplateArgument(val, t); + return new CPPTemplateNonTypeArgument(val, t); } @Override @@ -123,26 +122,32 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements public boolean isStatic() { return false; } + @Override public boolean isExtern() { return false; } + @Override public boolean isAuto() { return false; } + @Override public boolean isRegister() { return false; } + @Override public IValue getInitialValue() { return null; } + @Override public boolean isExternC() { return false; } + @Override public boolean isMutable() { return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index 67f62f5fe8b..bc070eda26f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -131,7 +131,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement if (d == null) return null; - return new CPPTemplateArgument(d); + return new CPPTemplateTypeArgument(d); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java similarity index 67% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java index a7a33a6a73e..7ec0f62f798 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeArgument.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -17,47 +18,39 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.core.runtime.Assert; /** - * Implementation of template arguments, used by ast and index. + * Implementation of type template arguments, used by AST and index. */ -public class CPPTemplateArgument implements ICPPTemplateArgument { +public class CPPTemplateTypeArgument implements ICPPTemplateArgument { private final IType fType; - private final IValue fValue; - public CPPTemplateArgument(IValue value, IType type) { - Assert.isNotNull(value); - fType= type; - fValue= value; - } - - public CPPTemplateArgument(IType type) { + public CPPTemplateTypeArgument(IType type) { Assert.isNotNull(type); fType= type; - fValue= null; } @Override public boolean isTypeValue() { - return fValue == null; + return true; } @Override public boolean isNonTypeValue() { - return fValue != null; + return false; } @Override public IType getTypeValue() { - return isTypeValue() ? fType : null; + return fType; } @Override public IValue getNonTypeValue() { - return fValue; + return null; } @Override public IType getTypeOfNonTypeValue() { - return isNonTypeValue() ? fType : null; + return null; } @Override @@ -70,10 +63,7 @@ public class CPPTemplateArgument implements ICPPTemplateArgument { if (fType instanceof ICPPParameterPackType) { IType t= ((ICPPParameterPackType) fType).getType(); if (t != null) { - if (fValue != null) { - return new CPPTemplateArgument(fValue, t); - } - return new CPPTemplateArgument(t); + return new CPPTemplateTypeArgument(t); } } return null; @@ -81,16 +71,11 @@ public class CPPTemplateArgument implements ICPPTemplateArgument { @Override public boolean isSameValue(ICPPTemplateArgument arg) { - if (fValue != null) { - return fValue.equals(arg.getNonTypeValue()); - } return fType.isSameType(arg.getTypeValue()); } @Override public String toString() { - if (fValue != null) - return fValue.toString(); return fType.toString(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java index ec47f888fbd..9b2bf75ab72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java @@ -78,7 +78,7 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements if (t == null) return null; - return new CPPTemplateArgument(t); + return new CPPTemplateTypeArgument(t); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index d83258844ef..93a9386f9ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java index 2c0e8bcf8cc..27c8eb90687 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownConstructor.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java index 9221489b2c3..90726a1e0a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java @@ -26,8 +26,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType; * it depends on a template parameter. A compiler would resolve it during instantiation. */ public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunction { - - private static final ICPPFunctionType FUNCTION_TYPE= new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); + private static final ICPPFunctionType FUNCTION_TYPE= + new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY); public static ICPPFunction createForSample(IFunction sample) throws DOMException { if (sample instanceof ICPPConstructor) @@ -36,7 +36,6 @@ public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunctio return new CPPUnknownFunction(sample.getOwner(), sample.getNameCharArray()); } - public CPPUnknownFunction(IBinding owner, char[] name) { super(owner, name); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index bfa9f6b0498..a32d30b02d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -47,9 +47,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.core.runtime.PlatformObject; public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInternalBinding, IInternalVariable { - private IASTName fDefinition = null; - private IASTName fDeclarations[] = null; - private IType fType = null; + private IASTName fDefinition; + private IASTName fDeclarations[]; + private IType fType; private boolean fAllResolved; public CPPVariable(IASTName name) { @@ -59,10 +59,11 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt name = ns[ns.length - 1]; } - if (isDef) + if (isDef) { fDefinition = name; - else + } else { fDeclarations = new IASTName[] { name }; + } // built-in variables supply a null if (name != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index d2b13592b99..3ddeba3b2fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -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 @@ -54,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +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.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; @@ -101,14 +102,14 @@ public class ClassTypeHelper { IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : members) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0) { - resultSet.put(((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding()); + resultSet.put(((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding()); } else { for (IASTDeclarator dtor : dtors) { if (dtor == null) break; @@ -118,9 +119,9 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); + ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) decl).getDeclSpecifier(); if (declSpec.isFriend()) { - IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); + IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator(); dtor= ASTQueries.findInnermostDeclarator(dtor); resultSet.put(dtor.getName().resolveBinding()); } @@ -144,7 +145,7 @@ public class ClassTypeHelper { if (type.isSameType(classType)) { return true; } - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPClassType && type.isSameType((IType) friend)) { return true; } @@ -152,7 +153,7 @@ public class ClassTypeHelper { } else if (binding instanceof ICPPFunction) { type = ((ICPPFunction) binding).getType(); char[] name = binding.getNameCharArray(); - for (IBinding friend : classType.getFriends()) { + for (IBinding friend : getFriends(classType, null)) { if (friend instanceof ICPPFunction && CharArrayUtils.equals(name, friend.getNameCharArray()) && SemanticUtil.isSameOwner(binding.getOwner(), friend.getOwner()) && @@ -217,17 +218,17 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { if (decl instanceof IASTSimpleDeclaration) { - IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); + IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators(); for (IASTDeclarator dtor : dtors) { binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding(); if (binding instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding); } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPField) result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element); @@ -240,27 +241,63 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPField.class, result); } + public static ICPPBase[] getBases(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getBases(point); + return classType.getBases(); + } + + public static ICPPConstructor[] getConstructors(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getConstructors(point); + return classType.getConstructors(); + } + + public static ICPPField[] getDeclaredFields(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredFields(point); + return classType.getDeclaredFields(); + } + + public static ICPPMethod[] getDeclaredMethods(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getDeclaredMethods(point); + return classType.getDeclaredMethods(); + } + + public static IBinding[] getFriends(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getFriends(point); + return classType.getFriends(); + } + + public static ICPPClassType[] getNestedClasses(ICPPClassType classType, IASTNode point) { + if (classType instanceof ICPPClassSpecialization) + return ((ICPPClassSpecialization) classType).getNestedClasses(point); + return classType.getNestedClasses(); + } + /** * Returns all direct and indirect base classes. * @param classType a class * @return An array of visible base classes in arbitrary order. */ - public static ICPPClassType[] getAllBases(ICPPClassType classType) { + public static ICPPClassType[] getAllBases(ICPPClassType classType, IASTNode point) { HashSet result= new HashSet(); result.add(classType); - getAllBases(classType, result); + getAllBases(classType, result, point); result.remove(classType); return result.toArray(new ICPPClassType[result.size()]); } - private static void getAllBases(ICPPClassType classType, HashSet result) { - ICPPBase[] bases= classType.getBases(); + private static void getAllBases(ICPPClassType classType, HashSet result, IASTNode point) { + ICPPBase[] bases= ClassTypeHelper.getBases(classType, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { final ICPPClassType baseClass = (ICPPClassType) b; if (result.add(baseClass)) { - getAllBases(baseClass, result); + getAllBases(baseClass, result, point); } } } @@ -287,25 +324,22 @@ public class ClassTypeHelper { return false; } - public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct) { - ICPPMethod[] methods= ct.getDeclaredMethods(); - ICPPClassType[] bases= getAllBases(ct); + public static ICPPMethod[] getAllDeclaredMethods(ICPPClassType ct, IASTNode point) { + ICPPMethod[] methods= getDeclaredMethods(ct, point); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - methods = ArrayUtil.addAll(ICPPMethod.class, methods, base.getDeclaredMethods()); + methods = ArrayUtil.addAll(ICPPMethod.class, methods, getDeclaredMethods(base, point)); } return ArrayUtil.trim(ICPPMethod.class, methods); } - public static ICPPMethod[] getMethods(ICPPClassType ct) { - ObjectSet set = getOwnMethods(ct); + public static ICPPMethod[] getMethods(ICPPClassType ct, IASTNode point) { + ObjectSet set = getOwnMethods(ct, point); - ICPPClassType[] bases= getAllBases(ct); + ICPPClassType[] bases= getAllBases(ct, point); for (ICPPClassType base : bases) { - set.addAll(base.getDeclaredMethods()); - final IScope compositeScope = base.getCompositeScope(); - if (compositeScope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) compositeScope).getImplicitMethods()); - } + set.addAll(getDeclaredMethods(base, point)); + set.addAll(getImplicitMethods(base, point)); } return set.keyArray(ICPPMethod.class); } @@ -314,16 +348,23 @@ public class ClassTypeHelper { * Returns methods either declared by the given class or generated by the compiler. Does not * include methods declared in base classes. */ - private static ObjectSet getOwnMethods(ICPPClassType classType) { + private static ObjectSet getOwnMethods(ICPPClassType classType, IASTNode point) { ObjectSet set= new ObjectSet(4); - set.addAll(classType.getDeclaredMethods()); - IScope scope = classType.getCompositeScope(); - if (scope instanceof ICPPClassScope) { - set.addAll(((ICPPClassScope) scope).getImplicitMethods()); - } + set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point)); + set.addAll(getImplicitMethods(classType, point)); return set; } + public static ICPPMethod[] getImplicitMethods(ICPPClassType classType, IASTNode point) { + IScope scope = classType.getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getImplicitMethods(point); + } else if (scope instanceof ICPPClassScope) { + return ((ICPPClassScope) scope).getImplicitMethods(); + } + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + public static ICPPMethod[] getDeclaredMethods(ICPPInternalClassTypeMixinHost host) { if (host.getDefinition() == null) { host.checkForDefinition(); @@ -341,9 +382,9 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { - final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration)decl; + final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl; if (!((ICPPASTDeclSpecifier) sdecl.getDeclSpecifier()).isFriend()) { IASTDeclarator[] dtors = sdecl.getDeclarators(); for (IASTDeclarator dtor : dtors) { @@ -353,7 +394,7 @@ public class ClassTypeHelper { } } } else if (decl instanceof IASTFunctionDefinition) { - final IASTFunctionDefinition fdef = (IASTFunctionDefinition)decl; + final IASTFunctionDefinition fdef = (IASTFunctionDefinition) decl; if (!((ICPPASTDeclSpecifier) fdef.getDeclSpecifier()).isFriend()) { IASTDeclarator dtor = fdef.getDeclarator(); dtor = ASTQueries.findInnermostDeclarator(dtor); @@ -363,10 +404,10 @@ public class ClassTypeHelper { } } } else if (decl instanceof ICPPASTUsingDeclaration) { - IASTName n = ((ICPPASTUsingDeclaration)decl).getName(); + IASTName n = ((ICPPASTUsingDeclaration) decl).getName(); binding = n.resolveBinding(); if (binding instanceof ICPPUsingDeclaration) { - IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates(); + IBinding[] bs = ((ICPPUsingDeclaration) binding).getDelegates(); for (IBinding element : bs) { if (element instanceof ICPPMethod) result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element); @@ -407,15 +448,15 @@ public class ClassTypeHelper { IASTDeclaration[] decls = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : decls) { while (decl instanceof ICPPASTTemplateDeclaration) - decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration(); + decl = ((ICPPASTTemplateDeclaration) decl).getDeclaration(); if (decl instanceof IASTSimpleDeclaration) { IBinding binding = null; IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) decl).getDeclSpecifier(); if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { - binding = ((ICPPASTCompositeTypeSpecifier)declSpec).getName().resolveBinding(); + binding = ((ICPPASTCompositeTypeSpecifier) declSpec).getName().resolveBinding(); } else if (declSpec instanceof ICPPASTElaboratedTypeSpecifier && - ((IASTSimpleDeclaration)decl).getDeclarators().length == 0) { - binding = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding(); + ((IASTSimpleDeclaration) decl).getDeclarators().length == 0) { + binding = ((ICPPASTElaboratedTypeSpecifier) declSpec).getName().resolveBinding(); } if (binding instanceof ICPPClassType) result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding); @@ -424,11 +465,11 @@ public class ClassTypeHelper { return ArrayUtil.trim(ICPPClassType.class, result); } - public static IField[] getFields(ICPPClassType ct) { - IField[] fields = ct.getDeclaredFields(); - ICPPClassType[] bases = getAllBases(ct); + public static IField[] getFields(ICPPClassType ct, IASTNode point) { + IField[] fields = getDeclaredFields(ct, point); + ICPPClassType[] bases = getAllBases(ct, point); for (ICPPClassType base : bases) { - fields = ArrayUtil.addAll(IField.class, fields, base.getDeclaredFields()); + fields = ArrayUtil.addAll(IField.class, fields, getDeclaredFields(base, point)); } return ArrayUtil.trim(IField.class, fields); } @@ -464,7 +505,8 @@ public class ClassTypeHelper { final ICPPClassType mcl= m.getClassOwner(); if (mcl != null) { final ICPPFunctionType mft= m.getType(); - ICPPMethod[] allMethods= mcl.getMethods(); + IASTNode point = null; // Instantiation of dependent expressions may not work + ICPPMethod[] allMethods= ClassTypeHelper.getMethods(mcl, point); for (ICPPMethod method : allMethods) { if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft, method.getType())) { if (method.isVirtual()) { @@ -520,7 +562,7 @@ public class ClassTypeHelper { if (sourceClass == null || targetClass == null) return false; - ICPPClassType[] bases= getAllBases(sourceClass); + ICPPClassType[] bases= getAllBases(sourceClass, null); for (ICPPClassType base : bases) { if (base.isSameType(targetClass)) return true; @@ -532,7 +574,7 @@ public class ClassTypeHelper { /** * Returns all methods that are overridden by the given {@code method}. */ - public static ICPPMethod[] findOverridden(ICPPMethod method) { + public static ICPPMethod[] findOverridden(ICPPMethod method, IASTNode point) { if (method instanceof ICPPConstructor) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; @@ -546,7 +588,7 @@ public class ClassTypeHelper { final ICPPFunctionType mft= method.getType(); virtualInClass.put(mcl, method.isVirtual()); - ICPPBase[] bases= mcl.getBases(); + ICPPBase[] bases= getBases(mcl, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { @@ -681,10 +723,10 @@ public class ClassTypeHelper { /** * For implicit methods the exception specification is inherited, search it */ - public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod) { + public static IType[] getInheritedExceptionSpecification(ICPPMethod implicitMethod, IASTNode point) { // See 15.4.13 ICPPClassType owner= implicitMethod.getClassOwner(); - if (owner == null || owner.getBases().length == 0) + if (owner == null || ClassTypeHelper.getBases(owner, point).length == 0) return null; // we use a list as types aren't comparable, and can have duplicates (15.4.6) @@ -693,10 +735,10 @@ public class ClassTypeHelper { return null; List inheritedTypeids = new ArrayList(); - ICPPClassType[] bases= getAllBases(owner); + ICPPClassType[] bases= getAllBases(owner, point); for (ICPPClassType base : bases) { if (!(base instanceof ICPPDeferredClassInstance)) { - ICPPMethod baseMethod= getMethodInClass(base, kind); + ICPPMethod baseMethod= getMethodInClass(base, kind, point); if (baseMethod != null) { IType[] baseExceptionSpec= baseMethod.getExceptionSpecification(); if (baseExceptionSpec == null) @@ -759,17 +801,17 @@ public class ClassTypeHelper { return false; } - private static ICPPMethod getMethodInClass(ICPPClassType ct, int kind) { + private static ICPPMethod getMethodInClass(ICPPClassType ct, int kind, IASTNode point) { switch (kind) { case KIND_DEFAULT_CTOR: case KIND_COPY_CTOR: - for (ICPPConstructor ctor : ct.getConstructors()) { + for (ICPPConstructor ctor : getConstructors(ct, point)) { if (!ctor.isImplicit() && getImplicitMethodKind(ct, ctor) == kind) return ctor; } return null; case KIND_ASSIGNMENT_OP: - for (ICPPMethod method : ct.getDeclaredMethods()) { + for (ICPPMethod method : getDeclaredMethods(ct, point)) { if (method instanceof ICPPConstructor) continue; if (getImplicitMethodKind(ct, method) == kind) @@ -777,7 +819,7 @@ public class ClassTypeHelper { } return null; case KIND_DTOR: - for (ICPPMethod method : ct.getDeclaredMethods()) { + for (ICPPMethod method : getDeclaredMethods(ct, point)) { if (method.isDestructor()) return method; } @@ -792,10 +834,10 @@ public class ClassTypeHelper { * no private or protected non-static data members (Clause 11), * no base classes (Clause 10), and no virtual functions (10.3). */ - public static boolean isAggregateClass(ICPPClassType classTarget) { - if (classTarget.getBases().length > 0) + public static boolean isAggregateClass(ICPPClassType classTarget, IASTNode point) { + if (ClassTypeHelper.getBases(classTarget, point).length > 0) return false; - ICPPMethod[] methods = classTarget.getDeclaredMethods(); + ICPPMethod[] methods = ClassTypeHelper.getDeclaredMethods(classTarget, point); for (ICPPMethod m : methods) { if (m instanceof ICPPConstructor) return false; @@ -803,7 +845,7 @@ public class ClassTypeHelper { return false; } } - ICPPField[] fields = classTarget.getDeclaredFields(); + ICPPField[] fields = ClassTypeHelper.getDeclaredFields(classTarget, point); for (ICPPField field : fields) { if (!(field.getVisibility() == ICPPMember.v_public || field.isStatic())) { return false; @@ -828,7 +870,7 @@ public class ClassTypeHelper { * @param classTarget the class to check * @return true if the class has a trivial copy constructor */ - public static boolean hasTrivialCopyCtor(ICPPClassType classTarget) { + public static boolean hasTrivialCopyCtor(ICPPClassType classTarget, IASTNode point) { if (getImplicitCopyCtor(classTarget) == null) return false; if (isPolymorphic(classTarget)) @@ -837,8 +879,8 @@ public class ClassTypeHelper { if (base.isVirtual()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass)) + for (ICPPClassType baseClass : getAllBases(classTarget, point)) { + if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass, point)) return false; } for (ICPPField field : classTarget.getDeclaredFields()) { @@ -846,7 +888,7 @@ public class ClassTypeHelper { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialCopyCtor((ICPPClassType) type)) { + !hasTrivialCopyCtor((ICPPClassType) type, point)) { return false; } } @@ -882,23 +924,24 @@ public class ClassTypeHelper { * Similar to std::tr1::has_trivial_default_constructor. * * @param classTarget the class to check + * @param point * @return true if the class has a trivial default constructor */ - public static boolean hasTrivialDefaultConstructor(ICPPClassType classTarget) { - for (ICPPConstructor ctor : classTarget.getConstructors()) { + public static boolean hasTrivialDefaultConstructor(ICPPClassType classTarget, IASTNode point) { + for (ICPPConstructor ctor : getConstructors(classTarget, point)) { if (!ctor.isImplicit() && ctor.getParameters().length == 0) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass)) + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { + if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point)) return false; } - for (ICPPField field : classTarget.getDeclaredFields()) { + for (ICPPField field : getDeclaredFields(classTarget, point)) { if (!field.isStatic()) { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialDefaultConstructor((ICPPClassType) type)) { + !hasTrivialDefaultConstructor((ICPPClassType) type, point)) { return false; } } @@ -920,21 +963,21 @@ public class ClassTypeHelper { * @param classTarget the class to check * @return true if the class has a trivial destructor */ - public static boolean hasTrivialDestructor(ICPPClassType classTarget) { - for (ICPPMethod method : classTarget.getDeclaredMethods()) { + public static boolean hasTrivialDestructor(ICPPClassType classTarget, IASTNode point) { + for (ICPPMethod method : getDeclaredMethods(classTarget, point)) { if (method.isDestructor()) return false; } - for (ICPPClassType baseClass : getAllBases(classTarget)) { - if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass)) + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { + if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass, point)) return false; } - for (ICPPField field : classTarget.getDeclaredFields()) { + for (ICPPField field : getDeclaredFields(classTarget, point)) { if (!field.isStatic()) { IType type = field.getType(); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY); if (type instanceof ICPPClassType && !classTarget.isSameType(type) && - !hasTrivialDestructor((ICPPClassType) type)) { + !hasTrivialDestructor((ICPPClassType) type, point)) { return false; } } @@ -952,7 +995,7 @@ public class ClassTypeHelper { public static boolean isPolymorphic(ICPPClassType classTarget) { if (hasDeclaredVirtualMethod(classTarget)) return true; - for (ICPPClassType baseClass : getAllBases(classTarget)) { + for (ICPPClassType baseClass : getAllBases(classTarget, null)) { if (hasDeclaredVirtualMethod(baseClass)) return true; } @@ -976,9 +1019,9 @@ public class ClassTypeHelper { * but doesn't take into account base classes and methods dependent on unspecified * template parameters. */ - public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) { + public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType, IASTNode point) { Map> result= collectPureVirtualMethods(classType, - new HashMap>>()); + new HashMap>>(), point); int resultArraySize = 0; for (List methods : result.values()) { @@ -995,7 +1038,7 @@ public class ClassTypeHelper { } private static Map> collectPureVirtualMethods(ICPPClassType classType, - Map>> cache) { + Map>> cache, IASTNode point) { Map> result = cache.get(classType); if (result != null) return result; @@ -1005,10 +1048,10 @@ public class ClassTypeHelper { // Look at the pure virtual methods of the base classes Set handledBaseClasses= new HashSet(); - for (ICPPBase base : classType.getBases()) { + for (ICPPBase base : ClassTypeHelper.getBases(classType, point)) { final IBinding baseClass = base.getBaseClass(); if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) { - Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache); + Map> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache, point); // Merge derived pure virtual methods for (String key : pureVirtuals.keySet()) { List list = result.get(key); @@ -1021,8 +1064,8 @@ public class ClassTypeHelper { } } - // Remove overridden pure-virtual methods and add in new pure virutals. - final ObjectSet methods = getOwnMethods(classType); + // Remove overridden pure-virtual methods and add in new pure virtuals. + final ObjectSet methods = getOwnMethods(classType, point); for (ICPPMethod method : methods) { String key= getMethodNameForOverrideKey(method); List list = result.get(key); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index e4634d81fb0..de1972896ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -13,6 +13,7 @@ * Mike Kucera (IBM) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -80,6 +81,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement; @@ -165,26 +167,25 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private final IIndex index; protected ICPPASTTranslationUnit translationUnit; - private int functionBodyCount= 0; + private int functionBodyCount; private char[] currentClassName; private final ICPPNodeFactory nodeFactory; private TemplateIdStrategy fTemplateParameterListStrategy; - + public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, ICPPParserExtensionConfiguration config) { this(scanner, mode, log, config, null); } - public GNUCPPSourceParser(IScanner scanner, ParserMode mode, - IParserLogService log, ICPPParserExtensionConfiguration config, - IIndex index) { + public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, + ICPPParserExtensionConfiguration config, IIndex index) { super(scanner, log, mode, CPPNodeFactory.getDefault(), config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), - config.supportAlignOfUnaryExpression(), + config.supportTypeofUnaryExpressions(), + config.supportAlignOfUnaryExpression(), config.supportKnRC(), - config.supportAttributeSpecifiers(), + config.supportAttributeSpecifiers(), config.supportDeclspecSpecifiers(), config.getBuiltinBindingsProvider()); allowCPPRestrict = config.allowRestrictPointerOperators(); @@ -210,7 +211,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw backtrack; } - + private IASTName qualifiedName() throws BacktrackException, EndOfFileException { return ambiguousQualifiedName(CastExprCtx.eNotInBExpr); } @@ -218,7 +219,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTName ambiguousQualifiedName(CastExprCtx ctx) throws BacktrackException, EndOfFileException { TemplateIdStrategy strat= new TemplateIdStrategy(); IToken m= mark(); - for(;;) { + while (true) { try { return qualifiedName(ctx, strat); } catch (BacktrackException e) { @@ -237,7 +238,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTName qualifiedName(CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException { if (strat == null) return ambiguousQualifiedName(ctx); - + ICPPASTQualifiedName qname= null; IASTName name= null; final int offset= LA(1).getOffset(); @@ -250,9 +251,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { boolean mustBeLast= false; boolean haveName= false; - loop: for(;;) { + loop: while (true) { boolean keywordTemplate= false; - if (qname != null && LT(1) == IToken.t_template) { + if (qname != null && LT(1) == IToken.t_template) { consume(); keywordTemplate= true; } @@ -270,7 +271,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken nt= consume(); name = buildName(destructorOffset, nt); break; - + case IToken.t_operator: name= operatorId(); break; @@ -287,7 +288,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } haveName= true; - + // Check for template-id if (LTcatchEOF(1) == IToken.tLT) { final boolean inBinaryExpression = ctx != CastExprCtx.eNotInBExpr; @@ -303,7 +304,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (templateID) { if (haveArgs == -1) throwBacktrack(LA(1)); - + name= addTemplateArguments(name, strat); } } @@ -362,7 +363,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken end= LA(1); switch (end.getType()) { case IToken.tGT_in_SHIFTR: - case IToken.tGT: + case IToken.tGT: consume(); break; case IToken.tEOC: @@ -389,7 +390,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } /** - * Makes a fast check whether there could be template arguments. + * Makes a fast check whether there could be template arguments. * -1: no, 0: ambiguous, 1: yes */ private static final int NO_TEMPLATE_ID= -1; @@ -409,53 +410,53 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tEOC: case IToken.tCOMPLETION: return AMBIGUOUS_TEMPLATE_ID; - + case IToken.tLT: if (nk == 0) { angleDepth++; } break; case IToken.tGT_in_SHIFTR: - case IToken.tGT: + case IToken.tGT: if (nk == 0) { --angleDepth; if (!inBinaryExpression) return angleDepth == 0 ? TEMPLATE_ID : AMBIGUOUS_TEMPLATE_ID; - + int end= endsTemplateIDInBinaryExpression(); if (end == NO_TEMPLATE_ID) { if (angleDepth == 0) return NO_TEMPLATE_ID; } else { return AMBIGUOUS_TEMPLATE_ID; - } + } } break; - case IToken.tLBRACKET: + case IToken.tLBRACKET: if (nk == 0) { nk= IToken.tLBRACKET; depth= 0; } else if (nk == IToken.tLBRACKET) { depth++; - } + } break; - case IToken.tRBRACKET: + case IToken.tRBRACKET: if (nk == IToken.tLBRACKET) { if (--depth < 0) { nk= 0; } } break; - case IToken.tLPAREN: + case IToken.tLPAREN: if (nk == 0) { nk= IToken.tLPAREN; depth= 0; } else if (nk == IToken.tLPAREN) { depth++; - } + } break; - case IToken.tRPAREN: + case IToken.tRPAREN: if (nk == IToken.tLPAREN) { if (--depth < 0) { nk= 0; @@ -476,9 +477,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); } } - + /** - * If '>' is followed by an expression, then it denotes the binary operator, + * If '>' is followed by an expression, then it denotes the binary operator, * else it is the end of a template-id, or special-cast. */ private int endsTemplateIDInBinaryExpression() { @@ -493,10 +494,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return AMBIGUOUS_TEMPLATE_ID; // Start of unary expression - case IToken.tMINUS: - case IToken.tPLUS: - case IToken.tAMPER: - case IToken.tSTAR: + case IToken.tMINUS: + case IToken.tPLUS: + case IToken.tAMPER: + case IToken.tSTAR: case IToken.tNOT: case IToken.tBITCOMPLEMENT: case IToken.tINCR: @@ -506,7 +507,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_sizeof: case IGCCToken.t___alignof__: return NO_TEMPLATE_ID; - + // Start of a postfix expression case IToken.t_typename: case IToken.t_char: @@ -527,7 +528,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_const_cast: case IToken.t_typeid: return NO_TEMPLATE_ID; - + // Start of a primary expression case IToken.tINTEGER: case IToken.tFLOATINGPT: @@ -546,7 +547,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_operator: case IToken.tCOMPLETION: return NO_TEMPLATE_ID; - + // Tokens that end an expression case IToken.tSEMI: case IToken.tCOMMA: @@ -565,8 +566,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tGT_in_SHIFTR: case IToken.tEQUAL: return TEMPLATE_ID; - - default: + + default: return AMBIGUOUS_TEMPLATE_ID; } } @@ -587,7 +588,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { needComma= true; } - + IASTNode node= templateArgument(strat); if (list == null) { list= new ArrayList(); @@ -616,7 +617,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { || lt1 == IToken.tEOC || lt1 == IToken.tELLIPSIS)) { // This is potentially a type-id, now check ambiguity with id-expression IASTDeclSpecifier declspec= typeId.getDeclSpecifier(); - if (declspec instanceof IASTNamedTypeSpecifier) { + if (declspec instanceof IASTNamedTypeSpecifier) { final IASTNamedTypeSpecifier namedDeclspec = (IASTNamedTypeSpecifier) declspec; IASTName name= namedDeclspec.getName(); if (name.contains(typeId)) { @@ -652,7 +653,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return typeId; } - + // Not a type-id, parse as expression backup(argStart); IASTExpression expr= expression(ExprKind.eAssignment, BinaryExprCtx.eInTemplateID, null, strat); @@ -682,12 +683,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { switch (lt1) { case IToken.tLPAREN: op = OverloadableOperator.PAREN; // operator () - consume(); + consume(); endOffset = consume(IToken.tRPAREN).getEndOffset(); break; case IToken.tLBRACKET: op = OverloadableOperator.BRACKET; // operator [] - consume(); + consume(); endOffset = consume(IToken.tRBRACKET).getEndOffset(); break; case IToken.t_new: @@ -714,8 +715,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset= consume().getEndOffset(); } break; - } - + } + if (op != null) { IASTName name= nodeFactory.newOperatorName(op.toCharArray()); setRange(name, firstToken.getOffset(), endOffset); @@ -750,17 +751,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTExpression expression(final ExprKind kind, final BinaryExprCtx ctx, IASTInitializerClause expr, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { final boolean allowComma= kind==ExprKind.eExpression; boolean allowAssignment= kind !=ExprKind.eConstant; - + if (allowAssignment && LT(1) == IToken.t_throw) { return throwExpression(); - } + } final int startOffset= expr != null ? ((ASTNode) expr).getOffset() : LA(1).getOffset(); int lt1; int conditionCount= 0; BinaryOperator lastOperator= null; NameOrTemplateIDVariants variants= null; - + if (expr == null) { Object e = castExpressionForBinaryExpression(strat); if (e instanceof IASTExpression) { @@ -780,7 +781,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { boolean allowThrow= false; // Brace initializers are allowed on the right hand side of an expression boolean allowBraceInitializer= false; - + BacktrackException tryRecovery= null; final int operatorOffset= LA().getOffset(); lt1= LT(1); @@ -789,7 +790,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { conditionCount++; // ? : // Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 25, 0); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 25, 0); allowAssignment= true; // assignment expressions will be subsumed by the conditional expression allowThrow= true; break; @@ -799,13 +800,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; } else { // ? : - // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 0, 15); + // Precedence: 0 is lower than precedence of expression; 15 is lower than precedence of assignment; + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 0, 15); allowAssignment= true; // assignment expressions will be subsumed by the conditional expression allowThrow= true; } break; - + case IToken.tCOMMA: allowThrow= true; if (!allowComma && conditionCount == 0) { @@ -831,13 +832,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; } else { // Assignments group right to left - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20); allowBraceInitializer= true; } break; case IToken.tOR: - lastOperator= new BinaryOperator(lastOperator, expr, lt1, 30, 31); + lastOperator= new BinaryOperator(lastOperator, expr, lt1, 30, 31); break; case IToken.tAND: lastOperator= new BinaryOperator(lastOperator, expr, lt1, 40, 41); @@ -878,8 +879,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backtrack.initialize(token.getOffset(), token.getLength()); tryRecovery= backtrack; break; - } - + } + lt1= IToken.tSHIFTR; // convert back consume(); // consume the extra token //$FALL-THROUGH$ @@ -904,19 +905,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { doneExpression= true; break; } - + if (!doneExpression && tryRecovery == null) { consume(); // consumes the operator - + // Link variants that are closed by the new operator if (variants != null) { variants.closeVariants(operatorOffset, lastOperator); } - + // Determine next sub-expression if (lt1 == IToken.tQUESTION && LT(1) == IToken.tCOLON) { // Missing sub-expression after '?' (gnu-extension) - expr= null; + expr= null; } else if (allowThrow && LT(1) == IToken.t_throw) { // Throw expression expr= throwExpression(); @@ -939,20 +940,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { final Variant ae = (Variant) e; expr= ae.getExpression(); - if (variants == null) + if (variants == null) variants= new NameOrTemplateIDVariants(); - + variants.addBranchPoint(ae.getNext(), lastOperator, allowAssignment, conditionCount); } } catch (BacktrackException e) { - if (variants == null) + if (variants == null) throw e; tryRecovery= e; backup(m); } } } - + if (tryRecovery != null || doneExpression) { if (variants != null) { if (lt1 == IToken.tEOC) { @@ -961,7 +962,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Try fall-back to an open variant Variant fallback= variants.findFallback(operatorOffset); if (fallback == null) { - if (tryRecovery != null) + if (tryRecovery != null) throw tryRecovery; variants.discardOpenVariants(operatorOffset); } else { @@ -982,7 +983,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } } - } + } } while (!doneExpression); // Check for incomplete conditional expression @@ -994,7 +995,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(result, startOffset, calculateEndOffset(expr)); return result; } - + return buildExpression(lastOperator, expr); } @@ -1003,15 +1004,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (s != null) { return castExpression(CastExprCtx.eDirectlyInBExpr, s); } - + TemplateIdStrategy strat= new TemplateIdStrategy(); Variant variants= null; IASTExpression singleExpression= null; IASTName[] firstNames= null; - + final IToken mark= mark(); IToken lastToken= null; - for(;;) { + while (true) { try { IASTExpression e = castExpression(CastExprCtx.eDirectlyInBExpr, strat); if (variants == null) { @@ -1027,15 +1028,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { lastToken= LA(); if (variants != null) { variants = new Variant(variants, e, strat.getTemplateNames(), lastToken.getOffset()); - } + } if (!strat.setNextAlternative()) { break; } } catch (BacktrackException e) { if (!strat.setNextAlternative()) { - if (lastToken == null) + if (lastToken == null) throw e; - + backup(lastToken); break; } @@ -1045,7 +1046,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return variants != null ? variants : singleExpression; } - @Override protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) { IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2); @@ -1063,8 +1063,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(throwToken); consume(); } - int o = throwExpression != null ? calculateEndOffset(throwExpression) - : throwToken.getEndOffset(); + int o = throwExpression != null ? + calculateEndOffset(throwExpression) : throwToken.getEndOffset(); return buildUnaryExpression(ICPPASTUnaryExpression.op_throw, throwExpression, throwToken.getOffset(), o); // fix for 95225 } @@ -1095,7 +1095,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return deleteExpression; } - /** * Parse a new-expression. There is room for ambiguities. With P for placement, T for typeid, * and I for initializer the potential patterns (with the new omitted) are: @@ -1126,11 +1125,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { plcmt= expressionList(); endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - + final int lt1= LT(1); if (lt1 == IToken.tEOC) { return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); - } + } if (lt1 == IToken.tLPAREN) { // (P)(T) ... isNewTypeId= false; @@ -1153,8 +1152,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int lt1= LT(1); if (lt1 == IToken.tEOC) return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); - - if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { + + if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { init= bracedOrCtorStyleInitializer(); endOffset= calculateEndOffset(init); return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset); @@ -1169,13 +1168,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { typeid2= typeId(DeclarationOptions.TYPEID); endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset(); - + final int lt1= LT(1); - if (lt1 == IToken.tEOC) + if (lt1 == IToken.tEOC) return newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); - + if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) { - if (plcmt != null && + if (plcmt != null && ASTQueries.findTypeRelevantDeclarator(typeid2.getAbstractDeclarator()) instanceof IASTArrayDeclarator) { throwBacktrack(LA(1)); } @@ -1189,9 +1188,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw e; endOffset2= -1; } - - if (plcmt == null || endOffset2 > endOffset) + if (plcmt == null || endOffset2 > endOffset) return newExpression(isGlobal, null, typeid2, false, init2, offset, endOffset2); if (endOffset != endOffset2) { @@ -1208,9 +1206,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) ex1); return ambiguity; } - + // T ... - final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW); + final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW); int endOffset = calculateEndOffset(typeid); IASTInitializer init= null; final int lt1= LT(1); @@ -1222,10 +1220,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return newExpression(isGlobal, null, typeid, true, init, offset, endOffset); } - private IASTExpression newExpression(boolean isGlobal, List plcmt, IASTTypeId typeid, boolean isNewTypeId, IASTInitializer init, int offset, int endOffset) { - + IASTInitializerClause[] plcmtArray= null; if (plcmt != null && !plcmt.isEmpty()) { plcmtArray= plcmt.toArray(new IASTInitializerClause[plcmt.size()]); @@ -1237,7 +1234,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - @Override protected IASTExpression unaryExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { switch (LT(1)) { @@ -1280,7 +1276,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(idexpr, id); IASTUnaryExpression expr= nodeFactory.newUnaryExpression(IASTUnaryExpression.op_sizeofParameterPack, idexpr); final int lt1= LT(1); - if (lt1 == IToken.tEOC) { + if (lt1 == IToken.tEOC) { setRange(expr, offset, calculateEndOffset(id)); } else { final int endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) @@ -1288,12 +1284,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return expr; } - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat); case IGCCToken.t___alignof__: - return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), + return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(), IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat); - + case IGCCToken.tTT_has_nothrow_assign: case IGCCToken.tTT_has_nothrow_constructor: case IGCCToken.tTT_has_nothrow_copy: @@ -1307,11 +1303,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.tTT_is_class: case IGCCToken.tTT_is_empty: case IGCCToken.tTT_is_enum: + case IGCCToken.tTT_is_literal_type: case IGCCToken.tTT_is_pod: case IGCCToken.tTT_is_polymorphic: + case IGCCToken.tTT_is_standard_layout: + case IGCCToken.tTT_is_trivial: case IGCCToken.tTT_is_union: return parseTypeTrait(); - + default: return postfixExpression(ctx, strat); } @@ -1320,7 +1319,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTExpression parseTypeTrait() throws EndOfFileException, BacktrackException { IToken first= consume(); final boolean isBinary= isBinaryTrait(first); - + consume(IToken.tLPAREN); IASTTypeId typeId= typeId(DeclarationOptions.TYPEID); IASTTypeId secondTypeId= null; @@ -1341,7 +1340,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private boolean isBinaryTrait(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_is_base_of: return true; } @@ -1349,17 +1348,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private Operator getBinaryTypeTraitOperator(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_is_base_of: return IASTBinaryTypeIdExpression.Operator.__is_base_of; } - + assert false; return null; } private int getUnaryTypeTraitOperator(IToken first) { - switch(first.getType()) { + switch (first.getType()) { case IGCCToken.tTT_has_nothrow_assign: return IASTTypeIdExpression.op_has_nothrow_assign; case IGCCToken.tTT_has_nothrow_constructor: @@ -1381,15 +1380,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.tTT_is_class: return IASTTypeIdExpression.op_is_class; case IGCCToken.tTT_is_empty: - return IASTTypeIdExpression.op_is_abstract; + return IASTTypeIdExpression.op_is_empty; case IGCCToken.tTT_is_enum: - return IASTTypeIdExpression.op_is_abstract; + return IASTTypeIdExpression.op_is_enum; + case IGCCToken.tTT_is_literal_type: + return IASTTypeIdExpression.op_is_literal_type; case IGCCToken.tTT_is_pod: - return IASTTypeIdExpression.op_is_abstract; + return IASTTypeIdExpression.op_is_pod; case IGCCToken.tTT_is_polymorphic: - return IASTTypeIdExpression.op_is_abstract; + return IASTTypeIdExpression.op_is_polymorphic; + case IGCCToken.tTT_is_standard_layout: + return IASTTypeIdExpression.op_is_standard_layout; + case IGCCToken.tTT_is_trivial: + return IASTTypeIdExpression.op_is_trivial; case IGCCToken.tTT_is_union: - return IASTTypeIdExpression.op_is_abstract; + return IASTTypeIdExpression.op_is_union; } assert false; return 0; @@ -1400,7 +1405,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * [gnu-extension, compound literals in c++] * ( type-name ) { initializer-list } * ( type-name ) { initializer-list , } - * + * * primary-expression * postfix-expression [ expression ] * postfix-expression [ braced-init-list ] @@ -1425,6 +1430,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTExpression postfixExpression(CastExprCtx ctx, ITemplateIdStrategy strat) throws EndOfFileException, BacktrackException { IASTExpression firstExpression = null; boolean isTemplate = false; + int offset; switch (LT(1)) { case IToken.t_dynamic_cast: @@ -1439,15 +1445,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_const_cast: firstExpression = specialCastExpression(ICPPASTCastExpression.op_const_cast); break; - + case IToken.t_typeid: // 'typeid' ( expression ) // 'typeid' ( type-id ) - int so = consume().getOffset(); - firstExpression = parseTypeidInParenthesisOrUnaryExpression(true, so, + firstExpression = parseTypeidInParenthesisOrUnaryExpression(true, consume().getOffset(), ICPPASTTypeIdExpression.op_typeid, ICPPASTUnaryExpression.op_typeid, ctx, strat); break; - + + case IToken.t_noexcept: + // 'noexcept' ( expression ) + offset= consume().getOffset(); // noexcept + consume(IToken.tLPAREN); // ( + firstExpression= expression(); + firstExpression= nodeFactory.newUnaryExpression(IASTUnaryExpression.op_noexcept, firstExpression); + final int endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) + setRange(firstExpression, offset, endOffset); + break; + case IToken.tLPAREN: // Gnu-extension: compound literals in c++ // ( type-name ) { initializer-list } @@ -1455,19 +1470,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken m = mark(); try { if (canBeCompoundLiteral()) { - int offset = consume().getOffset(); + offset = consume().getOffset(); IASTTypeId t= typeId(DeclarationOptions.TYPEID); consume(IToken.tRPAREN); if (LT(1) == IToken.tLBRACE) { IASTInitializer i = bracedInitList(false); firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i); setRange(firstExpression, offset, calculateEndOffset(i)); - break; + break; } } } catch (BacktrackException bt) { } - backup(m); + backup(m); firstExpression= primaryExpression(ctx, strat); break; @@ -1493,7 +1508,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.t_typeof: firstExpression = simpleTypeConstructorExpression(simpleTypeSpecifier()); break; - + default: firstExpression = primaryExpression(ctx, strat); if (firstExpression instanceof IASTIdExpression && LT(1) == IToken.tLBRACE) { @@ -1528,7 +1543,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tRPAREN) { initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { - final List exprList = expressionList(); + final List exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); } endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); @@ -1547,7 +1562,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixDecr, firstExpression, ((ASTNode) firstExpression).getOffset(), endOffset); break; - + case IToken.tDOT: // member access IToken dot = consume(); @@ -1557,9 +1572,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } IASTName name = qualifiedName(ctx, strat); - + if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), + throwBacktrack(((ASTNode) firstExpression).getOffset(), ((ASTNode) firstExpression).getLength() + dot.getLength()); ICPPASTFieldReference fieldReference = nodeFactory.newFieldReference(name, firstExpression); @@ -1580,11 +1595,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } name = qualifiedName(ctx, strat); - + if (name == null) - throwBacktrack(((ASTNode) firstExpression).getOffset(), + throwBacktrack(((ASTNode) firstExpression).getOffset(), ((ASTNode) firstExpression).getLength() + arrow.getLength()); - + fieldReference = nodeFactory.newFieldReference(name, firstExpression); fieldReference.setIsPointerDereference(true); fieldReference.setIsTemplate(isTemplate); @@ -1603,7 +1618,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTAmbiguousExpression createAmbiguousExpression() { return new CPPASTAmbiguousExpression(); } - + @Override protected IASTAmbiguousExpression createAmbiguousBinaryVsCastExpression(IASTBinaryExpression binary, IASTCastExpression castExpr) { return new CPPASTAmbiguousBinaryVsCastExpression(binary, castExpr); @@ -1617,7 +1632,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected ICPPASTAmbiguousTemplateArgument createAmbiguousTemplateArgument() { return new CPPASTAmbiguousTemplateArgument(); } - private IASTExpression simpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec) throws EndOfFileException, BacktrackException { IASTInitializer initializer = bracedOrCtorStyleInitializer(); @@ -1634,11 +1648,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // TO DO: we need more literals... case IToken.tINTEGER: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_integer_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tFLOATINGPT: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_float_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tSTRING: case IToken.tLSTRING: @@ -1650,24 +1664,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tUTF16CHAR: case IToken.tUTF32CHAR: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_char_constant, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_false: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_false, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_false, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_true: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_true, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_true, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.t_nullptr: t= consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_nullptr, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_nullptr, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); - + case IToken.t_this: t = consume(); - literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_this, t.getImage()); + literalExpression = nodeFactory.newLiteralExpression(IASTLiteralExpression.lk_this, t.getImage()); return setRange(literalExpression, t.getOffset(), t.getEndOffset()); case IToken.tLPAREN: if (supportStatementsInExpressions && LT(2) == IToken.tLBRACE) { @@ -1696,7 +1710,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } case IToken.tLBRACKET: return lambdaExpression(); - + default: IToken la = LA(1); int startingOffset = la.getOffset(); @@ -1725,11 +1739,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= LA().getOffset(); ICPPASTLambdaExpression lambdaExpr= nodeFactory.newLambdaExpression(); - + // Lambda introducer consume(IToken.tLBRACKET); boolean needComma= false; - switch(LT(1)) { + switch (LT(1)) { case IToken.tASSIGN: lambdaExpr.setCaptureDefault(CaptureDefault.BY_COPY); consume(); @@ -1744,31 +1758,31 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; } - loop: for(;;) { + loop: while (true) { switch (LT(1)) { - case IToken.tEOC: + case IToken.tEOC: return setRange(lambdaExpr, offset, LA().getEndOffset()); - case IToken.tRBRACKET: + case IToken.tRBRACKET: consume(); break loop; } - + if (needComma) { consume(IToken.tCOMMA); } - + ICPPASTCapture cap= capture(); lambdaExpr.addCapture(cap); needComma= true; } - + if (LT(1) == IToken.tLPAREN) { ICPPASTFunctionDeclarator dtor = functionDeclarator(true); lambdaExpr.setDeclarator(dtor); if (LT(1) == IToken.tEOC) return setRange(lambdaExpr, offset, calculateEndOffset(dtor)); } - + IASTCompoundStatement body = functionBody(); lambdaExpr.setBody(body); return setRange(lambdaExpr, offset, calculateEndOffset(body)); @@ -1777,7 +1791,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTCapture capture() throws EndOfFileException, BacktrackException { final int offset= LA().getOffset(); final ICPPASTCapture result = nodeFactory.newCapture(); - + switch (LT(1)) { case IToken.t_this: return setRange(result, offset, consume().getEndOffset()); @@ -1786,15 +1800,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result.setIsByReference(true); break; } - + final IASTName identifier= identifier(); result.setIdentifier(identifier); - + if (LT(1) == IToken.tELLIPSIS) { result.setIsPackExpansion(true); return setRange(result, offset, consume().getEndOffset()); - } - + } + return setRange(result, offset, calculateEndOffset(identifier)); } @@ -1826,7 +1840,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; default: operator = IASTCastExpression.op_cast; - break; + break; } return buildCastExpression(operator, typeID, operand, offset, endOffset); } @@ -1836,7 +1850,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * using-declaration: using typename? ::? nested-name-specifier * unqualified-id ; using :: unqualified-id ; using-directive: using * namespace ::? nested-name-specifier? namespace-name ; - * + * * @throws BacktrackException * request for a backtrack */ @@ -1859,7 +1873,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } attributes = __attribute__(); - + switch (LT(1)) { case IToken.tSEMI: case IToken.tEOC: @@ -1907,13 +1921,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - /** * static_assert-declaration: static_assert ( constant-expression , string-literal ) ; */ private ICPPASTStaticAssertDeclaration staticAssertDeclaration() throws EndOfFileException, BacktrackException { - int offset= consume(IToken.t_static_assert).getOffset(); + int offset= consume(IToken.t_static_assert).getOffset(); consume(IToken.tLPAREN); IASTExpression e= constantExpression(); int endOffset= calculateEndOffset(e); @@ -1924,7 +1937,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tRPAREN); endOffset= consume(IToken.tSEMI).getEndOffset(); } - ICPPASTStaticAssertDeclaration assertion = nodeFactory.newStaticAssertion(e, lit); + ICPPASTStaticAssertDeclaration assertion = nodeFactory.newStaticAssertion(e, lit); return setRange(assertion, offset, endOffset); } @@ -1932,14 +1945,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * Implements Linkage specification in the ANSI C++ grammar. * linkageSpecification : extern "string literal" declaration | extern * "string literal" { declaration-seq } - * + * * @throws BacktrackException * request for a backtrack */ protected ICPPASTLinkageSpecification linkageSpecification() throws EndOfFileException, BacktrackException { int offset= consume().getOffset(); // t_extern String spec = consume().getImage(); // tString - ICPPASTLinkageSpecification linkage = nodeFactory.newLinkageSpecification(spec); + ICPPASTLinkageSpecification linkage = nodeFactory.newLinkageSpecification(spec); if (LT(1) == IToken.tLBRACE) { declarationListInBraces(linkage, offset, DeclarationOptions.GLOBAL); @@ -1953,15 +1966,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return linkage; } - /** * Represents the amalgamation of template declarations, template * instantiations and specializations in the ANSI C++ grammar. * template-declaration: export? template < template-parameter-list > * declaration explicit-instantiation: template declaration * explicit-specialization: template <>declaration - * @param option - * + * @param option + * * @throws BacktrackException * request for a backtrack */ @@ -1987,9 +1999,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { explicitInstMod= ICPPASTExplicitTemplateInstantiation.INLINE; break; } - + consume(IToken.t_template); - + if (LT(1) != IToken.tLT) { // explicit-instantiation IASTDeclaration d = declaration(option); @@ -1998,12 +2010,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(ti, offset, calculateEndOffset(d)); return ti; } - + // Modifiers for explicit instantiations if (explicitInstMod != 0) { throwBacktrack(LA(1)); } - consume(IToken.tLT); + consume(IToken.tLT); if (LT(1) == IToken.tGT) { // explicit-specialization consume(); @@ -2037,7 +2049,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * template-argument-list: template-argument template-argument-list , * template-argument template-argument: assignment-expression type-id * id-expression - * + * * @throws BacktrackException * request for a backtrack */ @@ -2046,7 +2058,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { List result = new ArrayList(DEFAULT_PARM_LIST_SIZE); IToken m= mark(); - for(;;) { + while (true) { try { return templateParameterList(result); } catch (BacktrackException e) { @@ -2111,7 +2123,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { defaultValue = typeId(DeclarationOptions.TYPEID); // type-id endOffset = calculateEndOffset(defaultValue); } - + // Check if followed by comma switch (LT(1)) { case IToken.tGT: @@ -2149,7 +2161,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tASSIGN) { // optional = type-id if (parameterPack) throw backtrack; - + consume(); defaultValue = primaryExpression(CastExprCtx.eNotInBExpr, null); endOffset = calculateEndOffset(defaultValue); @@ -2157,7 +2169,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { identifierName = nodeFactory.newName(); } - + ICPPASTTemplatedTypeTemplateParameter tpar = nodeFactory.newTemplatedTypeTemplateParameter(identifierName, defaultValue); tpar.setIsParameterPack(parameterPack); setRange(tpar, start.getOffset(), endOffset); @@ -2167,13 +2179,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { tpar.addTemplateParameter(p); } return tpar; - } - + } + // Try non-type template parameter return parameterDeclaration(); } - /** * The most abstract construct within a translationUnit : a declaration. * declaration : {"asm"} asmDefinition | {"namespace"} namespaceDefinition | @@ -2183,7 +2194,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * functionDefinition into simpleDeclaration - namespaceAliasDefinition into * namespaceDefinition - usingDirective into usingDeclaration - * explicitInstantiation and explicitSpecialization into templateDeclaration - * + * * @throws BacktrackException * request a backtrack */ @@ -2221,10 +2232,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declspec); ((ASTNode) declspec).setOffsetAndLength(t.getOffset(), 0); ((ASTNode) decl).setOffsetAndLength(t.getOffset(), t.getLength()); - return decl; + return decl; case IToken.t_public: case IToken.t_protected: - case IToken.t_private: + case IToken.t_private: if (option == DeclarationOptions.CPP_MEMBER) { t= consume(); int key= t.getType(); @@ -2235,7 +2246,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } break; } - + try { return simpleDeclaration(option); } catch (BacktrackException e) { @@ -2252,12 +2263,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } } - + /** * Serves as the namespace declaration portion of the ANSI C++ grammar. * namespace-definition: namespace identifier { namespace-body } | namespace { * namespace-body } namespace-body: declaration-seq? - * + * * @throws BacktrackException * request a backtrack */ @@ -2265,13 +2276,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= LA().getOffset(); int endOffset; boolean isInline= false; - + if (LT(1) == IToken.t_inline) { consume(); isInline= true; } consume(IToken.t_namespace); - + // optional name IASTName name = null; if (LT(1) == IToken.tIDENTIFIER) { @@ -2289,8 +2300,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ns.setIsInline(isInline); declarationListInBraces(ns, offset, DeclarationOptions.GLOBAL); return ns; - } - + } + if (LT(1) == IToken.tASSIGN) { endOffset= consume().getEndOffset(); if (name.toString() == null) { @@ -2304,7 +2315,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTNamespaceAlias alias = nodeFactory.newNamespaceAlias(name, qualifiedName); ((ASTNode) alias).setOffsetAndLength(offset, endOffset - offset); return alias; - } + } throwBacktrack(LA(1)); return null; } @@ -2313,6 +2324,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTElaboratedTypeSpecifier) { return ((IASTElaboratedTypeSpecifier) declSpec).getKind() != IASTElaboratedTypeSpecifier.k_enum; + } else if (declSpec instanceof ICPPASTNamedTypeSpecifier && + ((ICPPASTNamedTypeSpecifier) declSpec).isFriend()) { + return true; } return super.isLegalWithoutDtor(declSpec); } @@ -2323,7 +2337,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTDeclaration simpleDeclaration(DeclarationOptions declOption) throws BacktrackException, EndOfFileException { if (LT(1) == IToken.tLBRACE) throwBacktrack(LA(1)); - + final int firstOffset= LA(1).getOffset(); int endOffset= firstOffset; boolean insertSemi= false; @@ -2354,7 +2368,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throw e; } - + IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; if (dtor != null) { declarators= new IASTDeclarator[]{dtor}; @@ -2394,7 +2408,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tASSIGN: // defaulted or deleted function definition if (declarators.length != 1 || !declOption.fAllowFunctionDefinition) throwBacktrack(LA(1)); - + dtor= declarators[0]; if (altDeclSpec != null && altDtor != null && dtor != null && !(ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator)) { @@ -2402,8 +2416,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { dtor= altDtor; } return functionDefinition(firstOffset, declSpec, dtor); - - default: + + default: insertSemi= true; if (declOption == DeclarationOptions.LOCAL) { endOffset= figureEndOffset(declSpec, declarators); @@ -2425,9 +2439,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throwBacktrack(LA(1)); } - + // no function body - + final boolean isAmbiguous= altDeclSpec != null && altDtor != null && declarators.length == 1; IASTSimpleDeclaration simpleDeclaration; if (isAmbiguous) { @@ -2435,13 +2449,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // prefer the empty declspec, it shall be used if both variants show no problems simpleDeclaration= nodeFactory.newSimpleDeclaration(altDeclSpec); simpleDeclaration.addDeclarator(altDtor); - } else { + } else { simpleDeclaration= nodeFactory.newSimpleDeclaration(declSpec); for (IASTDeclarator declarator : declarators) { - simpleDeclaration.addDeclarator(declarator); + simpleDeclaration.addDeclarator(declarator); } } - + setRange(simpleDeclaration, firstOffset, endOffset); if (isAmbiguous) { simpleDeclaration = new CPPASTAmbiguousSimpleDeclaration(simpleDeclaration, declSpec, dtor); @@ -2457,23 +2471,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException { - + final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); if (!(dtor instanceof ICPPASTFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); - ICPPASTFunctionDefinition fdef; if (LT(1) == IToken.t_try) { consume(); - fdef= nodeFactory.newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef= nodeFactory.newFunctionTryBlock(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } else { - fdef= nodeFactory.newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); + fdef= nodeFactory.newFunctionDefinition(declSpec, (ICPPASTFunctionDeclarator) dtor, null); } if (LT(1) == IToken.tASSIGN) { consume(); IToken kind= consume(); - switch(kind.getType()) { + switch (kind.getType()) { case IToken.t_default: fdef.setIsDefaulted(true); break; @@ -2503,7 +2516,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throw bt; } - + if (fdef instanceof ICPPASTFunctionWithTryBlock) { ICPPASTFunctionWithTryBlock tryblock= (ICPPASTFunctionWithTryBlock) fdef; List handlers = new ArrayList(DEFAULT_CATCH_HANDLER_LIST_SIZE); @@ -2525,7 +2538,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * : mem-initializer-list * mem-initializer-list: * mem-initializer ...? - * mem-initializer ...?, mem-initializer-list + * mem-initializer ...?, mem-initializer-list * mem-initializer: * mem-initializer-id ( expression-list? ) * mem-initializer-id braced-init-list @@ -2535,7 +2548,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); - loop: for(;;) { + loop: while (true) { final int offset= LA(1).getOffset(); final IASTName name = qualifiedName(); final IASTInitializer init; @@ -2551,7 +2564,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tELLIPSIS) { ctorInitializer.setIsPackExpansion(true); endOffset= consume().getEndOffset(); - } + } fdef.addMemberInitializer(setRange(ctorInitializer, offset, endOffset)); if (LT(1) == IToken.tCOMMA) { @@ -2564,17 +2577,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * This routine parses a parameter declaration - * + * * @throws BacktrackException * request a backtrack */ protected ICPPASTParameterDeclaration parameterDeclaration() throws BacktrackException, EndOfFileException { final int startOffset= LA(1).getOffset(); - + if (LT(1) == IToken.tLBRACKET && supportParameterInfoBlock) { skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET, 0); } - + IASTDeclSpecifier declSpec= null; IASTDeclarator declarator; try { @@ -2592,24 +2605,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return parm; } - - private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, + private final static int INLINE= 0x1, CONST= 0x2, CONSTEXPR= 0x4, RESTRICT= 0x8, VOLATILE= 0x10, SHORT= 0x20, UNSIGNED= 0x40, SIGNED= 0x80, COMPLEX= 0x100, IMAGINARY= 0x200, VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000, THREAD_LOCAL= 0x2000; - private static final int FORBID_IN_EMPTY_DECLSPEC = + private static final int FORBID_IN_EMPTY_DECLSPEC = CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND | THREAD_LOCAL; - /** * This function parses a declaration specifier sequence, as according to - * the ANSI C++ specification. - * declSpecifier : - * "register" | "static" | "extern" | "mutable" | + * the ANSI C++ specification. + * declSpecifier : + * "register" | "static" | "extern" | "mutable" | * "inline" | "virtual" | "explicit" | - * "typedef" | "friend" | "constexpr" | + * "typedef" | "friend" | "constexpr" | * "const" | "volatile" | * "short" | "long" | "signed" | "unsigned" | "int" | - * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | + * "char" | "wchar_t" | "bool" | "float" | "double" | "void" | * "auto" | * ("typename")? name | * { "class" | "struct" | "union" } classSpecifier | @@ -2619,7 +2630,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected Decl declSpecifierSeq(final DeclarationOptions option) throws BacktrackException, EndOfFileException { return declSpecifierSeq(option, false); } - + private ICPPASTDeclSpecifier simpleTypeSpecifier() throws BacktrackException, EndOfFileException { Decl d= declSpecifierSeq(null, true); return (ICPPASTDeclSpecifier) d.fDeclSpec1; @@ -2885,7 +2896,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { result= (ICPPASTDeclSpecifier) bt.getNodeBeforeProblem(); problem= bt.getProblem(); break declSpecifiers; - } + } throw bt; } endOffset= calculateEndOffset(result); @@ -2909,7 +2920,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { simpleType= IASTSimpleDeclSpecifier.t_typeof; consume(IGCCToken.t_typeof); - typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), + typeofExpression= parseTypeidInParenthesisOrUnaryExpression(false, LA(1).getOffset(), IASTTypeIdExpression.op_typeof, -1, CastExprCtx.eNotInBExpr, null); encounteredTypename= true; @@ -2940,7 +2951,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (encounteredRawType && encounteredTypename) throwBacktrack(LA(1)); - + if (single) break declSpecifiers; } @@ -2975,7 +2986,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw e; } } - + Decl target= new Decl(); target.fDeclSpec1= result; target.fDeclSpec2= altResult; @@ -2995,7 +3006,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private ICPPASTSimpleDeclSpecifier buildSimpleDeclSpec(int storageClass, int simpleType, int options, int isLong, IASTExpression typeofExpression, int offset, int endOffset) { ICPPASTSimpleDeclSpecifier declSpec= nodeFactory.newSimpleDeclSpecifier(); - + configureDeclSpec(declSpec, storageClass, options); declSpec.setType(simpleType); @@ -3039,7 +3050,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { isScoped= true; consume(); } - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); if (isScoped || LT(1) == IToken.tIDENTIFIER) { @@ -3065,28 +3076,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return elaboratedTypeSpecifier(); } mark= null; - + if (isOpaque && !isScoped && baseType == null) throwBacktrack(LA(1)); - + if (name == null) { if (isOpaque) throwBacktrack(LA(1)); name= nodeFactory.newName(); } - + final ICPPASTEnumerationSpecifier result= nodeFactory.newEnumerationSpecifier(isScoped, name, baseType); result.setIsOpaque(isOpaque); if (lt1 == IToken.tLBRACE) { endOffset= enumBody(result); - } + } assert endOffset != 0; return setRange(result, offset, endOffset); } /** * Parse an elaborated type specifier. - * + * * @throws BacktrackException * request a backtrack */ @@ -3111,18 +3122,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: throwBacktrack(LA(1)); } - + final int offset= consume().getOffset(); - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); IASTName name = qualifiedName(); return setRange(nodeFactory.newElaboratedTypeSpecifier(eck, name), offset, calculateEndOffset(name)); } - + @Override - protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) + protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { final IToken mark= mark(); IASTDeclarator dtor1= null; @@ -3132,23 +3143,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { dtor1= initDeclarator(DtorStrategy.PREFER_FUNCTION, declspec, option); verifyDtor(declspec, dtor1, option); - + int lt1= LTcatchEOF(1); switch (lt1) { case 0: return dtor1; - case IToken.tLBRACE: - if (option.fCanBeFollowedByBrace + case IToken.tLBRACE: + if (option.fCanBeFollowedByBrace || ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) return dtor1; dtor1= null; throwBacktrack(LA(1)); break; - + case IToken.tCOLON: - // a colon can be used after a type-id in a conditional expression + // a colon can be used after a type-id in a conditional expression if (option != DeclarationOptions.CPP_MEMBER && option != DeclarationOptions.GLOBAL) break; //$FALL-THROUGH$ @@ -3163,15 +3174,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); } } - + if (!(dtor1 instanceof IASTFunctionDeclarator)) return dtor1; - + end1= LA(1); } catch (BacktrackException e) { bt= e; - } - + } + if (!option.fAllowCtorStyleInitializer || !canHaveConstructorInitializer(declspec, dtor1)) { if (bt != null) throw bt; @@ -3181,7 +3192,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); try { dtor2= initDeclarator(DtorStrategy.PREFER_NESTED, declspec, option); - if (dtor1 == null) { + if (dtor1 == null) { return dtor2; } } catch (BacktrackException e) { @@ -3190,14 +3201,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return dtor1; } throw e; - } - + } + // we have an ambiguity if (end1 != null && LA(1).getEndOffset() != end1.getEndOffset()) { backup(end1); return dtor1; } - + if (functionBodyCount != 0) { // prefer the variable prototype: IASTDeclarator h= dtor1; dtor1= dtor2; dtor2= h; @@ -3225,7 +3236,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // accept conversion operator if (name instanceof ICPPASTConversionName) return; - if (opt == DeclarationOptions.CPP_MEMBER) { // Accept constructor and destructor within class body @@ -3240,15 +3250,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return; } } - + ASTNode node= (ASTNode) dtor; throwBacktrack(node.getOffset(), node.getLength()); } } - + private boolean canHaveConstructorInitializer(IASTDeclSpecifier declspec, IASTDeclarator dtor) { if (declspec instanceof ICPPASTDeclSpecifier) { - ICPPASTDeclSpecifier cppspec= (ICPPASTDeclSpecifier) declspec; + ICPPASTDeclSpecifier cppspec= (ICPPASTDeclSpecifier) declspec; if (cppspec.isFriend()) { return false; } @@ -3266,8 +3276,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { dtor.getPointerOperators().length == 0 && dtor.getNestedDeclarator() == null) { return false; } - } - + } + if (dtor != null) { IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName().getLastName(); if (name instanceof ICPPASTTemplateId) { @@ -3276,18 +3286,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (name instanceof ICPPASTOperatorName || name instanceof ICPPASTConversionName) return false; } - + return true; } /** * Parses the initDeclarator construct of the ANSI C++ spec. initDeclarator : * declarator ("=" initializerClause | "(" expressionList ")")? - * + * * @return declarator that this parsing produced. * @throws BacktrackException * request a backtrack - * @throws FoundAggregateInitializer + * @throws FoundAggregateInitializer */ private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException, FoundAggregateInitializer { @@ -3303,13 +3313,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken t = consume(); char[] image = t.getCharImage(); if (image.length != 1 || image[0] != '0') { - throwBacktrack(t); + throwBacktrack(t); } ((ICPPASTFunctionDeclarator) typeRelevantDtor).setPureVirtual(true); adjustEndOffset(dtor, t.getEndOffset()); // we can only adjust the offset of the outermost dtor. } } else { - if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE) + if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE) throw new FoundAggregateInitializer(declspec, dtor); IASTInitializer initializer= optionalInitializer(dtor, option); @@ -3335,12 +3345,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return dtor; } - + /** * initializer: * brace-or-equal-initializer * ( expression-list ) - * + * * brace-or-equal-initializer: * = initializer-clause * braced-init-list @@ -3348,14 +3358,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTInitializer optionalInitializer(IASTDeclarator dtor, DeclarationOptions option) throws EndOfFileException, BacktrackException { final int lt1= LTcatchEOF(1); - + // = initializer-clause if (lt1 == IToken.tASSIGN) { // Check for deleted or defaulted function syntax. final int lt2= LTcatchEOF(2); if (lt2 == IToken.t_delete || lt2 == IToken.t_default) return null; - + int offset= consume().getOffset(); final boolean allowSkipping = LT(1) == IToken.tLBRACE && specifiesArray(dtor); IASTInitializerClause initClause = initClause(allowSkipping); @@ -3367,14 +3377,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (option.fAllowBracedInitializer && lt1 == IToken.tLBRACE) { return bracedInitList(false); } - + // ( expression-list ) if (option.fAllowCtorStyleInitializer && lt1 == IToken.tLPAREN) { return ctorStyleInitializer(false); - } + } return null; } - + private boolean specifiesArray(IASTDeclarator dtor) { dtor = ASTQueries.findTypeRelevantDeclarator(dtor); return dtor instanceof IASTArrayDeclarator; @@ -3395,12 +3405,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throws EndOfFileException, BacktrackException { IASTInitializerClause[] initArray; int offset = consume(IToken.tLPAREN).getOffset(); - + // ( ) if (optionalExpressionList && LT(1) == IToken.tRPAREN) { initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { - final List exprList = expressionList(); + final List exprList = expressionList(); initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]); } int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); @@ -3441,17 +3451,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private ICPPASTInitializerList bracedInitList(boolean allowSkipping) throws EndOfFileException, BacktrackException { int offset = consume(IToken.tLBRACE).getOffset(); - + // { } if (LT(1) == IToken.tRBRACE) { return setRange(nodeFactory.newInitializerList(), offset, consume().getEndOffset()); } - + // { initializer-list ,opt } List initList= initializerList(allowSkipping); if (LT(1) == IToken.tCOMMA) consume(); - + int endOffset= consumeOrEOC(IToken.tRBRACE).getEndOffset(); ICPPASTInitializerList result = nodeFactory.newInitializerList(); for (IASTInitializerClause init : initList) { @@ -3459,7 +3469,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return setRange(result, offset, endOffset); } - + /** * initializerList: * initializer-clause ...opt @@ -3467,10 +3477,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { */ private List initializerList(boolean allowSkipping) throws EndOfFileException, BacktrackException { - List result= null; // List of initializer clauses - loop: for(;;) { + loop: while (true) { // Clause may be null, add to initializer anyways, such that the size can be computed. IASTInitializerClause clause = initClause(allowSkipping); if (LT(1) == IToken.tELLIPSIS) { @@ -3499,10 +3508,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(IToken.tCOMMA); } - + if (result == null) return Collections.emptyList(); - + return result; } @@ -3514,7 +3523,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset = LA().getOffset(); IASTDeclSpecifier declSpecifier = null; IASTDeclarator declarator = null; - + try { Decl decl= declSpecifierSequence_initDeclarator(option, false); declSpecifier= decl.fDeclSpec1; @@ -3522,22 +3531,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (FoundAggregateInitializer lie) { // type-ids have no initializers throwBacktrack(lie.fDeclarator); - } - ICPPASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator); + } + ICPPASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator); setRange(result, offset, figureEndOffset(declSpecifier, declarator)); return result; } /** * Parse a declarator, as according to the ANSI C++ specification. - * declarator : (ptrOperator)* directDeclarator - * directDeclarator : - * declaratorId | - * directDeclarator "(" parameterDeclarationClause ")" (cvQualifier)* (exceptionSpecification)* | - * directDeclarator "[" (constantExpression)? "]" | - * "(" declarator")" | - * directDeclarator "(" parameterDeclarationClause ")" (oldKRParameterDeclaration)* - * + * declarator : (ptrOperator)* directDeclarator + * directDeclarator : + * declaratorId | + * directDeclarator "(" parameterDeclarationClause ")" (cvQualifier)* (exceptionSpecification)* | + * directDeclarator "[" (constantExpression)? "]" | + * "(" declarator")" | + * directDeclarator "(" parameterDeclarationClause ")" (oldKRParameterDeclaration)* + * * declaratorId : name * @return declarator that this parsing produced. * @throws BacktrackException @@ -3552,7 +3561,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (pointerOps != null) { endOffset = calculateEndOffset(pointerOps.get(pointerOps.size() - 1)); } - + // Accept __attribute__ or __declspec between pointer operators and declarator. __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); @@ -3571,21 +3580,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tCOMPLETION: if (option.fRequireAbstract) throwBacktrack(LA(1)); - + final IASTName declaratorName= !option.fRequireSimpleName ? qualifiedName() : identifier(); endOffset= calculateEndOffset(declaratorName); return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, endOffset, strategy, option); - } - + } + if (lt1 == IToken.tLPAREN) { IASTDeclarator cand1= null; IToken cand1End= null; - // try an abstract function declarator + // try an abstract function declarator if (option.fAllowAbstract && option.fAllowFunctions) { final IToken mark= mark(); try { cand1= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, endOffset, strategy, option); - if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) + if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) return cand1; cand1End= LA(1); @@ -3593,7 +3602,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } backup(mark); } - + // type-ids for new or operator-id: if (!option.fAllowNested || hasEllipsis) { if (option.fAllowAbstract) { @@ -3601,7 +3610,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } throwBacktrack(LA(1)); } - + // try a nested declarator try { consume(); @@ -3620,7 +3629,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } // use the longer variant - if (cand1End.getOffset() < cand2End.getOffset()) + if (cand1End.getOffset() < cand2End.getOffset()) return cand2; } catch (BacktrackException e) { @@ -3643,7 +3652,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse a Pointer Operator. ptrOperator : "*" (cvQualifier)* | "&" | ::? * nestedNameSpecifier "*" (cvQualifier)* - * + * * @throws BacktrackException * request a backtrack */ @@ -3652,7 +3661,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for (;;) { // __attribute__ in-between pointers __attribute_decl_seq(supportAttributeSpecifiers, false); - + final int lt1 = LT(1); if (lt1 == IToken.tAMPER || lt1 == IToken.tAND) { IToken endToken= consume(); @@ -3669,7 +3678,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return Collections.singletonList(refOp); } - + IToken mark = mark(); final int startOffset = mark.getOffset(); boolean isConst = false, isVolatile = false, isRestrict = false; @@ -3704,7 +3713,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); return result; } - + int endOffset= consume().getEndOffset(); loop: for (;;) { switch (LTcatchEOF(1)) { @@ -3717,7 +3726,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { isVolatile = true; break; case IToken.t_restrict: - if (!allowCPPRestrict) + if (!allowCPPRestrict) throwBacktrack(LA(1)); endOffset= consume().getEndOffset(); isRestrict = true; @@ -3746,7 +3755,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private IASTDeclarator declarator(List pointerOps, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator, int startingOffset, int endOffset, - DtorStrategy strategy, DeclarationOptions option) + DtorStrategy strategy, DeclarationOptions option) throws EndOfFileException, BacktrackException { ICPPASTDeclarator result= null; List attributes = null; @@ -3759,20 +3768,20 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); } break loop; - + case IToken.tLBRACKET: result= arrayDeclarator(option); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; - + case IToken.tCOLON: if (!option.fAllowBitField || nestedDeclarator != null) break loop; // no backtrack because typeid can be followed by colon - + result= bitFieldDeclarator(); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; - + case IGCCToken.t__attribute__: // if __attribute__ is after a declarator if (!supportAttributeSpecifiers) throwBacktrack(LA(1)); @@ -3824,7 +3833,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } private void setDeclaratorID(ICPPASTDeclarator declarator, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator) { - if (nestedDeclarator != null) { + if (nestedDeclarator != null) { declarator.setNestedDeclarator(nestedDeclarator); declarator.setName(nodeFactory.newName()); } else { @@ -3832,7 +3841,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } declarator.setDeclaresParameterPack(hasEllipsis); } - + /** * Parse a function declarator starting with the left parenthesis. */ @@ -3840,7 +3849,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken last = consume(IToken.tLPAREN); final int startOffset= last.getOffset(); int endOffset= last.getEndOffset(); - + final ICPPASTFunctionDeclarator fc = nodeFactory.newFunctionDeclarator(null); ICPPASTParameterDeclaration pd= null; paramLoop: while(true) { @@ -3863,7 +3872,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: if (pd != null) throwBacktrack(startOffset, endOffset - startOffset); - + pd = parameterDeclaration(); fc.addParameterDeclaration(pd); endOffset = calculateEndOffset(pd); @@ -3911,7 +3920,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.t_throw) { fc.setEmptyExceptionSpecification(); consume(); // throw - consume(IToken.tLPAREN); + consume(IToken.tLPAREN); thloop: while (true) { switch (LT(1)) { @@ -3936,7 +3945,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (thoffset == thendoffset) { thendoffset = consume().getEndOffset(); } - IASTProblem p = createProblem(IProblem.SYNTAX_ERROR, thoffset, thendoffset-thoffset); + IASTProblem p = createProblem(IProblem.SYNTAX_ERROR, thoffset, thendoffset - thoffset); IASTProblemTypeId typeIdProblem = nodeFactory.newProblemTypeId(p); ((ASTNode) typeIdProblem).setOffsetAndLength(((ASTNode) p)); fc.addExceptionSpecificationTypeId(typeIdProblem); @@ -3949,13 +3958,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, false)); } - + + // noexcept specification + if (LT(1) == IToken.t_noexcept) { + consume(); // noexcept + IASTExpression expression; + if (LT(1) == IToken.tLPAREN) { + consume(); // ( + expression = expression(); + endOffset = consume(IToken.tRPAREN).getEndOffset(); // ) + } else { + expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT; + } + fc.setNoexceptExpression((ICPPASTExpression) expression); + } + if (LT(1) == IToken.tARROW) { consume(); IASTTypeId typeId= typeId(DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE); fc.setTrailingReturnType(typeId); endOffset= calculateEndOffset(typeId); - } + } if (attributes != null) { for (IASTAttribute attribute : attributes) { @@ -3975,27 +3998,26 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consumeArrayModifiers(option, arrayMods); if (arrayMods.isEmpty()) throwBacktrack(LA(1)); - + final int endOffset = calculateEndOffset(arrayMods.get(arrayMods.size() - 1)); final ICPPASTArrayDeclarator d = nodeFactory.newArrayDeclarator(null); for (IASTArrayModifier m : arrayMods) { d.addArrayModifier(m); } - + ((ASTNode) d).setOffsetAndLength(start, endOffset-start); return d; } - - + /** * Parses for a bit field declarator starting with the colon */ private ICPPASTFieldDeclarator bitFieldDeclarator() throws EndOfFileException, BacktrackException { int start= consume(IToken.tCOLON).getOffset(); - + final IASTExpression bitField = constantExpression(); final int endOffset = calculateEndOffset(bitField); - + ICPPASTFieldDeclarator d = nodeFactory.newFieldDeclarator(null, bitField); ((ASTNode) d).setOffsetAndLength(start, endOffset-start); return d; @@ -4004,7 +4026,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parse a class/struct/union definition. classSpecifier : classKey name * (baseClause)? "{" (memberSpecification)* "}" - * + * * @throws BacktrackException * request a backtrack */ @@ -4032,9 +4054,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return null; // line is never reached, hint for the parser } - // if __attribute__ or __declspec occurs after struct/union/class and before the identifier + // if __attribute__ or __declspec occurs after struct/union/class and before the identifier __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - + // class name IASTName name = null; if (LT(1) == IToken.tIDENTIFIER) { @@ -4042,10 +4064,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { name = nodeFactory.newName(); } - + // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); - + ICPPASTCompositeTypeSpecifier astClassSpecifier = nodeFactory.newCompositeTypeSpecifier(classKind, name); // base clause @@ -4087,45 +4109,45 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } /** - * Parse a base clause for a class specification. - * base-clause: - * : base-specifier-list - * base-specifier-list: - * base-specifier - * base-specifier-list, base-specifier + * Parse a base clause for a class specification. + * base-clause: + * : base-specifier-list + * base-specifier-list: + * base-specifier + * base-specifier-list, base-specifier */ private void baseClause(ICPPASTCompositeTypeSpecifier astClassSpec) throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); for (;;) { ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier baseSpec = baseSpecifier(); astClassSpec.addBaseSpecifier(baseSpec); - + if (LT(1) == IToken.tELLIPSIS) { baseSpec.setIsPackExpansion(true); adjustEndOffset(baseSpec, consume().getEndOffset()); } - + if (LT(1) != IToken.tCOMMA) { return; } - + consume(); } } /** - * base-specifier: - * ::? nested-name-specifier? class-name - * virtual access-specifier? ::? nested-name-specifier? class-name - * access-specifier virtual? ::? nested-name-specifier? class-name - * + * base-specifier: + * ::? nested-name-specifier? class-name + * virtual access-specifier? ::? nested-name-specifier? class-name + * access-specifier virtual? ::? nested-name-specifier? class-name + * * access-specifier: private | protected | public - * @return + * @return */ private ICPPASTBaseSpecifier baseSpecifier() throws EndOfFileException, BacktrackException { int startOffset= LA(1).getOffset(); boolean isVirtual = false; - int visibility = 0; + int visibility = 0; IASTName name = null; loop: for (;;) { switch (LT(1)) { @@ -4158,10 +4180,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected void catchHandlerSequence(List collection) throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tEOC) return; - - if (LT(1) != IToken.t_catch) + + if (LT(1) != IToken.t_catch) throwBacktrack(LA(1)); // error, need at least one - + int lt1 = LT(1); while (lt1 == IToken.t_catch) { int startOffset = consume().getOffset(); @@ -4195,7 +4217,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { handler.setCatchBody(compoundStatement); } } - + collection.add(handler); lt1 = LTcatchEOF(1); } @@ -4216,14 +4238,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } final int endOffset = figureEndOffset(declSpec, declarator); - final IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declSpec); - if (declarator != null) + final IASTSimpleDeclaration decl= nodeFactory.newSimpleDeclaration(declSpec); + if (declarator != null) decl.addDeclarator(declarator); ((ASTNode) decl).setOffsetAndLength(startOffset, endOffset - startOffset); return decl; } - protected IASTStatement catchBlockCompoundStatement() throws BacktrackException, EndOfFileException { if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE || !isActiveCode()) { int offset = LA(1).getOffset(); @@ -4248,11 +4269,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit = nodeFactory.newTranslationUnit(scanner); translationUnit.setIndex(index); - // add built-in names to the scope - // add built-in names to the scope + // Add built-in names to the scope. if (builtinBindingsProvider != null) { IScope tuScope = translationUnit.getScope(); - + IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope); for (IBinding binding : bindings) { ASTInternal.addBinding(tuScope, binding); @@ -4260,7 +4280,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - private void consumeArrayModifiers(DeclarationOptions option, List collection) throws EndOfFileException, BacktrackException { boolean allowExpression= option == DeclarationOptions.TYPEID_NEW; @@ -4288,7 +4307,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return; } - @Override protected IASTTranslationUnit getTranslationUnit() { return translationUnit; @@ -4362,7 +4380,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit = null; } - @Override protected IASTStatement parseWhileStatement() throws EndOfFileException, BacktrackException { int startOffset = consume().getOffset(); @@ -4386,7 +4403,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { while_statement = nodeFactory.newWhileStatement((IASTExpression)while_condition, while_body); else while_statement = nodeFactory.newWhileStatement((IASTDeclaration)while_condition, while_body); - + ((ASTNode) while_statement).setOffsetAndLength(startOffset, (while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset); return while_statement; @@ -4397,7 +4414,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTExpression e= null; IASTSimpleDeclaration decl= null; IToken end= null; - + IToken mark = mark(); try { decl= simpleSingleDeclaration(DeclarationOptions.CONDITION); @@ -4406,7 +4423,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (la != expectToken && la != IToken.tEOC) { end= null; decl= null; - } + } } catch (BacktrackException b) { } @@ -4421,7 +4438,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (end == null) return e; - final int endOffset = end.getOffset(); final int endOffset2 = end2.getOffset(); @@ -4430,8 +4446,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { setRange(ambig, e); return ambig; } - - if (endOffset < endOffset2) + + if (endOffset < endOffset2) return e; } catch (BacktrackException bt) { if (end == null) { @@ -4446,7 +4462,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return decl; } - @Override protected ASTVisitor createAmbiguityNodeVisitor() { return new CPPASTAmbiguityResolver(); @@ -4465,7 +4480,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int so = consume(IToken.t_if).getOffset(); consume(IToken.tLPAREN); // condition - IASTNode condition= cppStyleCondition(IToken.tRPAREN); + IASTNode condition= cppStyleCondition(IToken.tRPAREN); if (LT(1) == IToken.tEOC) { // Completing in the condition ICPPASTIfStatement new_if = nodeFactory.newIfStatement(); @@ -4481,11 +4496,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } consume(IToken.tRPAREN); - IASTStatement thenClause = statement(); ICPPASTIfStatement new_if_statement = nodeFactory.newIfStatement(); ((ASTNode) new_if_statement).setOffset(so); - if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) + if (condition != null && (condition instanceof IASTExpression || condition instanceof IASTDeclaration)) // shouldn't be possible but failure in condition() makes it so { if (condition instanceof IASTExpression) @@ -4545,7 +4559,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return result; } - @Override protected IASTCompoundStatement functionBody() throws EndOfFileException, BacktrackException { ++functionBodyCount; @@ -4580,7 +4593,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else if (switch_condition instanceof IASTDeclaration) { switch_statement.setControllerDeclaration((IASTDeclaration) switch_condition); } - + if (switch_body != null) { switch_statement.setBody(switch_body); } @@ -4613,7 +4626,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } return setRange(forStmt, offset, endOffset); } - + // Look for "for-range-declaration : for-range-initializer" // for-range-declaration: // attribute-specifier? type-specifier-seq declarator @@ -4633,7 +4646,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { default: init= expression(); } - + ICPPASTRangeBasedForStatement result = nodeFactory.newRangeBasedForStatement(); result.setDeclaration(decl); result.setInitializerClause(init); @@ -4644,7 +4657,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final IASTStatement initStmt = forInitStatement(); IASTNode condition= null; IASTExpression iterExpr= null; - + int lt1 = LT(1); if (lt1 != IToken.tSEMI && lt1 != IToken.tEOC) { condition = cppStyleCondition(IToken.tSEMI); @@ -4655,13 +4668,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (lt1 != IToken.tRPAREN && lt1 != IToken.tEOC) { iterExpr = expression(); } - + ICPPASTForStatement result = nodeFactory.newForStatement(); result.setInitializerStatement(initStmt); if (condition instanceof IASTExpression) { result.setConditionExpression((IASTExpression) condition); } else if (condition instanceof IASTDeclaration) { - result.setConditionDeclaration((IASTDeclaration) condition); + result.setConditionDeclaration((IASTDeclaration) condition); } result.setIterationExpression(iterExpr); return result; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java index 4dd8464e8fd..55da58c8586 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java @@ -1,20 +1,23 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; 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; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -39,25 +42,37 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope { /** * Computes the bases via the original class. */ - ICPPBase[] getBases(); + ICPPBase[] getBases(IASTNode point); + + /** + * Similar to {@link ICPPClassScope#getConstructors()} but a accepts a starting point + * for template instantiation. + */ + ICPPConstructor[] getConstructors(IASTNode point); + + /** + * Similar to {@link ICPPClassScope#getImplicitMethods()} but a accepts a starting point + * for template instantiation. + */ + ICPPMethod[] getImplicitMethods(IASTNode point); /** * Computes the methods via the original class. */ - ICPPMethod[] getDeclaredMethods(); + ICPPMethod[] getDeclaredMethods(IASTNode point); /** * Computes the fields via the original class. */ - ICPPField[] getDeclaredFields(); + ICPPField[] getDeclaredFields(IASTNode point); /** * Computes the friends via the original class. */ - IBinding[] getFriends(); + IBinding[] getFriends(IASTNode point); /** * Computes the nested classes via the original class. */ - ICPPClassType[] getNestedClasses(); + ICPPClassType[] getNestedClasses(IASTNode point); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java index 8bd724ab129..c6017e6a0f4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; * Interface for deferred class template instances. */ public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPTemplateInstance { - /** * Returns the class template for the deferred instantiation. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 62e90c102f4..aed832e59a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -14,6 +14,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; /** @@ -59,4 +61,25 @@ public interface ICPPEvaluation extends ISerializableEvaluation { * signatures are guaranteed to produce the same results. */ char[] getSignature(); + + /** + * Instantiates the evaluation with the provided template parameter map and pack offset. + * The context is used to replace templates with their specialization, where appropriate. + * @return a fully or partially instantiated evaluation, or the original evaluation + */ + ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point); + + /** + * Determines size of the template parameter pack. + * + * @noreference This method is not intended to be referenced by clients. + */ + int determinePackSize(ICPPTemplateParameterMap tpMap); + + /** + * Checks if the evaluation references a template parameter either directly or though nested + * evaluations. + */ + boolean referencesTemplateParameter(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java index af26b8dd21e..4d41e4df2f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java index 2ec1d50f377..daef1004737 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassInstance.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation - * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java index 910da0448ec..aaecce2d77a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownClassType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,5 +20,4 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; * @since 5.0 */ public interface ICPPUnknownClassType extends ICPPUnknownBinding, ICPPUnknownType, ICPPClassType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java index 341a26c7496..981782b0263 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownType.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -16,5 +16,4 @@ import org.eclipse.cdt.core.dom.ast.IType; * Marks types that depend on a template parameter and are thus unknown. */ public interface ICPPUnknownType extends IType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java index 78e1a4b670d..42a6213a7b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java @@ -152,7 +152,7 @@ public class AccessContext { return isAccessible(bindingVisibility, accessLevel); } - ICPPBase[] bases = derivedClass.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(derivedClass, name); if (bases != null) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java index 8579ae27553..35dd49ec54b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BaseClassLookup.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -29,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +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.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -69,14 +71,17 @@ class BaseClassLookup { private IBinding[] fBindings; private List fChildren= Collections.emptyList(); private BitSet fVirtual; - private boolean fHiddenAsVirtualBase= false; - private boolean fPropagationDone= false; + private boolean fHiddenAsVirtualBase; + private boolean fPropagationDone; private boolean fCollected; private boolean fCollectedAsRegularBase; + private final IASTNode fLookupPoint; - private BaseClassLookup(ICPPClassType type) { + private BaseClassLookup(ICPPClassType type, IASTNode lookupPoint) { fClassType= type; + fLookupPoint= lookupPoint; } + ICPPClassType getClassType() { return fClassType; } @@ -84,9 +89,11 @@ class BaseClassLookup { IBinding[] getResult() { return fBindings; } + boolean containsVirtualBase() { return (fVirtual != null && fVirtual.nextSetBit(0) >= 0); } + boolean hasMatches() { return fBindings != null && fBindings.length > 0 && fBindings[0] != null; } @@ -110,6 +117,7 @@ class BaseClassLookup { public void setHiddenAsVirtualBase() { fHiddenAsVirtualBase= true; } + public void propagateHiddenAsVirtual() { if (fPropagationDone) return; @@ -135,8 +143,8 @@ class BaseClassLookup { return false; } - static BaseClassLookup lookupInBaseClass(LookupData data, ICPPClassScope baseClassScope, boolean isVirtual, - ICPPClassType root, HashMap infoMap, int depth) { + static BaseClassLookup lookupInBaseClass(LookupData data, ICPPClassScope baseClassScope, + boolean isVirtual, ICPPClassType root, HashMap infoMap, int depth) { if (depth++ > CPPSemantics.MAX_INHERITANCE_DEPTH) return null; @@ -157,10 +165,10 @@ class BaseClassLookup { BaseClassLookup result; IBinding[] matches= IBinding.EMPTY_BINDING_ARRAY; if (baseClassScope == null) { - result= new BaseClassLookup(root); + result= new BaseClassLookup(root, data.getLookupPoint()); infoMap.put(root.getCompositeScope(), result); } else { - result= new BaseClassLookup(baseClassScope.getClassType()); + result= new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint()); infoMap.put(baseClassScope, result); try { IBinding[] members= CPPSemantics.getBindingsFromScope(baseClassScope, data); @@ -181,8 +189,7 @@ class BaseClassLookup { // base-classes ICPPClassType baseClass= result.getClassType(); if (baseClass != null) { - ICPPBase[] grandBases= null; - grandBases= baseClass.getBases(); + ICPPBase[] grandBases= ClassTypeHelper.getBases(baseClass, data.getLookupPoint()); if (grandBases != null && grandBases.length > 0) { HashSet grandBaseBindings= null; BitSet selectedBases= null; @@ -285,7 +292,7 @@ class BaseClassLookup { if (fClassType != null) { ICPPBase[] bases= null; - bases= fClassType.getBases(); + bases= ClassTypeHelper.getBases(fClassType, fLookupPoint); if (bases != null && bases.length > 0) { for (ICPPBase base : bases) { IBinding baseBinding = base.getBaseClass(); @@ -306,7 +313,7 @@ class BaseClassLookup { baseInfo.propagateHiddenAsVirtual(); } else { // mark to catch recursions - baseInfo= new BaseClassLookup(baseClass); + baseInfo= new BaseClassLookup(baseClass, fLookupPoint); infoMap.put(baseScope, baseInfo); baseInfo.hideVirtualBases(infoMap, depth); } @@ -314,6 +321,7 @@ class BaseClassLookup { } } } + public void collectResultForContentAssist(LookupData data) { if (fCollected) return; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java index 228047b9233..4032094ee4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/BuiltinOperators.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import java.util.ArrayList; import java.util.HashSet; @@ -67,6 +70,7 @@ class BuiltinOperators { private final OverloadableOperator fOperator; private final boolean fUnary; + private final IASTNode fPoint; private IType fType1; private IType fType2; private IType[][] fClassConversionTypes= { null, null }; @@ -80,7 +84,8 @@ class BuiltinOperators { Object[] globCandidates) { fFileScope= point.getTranslationUnit().getScope(); fOperator= operator; - fUnary= args.length<2; + fPoint = point; + fUnary= args.length < 2; fGlobalCandidates= globCandidates; if (args.length > 0) { IType type= args[0].getTypeOrFunctionSet(point); @@ -95,7 +100,6 @@ class BuiltinOperators { } } - private ICPPFunction[] create() { switch (fOperator) { case ARROW: @@ -231,8 +235,6 @@ class BuiltinOperators { return fResult.toArray(new ICPPFunction[fResult.size()]); } - - // 13.6-3, 13.6-4, 13.6-5 private void opIncOrDec() { IType[] types= getClassConversionTypes(FIRST); @@ -355,7 +357,7 @@ class BuiltinOperators { IType t2= SemanticUtil.getNestedType(memPtr.getMemberOfClass(), TDEF); if (t2 instanceof ICPPClassType) { ICPPClassType c2= (ICPPClassType) t2; - if (SemanticUtil.calculateInheritanceDepth(c1, c2) >= 0) { + if (SemanticUtil.calculateInheritanceDepth(c1, c2, fPoint) >= 0) { IType cvt= SemanticUtil.getNestedType(memPtr.getType(), TDEF); IType rt= new CPPReferenceType( SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile(), cv1.isRestrict()), false); @@ -424,7 +426,6 @@ class BuiltinOperators { return p1; } - // 13.6-13, 13.6.14 private void pointerArithmetic(boolean useRef, boolean isDiff) { IType[] types= getClassConversionTypes(FIRST); @@ -665,7 +666,7 @@ class BuiltinOperators { if (type instanceof ICPPClassType) { fIsClass[idx]= true; try { - ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type); + ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type, fPoint); result= new IType[ops.length]; int j= -1; for (ICPPMethod op : ops) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 69460068b57..53b6ff28028 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -12,14 +12,27 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; 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.ICPPEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; public abstract class CPPEvaluation implements ICPPEvaluation { @@ -27,11 +40,8 @@ public abstract class CPPEvaluation implements ICPPEvaluation { private static class SignatureBuilder implements ITypeMarshalBuffer { private static final byte NULL_TYPE= 0; private static final byte UNSTORABLE_TYPE= (byte) -1; - private static final char[] HEX_DIGITS = - { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; private final StringBuilder fBuffer; - private boolean hexMode; /** * Constructor for input buffer. @@ -45,6 +55,10 @@ public abstract class CPPEvaluation implements ICPPEvaluation { return fBuffer.toString(); } + public char[] getSignature() { + return CharArrayUtils.extractChars(fBuffer); + } + @Override public void marshalBinding(IBinding binding) throws CoreException { if (binding instanceof ISerializableType) { @@ -53,12 +67,17 @@ public abstract class CPPEvaluation implements ICPPEvaluation { putByte(NULL_TYPE); } else { appendSeparator(); - IBinding owner= binding.getOwner(); - if (owner instanceof IType) { - ASTTypeUtil.appendType((IType) owner, true, fBuffer); - fBuffer.append("::"); //$NON-NLS-1$ + if (binding instanceof ICPPBinding) { + if (binding instanceof ICPPTemplateParameter) { + ICPPTemplateParameter param = (ICPPTemplateParameter) binding; + fBuffer.append(param.isParameterPack() ? '*' : '#'); + fBuffer.append(param.getParameterID()); + } else { + fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + } + } else { + fBuffer.append(binding.getNameCharArray()); } - fBuffer.append(binding.getName()); } } @@ -95,49 +114,37 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } @Override - public void putByte(byte b) { - appendHexDigit(b >> 4); - appendHexDigit(b); + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg instanceof CPPTemplateNonTypeArgument) { + putByte(VALUE); + ((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + + @Override + public void putByte(byte value) { + appendSeparator(); + fBuffer.append(value); } @Override public void putShort(short value) { - appendHexDigit(value >> 12); - appendHexDigit(value >> 8); - appendHexDigit(value >> 4); - appendHexDigit(value); + appendSeparator(); + fBuffer.append(value); } @Override public void putInt(int value) { - appendHexDigit(value >> 28); - appendHexDigit(value >> 24); - appendHexDigit(value >> 20); - appendHexDigit(value >> 16); - appendHexDigit(value >> 12); - appendHexDigit(value >> 8); - appendHexDigit(value >> 4); - appendHexDigit(value); + appendSeparator(); + fBuffer.append(value); } @Override public void putLong(long value) { - appendHexDigit((int) (value >> 60)); - appendHexDigit((int) (value >> 56)); - appendHexDigit((int) (value >> 52)); - appendHexDigit((int) (value >> 48)); - appendHexDigit((int) (value >> 44)); - appendHexDigit((int) (value >> 40)); - appendHexDigit((int) (value >> 36)); - appendHexDigit((int) (value >> 32)); - appendHexDigit((int) (value >> 28)); - appendHexDigit((int) (value >> 24)); - appendHexDigit((int) (value >> 20)); - appendHexDigit((int) (value >> 16)); - appendHexDigit((int) (value >> 12)); - appendHexDigit((int) (value >> 8)); - appendHexDigit((int) (value >> 4)); - appendHexDigit((int) value); + appendSeparator(); + fBuffer.append(value); } @Override @@ -148,19 +155,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } - private void appendHexDigit(int val) { - if (hexMode) { - appendSeparator(); - fBuffer.append("0x"); //$NON-NLS-1$ - hexMode = true; - } - fBuffer.append(HEX_DIGITS[val & 0xF]); - } - private void appendSeparator() { if (fBuffer.length() != 0) fBuffer.append(' '); - hexMode = false; } @Override @@ -183,6 +180,11 @@ public abstract class CPPEvaluation implements ICPPEvaluation { throw new UnsupportedOperationException(); } + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + throw new UnsupportedOperationException(); + } + @Override public int getByte() throws CoreException { throw new UnsupportedOperationException(); @@ -214,6 +216,9 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } } + CPPEvaluation() { + } + @Override public char[] getSignature() { SignatureBuilder buf = new SignatureBuilder(); @@ -223,6 +228,33 @@ public abstract class CPPEvaluation implements ICPPEvaluation { CCorePlugin.log(e); return new char[] { '?' }; } - return buf.toString().toCharArray(); + return buf.getSignature(); + } + + protected static IBinding resolveUnknown(ICPPUnknownBinding unknown, ICPPTemplateParameterMap tpMap, + int packOffset, ICPPClassSpecialization within, IASTNode point) { + try { + return CPPTemplates.resolveUnknown(unknown, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return unknown; + } + + protected static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, + ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { + try { + return CPPTemplates.instantiateArguments(args, tpMap, packOffset, within, point); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return args; + } + + protected static SizeAndAlignment getSizeAndAlignment(IType type, IASTNode point) { + SizeofCalculator calc = point == null ? + SizeofCalculator.getDefault() : + ((ASTTranslationUnit) point.getTranslationUnit()).getSizeofCalculator(); + return calc.sizeAndAlignment(type); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index ed466a91df0..6fb0de1789f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -203,6 +203,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; @@ -244,7 +245,7 @@ public class CPPSemantics { public static int traceIndent= 0; // special return value for costForFunctionCall - private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0); + private static final FunctionCost CONTAINS_DEPENDENT_TYPES = new FunctionCost(null, 0, null); static protected IBinding resolveBinding(IASTName name) { if (traceBindingResolution) { @@ -257,11 +258,11 @@ public class CPPSemantics { ((CPPASTNameBase) name).incResolutionDepth(); } - // 1: get some context info off of the name to figure out what kind of lookup we want + // 1: Get some context info off of the name to figure out what kind of lookup we want. LookupData data = createLookupData(name); try { - // 2: lookup + // 2: Lookup lookup(data, null); // Perform argument dependent lookup @@ -274,14 +275,14 @@ public class CPPSemantics { if (data.problem != null) return data.problem; - // 3: resolve ambiguities + // 3: Resolve ambiguities IBinding binding; try { binding = resolveAmbiguities(data); } catch (DOMException e) { binding = e.getProblem(); } - // 4: post processing + // 4: Post processing binding = postResolution(binding, data); if (traceBindingResolution) { traceIndent--; @@ -306,6 +307,8 @@ public class CPPSemantics { if (lookupName == null) return binding; + IASTNode lookupPoint = data.getLookupPoint(); + if (binding == null && data.checkClassContainingFriend()) { // 3.4.1-10 if we don't find a name used in a friend declaration in the member declaration's class // we should look in the class granting friendship @@ -372,13 +375,13 @@ public class CPPSemantics { node= node.getParent(); } if (!ok) { - binding = new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_INVALID_TYPE, - data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } } } } else if (binding instanceof ICPPDeferredClassInstance) { - // try to replace binding by the one pointing to the enclosing template declaration. + // Try to replace binding by the one pointing to the enclosing template declaration. ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) binding; IBinding usedHere= CPPTemplates.isUsedInClassTemplateScope(dcl.getClassTemplate(), lookupName); if (usedHere instanceof ICPPClassTemplatePartialSpecialization) { @@ -403,7 +406,7 @@ public class CPPSemantics { if (data.getTranslationUnit() != null) { ICPPASTTemplateId id = (ICPPASTTemplateId) lookupName; ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id); - IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args, data.getLookupPoint()); + IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args, lookupPoint); if (inst instanceof ICPPClassType) { cls= (ICPPClassType) inst; } @@ -412,7 +415,7 @@ public class CPPSemantics { if (cls instanceof ICPPUnknownBinding) { binding= new CPPUnknownConstructor(cls); } else { - binding= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); + binding= CPPSemantics.resolveFunction(data, ClassTypeHelper.getConstructors(cls, lookupPoint), true); } } catch (DOMException e) { return e.getProblem(); @@ -460,13 +463,13 @@ public class CPPSemantics { if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { if (!(binding instanceof IType)) { // a type id needs to hold a type - binding = new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_INVALID_TYPE, - data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } // don't create a problem here } else { - binding = new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_INVALID_TYPE, - data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } } } else if (namePropertyInParent == IASTIdExpression.ID_NAME) { @@ -481,8 +484,8 @@ public class CPPSemantics { && ((ICPPASTUnaryExpression) idExpr.getParent()).getOperator() == IASTUnaryExpression.op_sizeofParameterPack) { // Argument of sizeof... can be a type } else { - binding= new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_INVALID_TYPE, - data.getFoundBindings()); + binding= new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } } } @@ -512,11 +515,11 @@ public class CPPSemantics { // If we're still null... if (binding == null) { if (name instanceof ICPPASTQualifiedName && declaration != null) { - binding = new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, - data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.getFoundBindings()); } else { - binding = new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, - data.getFoundBindings()); + binding = new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getFoundBindings()); } } return binding; @@ -712,7 +715,7 @@ public class CPPSemantics { } if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) { ICPPClassType ct= (ICPPClassType) t; - ICPPBase[] bases = ct.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(ct, tu); for (ICPPBase base : bases) { IBinding b = base.getBaseClass(); if (b instanceof IType) @@ -723,7 +726,7 @@ public class CPPSemantics { // (excluding template template parameters); // * ... owners of which any template template arguments are members; if (ct instanceof ICPPTemplateInstance) { - for (IBinding friend : ct.getFriends()) { + for (IBinding friend : ClassTypeHelper.getFriends(ct, tu)) { if (friend instanceof ICPPFunction) { friendFns.add((ICPPFunction) friend); } @@ -1223,7 +1226,8 @@ public class CPPSemantics { return expandUsingDeclarationsAndRemoveObjects(bindings, data); } - private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, LookupData data) { + private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, + LookupData data) { if (bindings == null || bindings.length == 0) return IBinding.EMPTY_BINDING_ARRAY; @@ -1301,9 +1305,10 @@ public class CPPSemantics { } /** - * Stores the using directive with the scope where the members of the nominated namespace will appear. - * In case of an unqualified lookup the transitive directives are stored, also. This is important because - * the members nominated by a transitive directive can appear before those of the original directive. + * Stores the using directive with the scope where the members of the nominated namespace will + * appear. In case of an unqualified lookup the transitive directives are stored, also. + * This is important because the members nominated by a transitive directive can appear before + * those of the original directive. */ private static void storeUsingDirective(LookupData data, ICPPNamespaceScope container, ICPPUsingDirective directive, Set handled) throws DOMException { @@ -1330,8 +1335,8 @@ public class CPPSemantics { listOfNominated.add(nominated); } - // in a non-qualified lookup the transitive directive have to be stored right away, they may overtake the - // container. + // In a non-qualified lookup the transitive directive have to be stored right away, + // they may overtake the container. if (!data.qualified || data.contentAssist) { assert handled != null; if (tu != null) { @@ -1347,7 +1352,8 @@ public class CPPSemantics { /** * Computes the common enclosing scope of s1 and s2. */ - private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu) throws DOMException { + private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu) + throws DOMException { ObjectSet set = new ObjectSet(2); IScope parent= s1; while (parent != null) { @@ -1392,7 +1398,7 @@ public class CPPSemantics { ICPPASTCompositeTypeSpecifier comp = (ICPPASTCompositeTypeSpecifier) parent; nodes = comp.getMembers(); } else if (parent instanceof ICPPASTNamespaceDefinition) { - // need binding because namespaces can be split + // Need binding because namespaces can be split. CPPNamespace namespace = (CPPNamespace) ((ICPPASTNamespaceDefinition) parent).getName().resolveBinding(); namespaceDefs = namespace.getNamespaceDefinitions(); nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[++namespaceIdx].getParent()).getDeclarations(); @@ -1488,7 +1494,7 @@ public class CPPSemantics { item = null; while (true) { if (namespaceDefs != null) { - // check all definitions of this namespace + // Check all definitions of this namespace. while (++namespaceIdx < namespaceDefs.length) { nodes = ((ICPPASTNamespaceDefinition) namespaceDefs[namespaceIdx].getParent()).getDeclarations(); if (nodes.length > 0) { @@ -1498,7 +1504,7 @@ public class CPPSemantics { } } } else if (parent instanceof IASTCompoundStatement && nodes instanceof IASTParameterDeclaration[]) { - // function body, we were looking at parameters, now check the body itself + // Function body, we were looking at parameters, now check the body itself. IASTCompoundStatement compound = (IASTCompoundStatement) parent; nodes = compound.getStatements(); if (nodes.length > 0) { @@ -1558,7 +1564,7 @@ public class CPPSemantics { innermost= dtor; dtor= dtor.getNestedDeclarator(); } - if (innermost != null) { // could be null when content assist in the declSpec + if (innermost != null) { // Could be null when content assist in the declSpec IASTName declName = innermost.getName(); ASTInternal.addName(scope, declName); return; @@ -1632,8 +1638,7 @@ public class CPPSemantics { ASTInternal.addName(scope, specName); } } - // Collect friends and elaborated type specifiers with declarators - // from nested classes + // Collect friends and elaborated type specifiers with declarators from nested classes. if (declarators.length > 0 || declSpec instanceof ICPPASTCompositeTypeSpecifier) { switch (scopeKind) { case eLocal: @@ -1695,7 +1700,6 @@ public class CPPSemantics { * lookups the method assumes that transitive directives have been stored in the lookup-data. * For qualified lookups the transitive directives are considered if the lookup of the original * directive returns empty. - * @param fileSet */ private static void lookupInNominated(LookupData data, ICPPNamespaceScope scope) throws DOMException { List allNominated= data.usingDirectives.remove(scope); @@ -1890,8 +1894,9 @@ public class CPPSemantics { private static IBinding resolveAmbiguities(LookupData data) throws DOMException { if (!data.hasResults() || data.contentAssist) return null; - + final IASTName lookupName = data.getLookupName(); + IASTNode lookupPoint = data.getLookupPoint(); final boolean indexBased= data.getIndex() != null; final boolean checkWholeClass= lookupName == null || LookupData.checkWholeClassScope(lookupName); @SuppressWarnings("unchecked") @@ -1904,7 +1909,7 @@ public class CPPSemantics { Object[] items = (Object[]) data.foundItems; for (int i = 0; i < items.length && items[i] != null; i++) { Object o = items[i]; - boolean declaredBefore = data.isIgnorePointOfDeclaration() || declaredBefore(o, data.getLookupPoint(), indexBased); + boolean declaredBefore = data.isIgnorePointOfDeclaration() || declaredBefore(o, lookupPoint, indexBased); boolean checkResolvedNamesOnly= false; if (!checkWholeClass && !declaredBefore) { if (lookupName != null && lookupName.getRoleOfName(false) != IASTNameOwner.r_reference) { @@ -1979,8 +1984,8 @@ public class CPPSemantics { type= temp; } } else { - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } } } @@ -1994,8 +1999,8 @@ public class CPPSemantics { if (c < 0) { obj= temp; } else if (c == 0) { - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } } } @@ -2008,8 +2013,8 @@ public class CPPSemantics { IFunction[] fnArray= fns.keyArray(IFunction.class); cmp= compareByRelevance(data, obj, fnArray); if (cmp == 0) { - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } } } @@ -2053,8 +2058,8 @@ public class CPPSemantics { if (obj != null) { int cmp= compareByRelevance(data, obj, fnArray); if (cmp == 0) { - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } if (cmp > 0) { return obj; @@ -2359,8 +2364,9 @@ public class CPPSemantics { Arrays.asList(argTypes), Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject, lookupPoint); - if (tmp.length == 0 || tmp[0] == null) - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); + if (tmp.length == 0 || tmp[0] == null) { + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); + } int viableCount= 0; for (IFunction f : tmp) { @@ -2373,7 +2379,7 @@ public class CPPSemantics { ++viableCount; } if (viableCount == 0) - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); // Check for dependent arguments fns= tmp; @@ -2413,7 +2419,7 @@ public class CPPSemantics { potentialCosts.add(fnCost); continue; } - int cmp= fnCost.compareTo(tu, bestFnCost, lookupPoint); + int cmp= fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { bestFnCost= fnCost; ambiguousFunctions= null; @@ -2425,7 +2431,7 @@ public class CPPSemantics { if (potentialCosts != null) { for (FunctionCost fnCost : potentialCosts) { if (!fnCost.mustBeWorse(bestFnCost) && fnCost.performUDC(lookupPoint)) { - int cmp= fnCost.compareTo(tu, bestFnCost, lookupPoint); + int cmp= fnCost.compareTo(tu, bestFnCost); if (cmp < 0) { bestFnCost= fnCost; ambiguousFunctions= null; @@ -2446,12 +2452,12 @@ public class CPPSemantics { if (ambiguousFunctions != null) { ambiguousFunctions= ArrayUtil.append(IFunction.class, ambiguousFunctions, bestFnCost.getFunction()); - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - ambiguousFunctions); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, ambiguousFunctions); } if (bestFnCost.hasAmbiguousUserDefinedConversion()) { - return new ProblemBinding(lookupName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, - data.getFoundBindings()); + return new ProblemBinding(lookupName, lookupPoint, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings()); } for (int i = 0; i < argTypes.length; i++) { @@ -2586,7 +2592,8 @@ public class CPPSemantics { } } if (isAmbiguous) - return new ProblemBinding(data.getLookupName(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, fns); + return new ProblemBinding(data.getLookupName(), data.getLookupPoint(), + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, fns); return bestInst; } @@ -2630,9 +2637,9 @@ public class CPPSemantics { final int sourceLen= argTypes.length - skipArg; final FunctionCost result; if (implicitParameterType == null) { - result= new FunctionCost(fn, sourceLen); + result= new FunctionCost(fn, sourceLen, data.getLookupPoint()); } else { - result= new FunctionCost(fn, sourceLen + 1); + result= new FunctionCost(fn, sourceLen + 1, data.getLookupPoint()); ValueCategory sourceIsLValue= LVALUE; if (impliedObjectType == null) { @@ -2656,7 +2663,7 @@ public class CPPSemantics { if (CPPTemplates.isDependentType(implicitParameterType) || CPPTemplates.isDependentType(impliedObjectType)) { IType s= getNestedType(impliedObjectType, TDEF|REF|CVTYPE); IType t= getNestedType(implicitParameterType, TDEF|REF|CVTYPE); - if (SemanticUtil.calculateInheritanceDepth(s, t) >= 0) + if (SemanticUtil.calculateInheritanceDepth(s, t, data.getLookupPoint()) >= 0) return null; return CONTAINS_DEPENDENT_TYPES; @@ -2671,11 +2678,11 @@ public class CPPSemantics { final UDCMode udc = allowUDC ? UDCMode.DEFER : UDCMode.FORBIDDEN; for (int j = 0; j < sourceLen; j++) { - final IType argType= SemanticUtil.getNestedType(argTypes[j+skipArg], TDEF | REF); + final IType argType= SemanticUtil.getNestedType(argTypes[j + skipArg], TDEF | REF); if (argType == null) return null; - final ValueCategory sourceIsLValue = isLValue[j+skipArg]; + final ValueCategory sourceIsLValue = isLValue[j + skipArg]; IType paramType; if (j < paramTypes.length) { @@ -2705,7 +2712,8 @@ public class CPPSemantics { } } } - cost = Conversions.checkImplicitConversionSequence(paramType, argType, sourceIsLValue, udc, ctx, data.getLookupPoint()); + cost = Conversions.checkImplicitConversionSequence(paramType, argType, sourceIsLValue, + udc, ctx, data.getLookupPoint()); if (data.fNoNarrowing && cost.isNarrowingConversion()) { cost= Cost.NO_CONVERSION; } @@ -2733,7 +2741,8 @@ public class CPPSemantics { ICPPASTConversionName astName= (ICPPASTConversionName) data.getLookupName(); IType t= CPPVisitor.createType(astName.getTypeId()); if (t instanceof ISemanticProblem) { - return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); + return new ProblemBinding(astName, data.getLookupPoint(), + IProblemBinding.SEMANTIC_INVALID_TYPE, data.getFoundBindings()); } if (data.forDeclaration() == null || data.forExplicitFunctionSpecialization() || data.forExplicitFunctionInstantiation()) { @@ -2753,11 +2762,13 @@ public class CPPSemantics { } if (unknown != null) return unknown; - return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getFoundBindings()); + return new ProblemBinding(astName, data.getLookupPoint(), + IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getFoundBindings()); } /** - * 13.4-1 A use of an overloaded function without arguments is resolved in certain contexts to a function + * 13.4-1 A use of an overloaded function without arguments is resolved in certain contexts to + * a function. */ static IBinding resolveTargetedFunction(IASTName name, CPPFunctionSet functionSet) { boolean addressOf= false; @@ -2815,7 +2826,8 @@ public class CPPSemantics { LookupData data= new LookupData(name); data.setFunctionArguments(false, init.getArguments()); try { - IBinding ctor = CPPSemantics.resolveFunction(data, ((ICPPClassType) targetType).getConstructors(), true); + IBinding ctor = CPPSemantics.resolveFunction(data, + ClassTypeHelper.getConstructors((ICPPClassType) targetType, name), true); if (ctor instanceof ICPPConstructor) { int i= 0; for (IASTNode arg : init.getArguments()) { @@ -2841,7 +2853,7 @@ public class CPPSemantics { } else if (prop == IASTFunctionCallExpression.ARGUMENT) { // Target is a parameter of a function, need to resolve the function call IASTFunctionCallExpression fnCall = (IASTFunctionCallExpression) parent; - IType t= SemanticUtil.getNestedType(fnCall.getFunctionNameExpression().getExpressionType(), TDEF|REF|CVTYPE); + IType t= SemanticUtil.getNestedType(fnCall.getFunctionNameExpression().getExpressionType(), TDEF | REF | CVTYPE); if (t instanceof IPointerType) { t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE); } @@ -2934,9 +2946,11 @@ public class CPPSemantics { try { if (fn instanceof ICPPFunctionTemplate) { final ICPPFunctionTemplate template = (ICPPFunctionTemplate) fn; - ICPPFunction inst= CPPTemplates.instantiateForAddressOfFunction(template, (ICPPFunctionType) targetType, set.getTemplateArguments(), point); + ICPPFunction inst= CPPTemplates.instantiateForAddressOfFunction(template, + (ICPPFunctionType) targetType, set.getTemplateArguments(), point); if (inst != null) { - int cmp= CPPTemplates.orderFunctionTemplates(resultTemplate, template, TypeSelection.PARAMETERS_AND_RETURN_TYPE, point); + int cmp= CPPTemplates.orderFunctionTemplates(resultTemplate, template, + TypeSelection.PARAMETERS_AND_RETURN_TYPE, point); if (cmp == 0) cmp= compareByRelevance(tu, resultTemplate, template); @@ -2959,7 +2973,8 @@ public class CPPSemantics { return result; } - public static ICPPFunction findOverloadedBinaryOperator(IASTNode point, OverloadableOperator op, ICPPEvaluation arg1, ICPPEvaluation arg2) { + public static ICPPFunction findOverloadedBinaryOperator(IASTNode point, OverloadableOperator op, + ICPPEvaluation arg1, ICPPEvaluation arg2) { if (op == null || arg1 == null || arg2 == null) return null; @@ -3086,7 +3101,7 @@ public class CPPSemantics { ValueCategory isLValue= evaluation.getValueCategory(name); if (sourceType != null) { Cost c; - if (calculateInheritanceDepth(sourceType, classType) >= 0) { + if (calculateInheritanceDepth(sourceType, classType, name) >= 0) { c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false, name); } else { c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, name); @@ -3122,13 +3137,13 @@ public class CPPSemantics { LookupData data = new LookupData(astName); data.setFunctionArguments(false, arguments); data.qualified = true; - data.foundItems = classType.getConstructors(); + data.foundItems = ClassTypeHelper.getConstructors(classType, name); binding = resolveAmbiguities(data); if (binding instanceof ICPPConstructor) return (ICPPConstructor) binding; } else if (initializer == null) { // Default initialization - ICPPConstructor[] ctors = classType.getConstructors(); + ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; @@ -3342,7 +3357,7 @@ public class CPPSemantics { if (callToObjectOfClassType != null) { try { // 13.3.1.1.2 call to object of class type - ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType); + ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType, point); for (ICPPMethod op : ops) { if (op.isExplicit()) continue; @@ -3652,14 +3667,15 @@ public class CPPSemantics { return false; } - protected static IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown) { + protected static IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown, IASTNode point) { final IASTName unknownName = unknown.getUnknownName(); - LookupData data = new LookupData(unknownName); + LookupData data = unknownName.getTranslationUnit() != null ? + new LookupData(unknownName) : new LookupData(unknownName.getSimpleID(), null, point); data.setIgnorePointOfDeclaration(true); data.typesOnly= unknown instanceof IType; try { - // 2: lookup + // 2: Lookup lookup(data, scope); } catch (DOMException e) { data.problem = (ProblemBinding) e.getProblem(); @@ -3668,7 +3684,7 @@ public class CPPSemantics { if (data.problem != null) return data.problem; - // 3: resolve ambiguities + // 3: Resolve ambiguities IBinding binding; try { binding = resolveAmbiguities(data); @@ -3677,7 +3693,7 @@ public class CPPSemantics { } // 4: Normal post processing is not possible, because the name is not rooted in AST if (binding == null) - binding = new ProblemBinding(unknownName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND); + binding = new ProblemBinding(unknownName, point, IProblemBinding.SEMANTIC_NAME_NOT_FOUND); return binding; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index acec6713497..122590d4731 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -51,7 +51,6 @@ 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.ICPPASTAmbiguousTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; @@ -102,7 +101,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; 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.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization; @@ -124,11 +122,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodTemplateSpecializat 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.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownBinding; @@ -138,6 +137,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclarationSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration; 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.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalClassTemplate; @@ -153,21 +153,21 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMod * type instantiation. */ public class CPPTemplates { - private static final int PACK_SIZE_DEFER = -1; - private static final int PACK_SIZE_FAIL = -2; - private static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; + static final int PACK_SIZE_DEFER = -1; + static final int PACK_SIZE_FAIL = -2; + static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; private static final ICPPFunction[] NO_FUNCTIONS = {}; static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } /** - * Instantiates a class template with the given arguments. May return null. + * Instantiates a class template with the given arguments. May return {@code null}. */ public static IBinding instantiate(ICPPClassTemplate template, ICPPTemplateArgument[] args, IASTNode point) { return instantiate(template, args, false, false, point); } /** - * Instantiates a class template with the given arguments. May return null. + * Instantiates a class template with the given arguments. May return {@code null}. */ private static IBinding instantiate(ICPPClassTemplate template, ICPPTemplateArgument[] args, boolean isDefinition, boolean isExplicitSpecialization, IASTNode point) { @@ -176,7 +176,7 @@ public class CPPTemplates { ICPPTemplateArgument[] arguments= SemanticUtil.getSimplifiedArguments(args); arguments= addDefaultArguments(template, arguments, point); if (arguments == null) - return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point); if (template instanceof ICPPTemplateTemplateParameter || hasDependentArgument(arguments)) { return deferredInstance(template, arguments); @@ -201,14 +201,14 @@ public class CPPTemplates { param= parameters[i]; isPack= param.isParameterPack(); } else { - return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point); } } if (i < numArgs) { ICPPTemplateArgument arg= arguments[i]; ICPPTemplateArgument newArg = CPPTemplates.matchTemplateParameterAndArgument(param, arg, map, point); if (newArg == null) - return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS); + return createProblem(template, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, point); if (newArg != arg) { if (arguments == args) { arguments= args.clone(); @@ -248,9 +248,8 @@ public class CPPTemplates { } } - private static IBinding createProblem(ICPPClassTemplate template, int id) { - IASTNode node= new CPPASTName(template.getNameCharArray()); - return new ProblemBinding(node, id, template.getNameCharArray()); + private static IBinding createProblem(ICPPClassTemplate template, int id, IASTNode point) { + return new ProblemBinding(point, id, template.getNameCharArray()); } static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) { @@ -320,7 +319,6 @@ public class CPPTemplates { /** * Instantiates a partial class template specialization. - * @param point */ private static IBinding instantiatePartialSpecialization( ICPPClassTemplatePartialSpecialization partialSpec, ICPPTemplateArgument[] args, boolean isDef, @@ -342,12 +340,11 @@ public class CPPTemplates { } /** - * Instantiates the selected template, without looking for specializations. May return null. - * @param map + * Instantiates the selected template, without looking for specializations. + * May return {@code null}. */ private static IBinding instantiatePrimaryTemplate(ICPPClassTemplate template, ICPPTemplateArgument[] arguments, CPPTemplateParameterMap map, boolean isDef, IASTNode point) throws DOMException { - assert !(template instanceof ICPPClassTemplatePartialSpecialization); ICPPTemplateInstance instance= getInstance(template, arguments, isDef); if (instance != null) { @@ -424,7 +421,7 @@ public class CPPTemplates { if (tpars[tparCount - 1].isParameterPack()) return arguments; - if (havePackExpansion && tparCount + 1 == argCount) + if (havePackExpansion && tparCount+1 == argCount) return arguments; return null; } @@ -492,11 +489,11 @@ public class CPPTemplates { if (tp.isParameterPack()) { t= new CPPParameterPackType(t); } - args[i] = new CPPTemplateArgument(t); + args[i] = new CPPTemplateTypeArgument(t); } else if (tp instanceof ICPPTemplateNonTypeParameter) { // Non-type template parameter pack already has type 'ICPPParameterPackType' final ICPPTemplateNonTypeParameter nttp = (ICPPTemplateNonTypeParameter) tp; - args[i] = new CPPTemplateArgument(Value.create(nttp), nttp.getType()); + args[i] = new CPPTemplateNonTypeArgument(Value.create(nttp), nttp.getType()); } else { assert false; } @@ -597,7 +594,7 @@ public class CPPTemplates { public static IBinding createBinding(ICPPASTTemplateId id) { if (!isClassTemplate(id)) { - //functions are instantiated as part of the resolution process + // Functions are instantiated as part of the resolution process. IBinding result= CPPVisitor.createBinding(id); IASTName templateName = id.getTemplateName(); if (result instanceof ICPPClassTemplate) { @@ -642,7 +639,7 @@ public class CPPTemplates { } } try { - // class template instance + // Class template instance. IBinding result= null; IASTName templateName = id.getTemplateName(); IBinding template = templateName.resolvePreBinding(); @@ -795,12 +792,13 @@ public class CPPTemplates { IType[] exceptionSpecs= instantiateTypes(func.getExceptionSpecification(), tpMap, -1, within, point); if (decl instanceof ICPPFunctionTemplate) { - if (decl instanceof ICPPConstructor) + if (decl instanceof ICPPConstructor) { spec = new CPPConstructorTemplateSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs); - else if (decl instanceof ICPPMethod) + } else if (decl instanceof ICPPMethod) { spec = new CPPMethodTemplateSpecialization((ICPPMethod) decl, owner, tpMap, type, exceptionSpecs); - else + } else { spec = new CPPFunctionTemplateSpecialization((ICPPFunctionTemplate) decl, owner, tpMap, type, exceptionSpecs); + } } else if (decl instanceof ICPPConstructor) { spec = new CPPConstructorSpecialization((ICPPConstructor) decl, owner, tpMap, type, exceptionSpecs); } else if (decl instanceof ICPPMethod) { @@ -845,7 +843,7 @@ public class CPPTemplates { return null; ICPPClassSpecialization within= (ICPPClassSpecialization) owner; ICPPClassType orig = within.getSpecializedBinding(); - for (;;) { + while (true) { IBinding o1 = within.getOwner(); IBinding o2 = orig.getOwner(); if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType)) @@ -862,43 +860,20 @@ public class CPPTemplates { ICPPClassSpecialization within, int maxdepth, IASTNode point) { if (value == null) return null; - IBinding[] unknowns= value.getUnknownBindings(); - IBinding[] resolvedUnknowns= null; - if (unknowns.length != 0) { - for (int i = 0; i < unknowns.length; i++) { - IBinding unknown= unknowns[i]; - IBinding resolved= unknown; - if (unknown instanceof ICPPUnknownBinding) { - try { - resolved= resolveUnknown((ICPPUnknownBinding) unknown, tpMap, packOffset, within, point); - } catch (DOMException e) { - return Value.UNKNOWN; - } - } - if (resolvedUnknowns != null) { - resolvedUnknowns[i]= resolved; - } else if (resolved != unknown) { - resolvedUnknowns= new IBinding[unknowns.length]; - System.arraycopy(unknowns, 0, resolvedUnknowns, 0, i); - resolvedUnknowns[i]= resolved; - } - } - } - - if (resolvedUnknowns != null) - return Value.reevaluate(value, packOffset, resolvedUnknowns, tpMap, maxdepth); - - if (Value.referencesTemplateParameter(value)) - return Value.reevaluate(value, packOffset, unknowns, tpMap, maxdepth); - - return value; + ICPPEvaluation evaluation = value.getEvaluation(); + if (evaluation == null) + return value; + ICPPEvaluation instantiated = evaluation.instantiate(tpMap, packOffset, within, maxdepth, point); + if (instantiated == evaluation) + return value; + return instantiated.getValue(point); } public static boolean containsParameterPack(IType type) { return determinePackSize(type, CPPTemplateParameterMap.EMPTY) == PACK_SIZE_DEFER; } - private static int determinePackSize(IType type, ICPPTemplateParameterMap tpMap) { + static int determinePackSize(IType type, ICPPTemplateParameterMap tpMap) { if (type instanceof ICPPFunctionType) { final ICPPFunctionType ft = (ICPPFunctionType) type; final IType rt = ft.getReturnType(); @@ -907,7 +882,7 @@ public class CPPTemplates { return r; IType[] ps = ft.getParameterTypes(); for (IType pt : ps) { - r= combine(r, determinePackSize(pt, tpMap)); + r= combinePackSize(r, determinePackSize(pt, tpMap)); if (r < 0) return r; } @@ -915,37 +890,17 @@ public class CPPTemplates { } if (type instanceof ICPPTemplateParameter) { - final ICPPTemplateParameter tpar = (ICPPTemplateParameter) type; - if (tpar.isParameterPack()) { - ICPPTemplateArgument[] args= tpMap.getPackExpansion(tpar); - if (args != null) - return args.length; - return PACK_SIZE_DEFER; - } - return PACK_SIZE_NOT_FOUND; + return determinePackSize((ICPPTemplateParameter) type, tpMap); } - int r= PACK_SIZE_NOT_FOUND; if (type instanceof ICPPUnknownBinding) { - if (type instanceof ICPPDeferredClassInstance) { - ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) type; - ICPPTemplateArgument[] args = dcl.getTemplateArguments(); - for (ICPPTemplateArgument arg : args) { - r= combine(r, determinePackSize(arg, tpMap)); - if (r < 0) - return r; - } - } - IBinding binding= ((ICPPUnknownBinding) type).getOwner(); - if (binding instanceof IType) - r= combine(r, determinePackSize((IType) binding, tpMap)); - - return r; + return determinePackSize((ICPPUnknownBinding) type, tpMap); } if (type instanceof ICPPParameterPackType) return PACK_SIZE_NOT_FOUND; + int r= PACK_SIZE_NOT_FOUND; if (type instanceof IArrayType) { IArrayType at= (IArrayType) type; IValue asize= at.getSize(); @@ -956,12 +911,54 @@ public class CPPTemplates { if (type instanceof ITypeContainer) { final ITypeContainer typeContainer = (ITypeContainer) type; - r= combine(r, determinePackSize(typeContainer.getType(), tpMap)); + r= combinePackSize(r, determinePackSize(typeContainer.getType(), tpMap)); } return r; } - private static int combine(int ps1, int ps2) { + static int determinePackSize(ICPPTemplateParameter tpar, ICPPTemplateParameterMap tpMap) { + if (tpar.isParameterPack()) { + ICPPTemplateArgument[] args= tpMap.getPackExpansion(tpar); + if (args != null) + return args.length; + return PACK_SIZE_DEFER; + } + return PACK_SIZE_NOT_FOUND; + } + + static int determinePackSize(ICPPUnknownBinding binding, ICPPTemplateParameterMap tpMap) { + int r= PACK_SIZE_NOT_FOUND; + if (binding instanceof ICPPDeferredClassInstance) { + ICPPDeferredClassInstance dcl= (ICPPDeferredClassInstance) binding; + ICPPTemplateArgument[] args = dcl.getTemplateArguments(); + for (ICPPTemplateArgument arg : args) { + r= combinePackSize(r, determinePackSize(arg, tpMap)); + if (r < 0) + return r; + } + } + IBinding ownerBinding= binding.getOwner(); + if (ownerBinding instanceof IType) + r= combinePackSize(r, determinePackSize((IType) ownerBinding, tpMap)); + + return r; + } + + static int determinePackSize(IValue value, ICPPTemplateParameterMap tpMap) { + ICPPEvaluation eval = value.getEvaluation(); + if (eval == null) + return PACK_SIZE_NOT_FOUND; + + return ((CPPEvaluation) eval).determinePackSize(tpMap); + } + + static int determinePackSize(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap) { + if (arg.isTypeValue()) + return determinePackSize(arg.getTypeValue(), tpMap); + return determinePackSize(arg.getNonTypeValue(), tpMap); + } + + static int combinePackSize(int ps1, int ps2) { if (ps1 < 0 || ps2 == PACK_SIZE_NOT_FOUND) return ps1; if (ps2 < 0 || ps1 == PACK_SIZE_NOT_FOUND) @@ -971,43 +968,14 @@ public class CPPTemplates { return ps1; } - private static int determinePackSize(IValue value, ICPPTemplateParameterMap tpMap) { - int r= PACK_SIZE_NOT_FOUND; - IBinding[] unknown= value.getUnknownBindings(); - for (IBinding binding : unknown) { - if (binding instanceof IType) { - r= combine(r, determinePackSize((IType) binding, tpMap)); - if (r < 0) - return r; - } - } - int[] tpars= Value.getParameterPackReferences(value); - for (int parID : tpars) { - ICPPTemplateArgument[] args= tpMap.getPackExpansion(parID); - if (args != null) { - r= combine(r, args.length); - if (r < 0) - return r; - } - return PACK_SIZE_DEFER; - } - return r; - } - - private static int determinePackSize(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap) { - if (arg.isTypeValue()) - return determinePackSize(arg.getTypeValue(), tpMap); - return determinePackSize(arg.getNonTypeValue(), tpMap); - } - /** * Instantiates types contained in an array. * @param types an array of types * @param tpMap template argument map - * @param point * @return an array containing instantiated types. */ - public static IType[] instantiateTypes(IType[] types, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { + public static IType[] instantiateTypes(IType[] types, ICPPTemplateParameterMap tpMap, + int packOffset, ICPPClassSpecialization within, IASTNode point) { if (types == null) return null; @@ -1021,7 +989,8 @@ public class CPPTemplates { origType= ((ICPPParameterPackType) origType).getType(); int packSize= determinePackSize(origType, tpMap); if (packSize == PACK_SIZE_FAIL || packSize == PACK_SIZE_NOT_FOUND) { - newType= new ProblemBinding(null, IProblemBinding.SEMANTIC_INVALID_TYPE); + newType= new ProblemBinding(point, IProblemBinding.SEMANTIC_INVALID_TYPE, + types[i] instanceof IBinding ? ((IBinding) types[i]).getNameCharArray() : null); } else if (packSize == PACK_SIZE_DEFER) { newType= origType; } else { @@ -1052,7 +1021,6 @@ public class CPPTemplates { /** * Instantiates arguments contained in an array. - * @param point */ public static ICPPTemplateArgument[] instantiateArguments(ICPPTemplateArgument[] args, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) @@ -1067,7 +1035,7 @@ public class CPPTemplates { origArg= origArg.getExpansionPattern(); int packSize= determinePackSize(origArg, tpMap); if (packSize == PACK_SIZE_FAIL || packSize == PACK_SIZE_NOT_FOUND) { - throw new DOMException(new ProblemBinding(null, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS)); + throw new DOMException(new ProblemBinding(point, IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS, null)); } else if (packSize == PACK_SIZE_DEFER) { newArg= origArg; } else { @@ -1100,7 +1068,6 @@ public class CPPTemplates { /** * Instantiates an argument - * @param point */ static ICPPTemplateArgument instantiateArgument(ICPPTemplateArgument arg, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { @@ -1113,14 +1080,14 @@ public class CPPTemplates { final IType instType= instantiateType(origType, tpMap, packOffset, within, point); if (origType == instType && origValue == instValue) return arg; - return new CPPTemplateArgument(instValue, instType); + return new CPPTemplateNonTypeArgument(instValue, instType); } final IType orig= arg.getTypeValue(); final IType inst= instantiateType(orig, tpMap, packOffset, within, point); if (orig == inst) return arg; - return new CPPTemplateArgument(inst); + return new CPPTemplateTypeArgument(inst); } private static CPPTemplateParameterMap instantiateArgumentMap(ICPPTemplateParameterMap orig, ICPPTemplateParameterMap tpMap, @@ -1148,7 +1115,6 @@ public class CPPTemplates { /** * Instantiates the given type with the provided map and packОffset. * The context is used to replace templates with their specialization, where appropriate. - * @param point */ public static IType instantiateType(IType type, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, IASTNode point) { @@ -1185,7 +1151,8 @@ public class CPPTemplates { ICPPTemplateArgument[] args = tpMap.getPackExpansion(tpar); if (args != null) { if (packOffset >= args.length) { - return new ProblemBinding(null, IProblemBinding.SEMANTIC_INVALID_TYPE); + return new ProblemBinding(point, IProblemBinding.SEMANTIC_INVALID_TYPE, + tpar.getNameCharArray()); } arg= args[packOffset]; } @@ -1287,6 +1254,13 @@ public class CPPTemplates { return typeContainer; } + if (type instanceof TypeOfDependentExpression) { + ICPPEvaluation eval = ((TypeOfDependentExpression) type).getEvaluation(); + ICPPEvaluation instantiated = eval.instantiate(tpMap, packOffset, within, Value.MAX_RECURSION_DEPTH, point); + if (instantiated != eval) + return instantiated.getTypeOrFunctionSet(point); + } + return type; } catch (DOMException e) { return e.getProblem(); @@ -1294,15 +1268,15 @@ public class CPPTemplates { } /** - * Checks whether a given name corresponds to a template declaration and returns the ast node for it. - * This works for the name of a template-definition and also for a name needed to qualify a member - * definition: + * Checks whether a given name corresponds to a template declaration and returns the AST node + * for it. This works for the name of a template-definition and also for a name needed to + * qualify a member definition: *

-	 * template <typename T> void MyTemplate<T>::member() {}
+	 * template <typename T> void MyTemplate<T>::member() {}
 	 * 
* @param name a name for which the corresponding template declaration is searched for. - * @return the template declaration or null if name does not - * correspond to a template declaration. + * @return the template declaration or {@code null} if {@code name} does not correspond + * to a template declaration. */ public static ICPPASTTemplateDeclaration getTemplateDeclaration(IASTName name) { if (name == null) @@ -1319,7 +1293,7 @@ public class CPPTemplates { if (parent instanceof ICPPASTTemplateId) { return null; } - // one name: use innermost template declaration + // One name: use innermost template declaration return tdecl; } @@ -1334,7 +1308,7 @@ public class CPPTemplates { return null; } - // not the last name, search for the matching template declaration + // Not the last name, search for the matching template declaration if (!(name instanceof ICPPASTTemplateId)) return null; @@ -1343,7 +1317,7 @@ public class CPPTemplates { tdecl= getDirectlyEnclosingTemplateDeclaration(tdecl); } final IASTName[] ns= qname.getNames(); - for (int i = ns.length-2; tdecl != null && i >= 0; i--) { + for (int i = ns.length - 2; tdecl != null && i >= 0; i--) { final IASTName n = ns[i]; if (n == name) { return tdecl; @@ -1439,17 +1413,17 @@ public class CPPTemplates { b= b.getOwner(); } if (depIDCount > 0) { - nestingLevel += depIDCount; + nestingLevel+= depIDCount; } else if (consumesTDecl < tdeclCount && !lastIsTemplate) { nestingLevel++; lastIsTemplate= true; } } else { - nestingLevel += depIDCount; + nestingLevel+= depIDCount; node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1462,7 +1436,7 @@ public class CPPTemplates { node= outerMostTDecl.getParent(); while (node != null) { if (node instanceof ICPPASTInternalTemplateDeclaration) { - nestingLevel += ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; + nestingLevel+= ((ICPPASTInternalTemplateDeclaration) node).getNestingLevel() + 1; break; } node= node.getParent(); @@ -1471,7 +1445,7 @@ public class CPPTemplates { } node= innerMostTDecl; - while (node instanceof ICPPASTInternalTemplateDeclaration) { + while(node instanceof ICPPASTInternalTemplateDeclaration) { if (--nestingLevel < 0) nestingLevel= 0; tdecl= (ICPPASTInternalTemplateDeclaration) node; @@ -1501,7 +1475,7 @@ public class CPPTemplates { private static CharArraySet collectTemplateParameterNames(ICPPASTTemplateDeclaration tdecl) { CharArraySet set= new CharArraySet(4); - while (true) { + while(true) { ICPPASTTemplateParameter[] pars = tdecl.getTemplateParameters(); for (ICPPASTTemplateParameter par : pars) { IASTName name= CPPTemplates.getTemplateParameterName(par); @@ -1521,7 +1495,7 @@ public class CPPTemplates { private static boolean usesTemplateParameter(final ICPPASTTemplateId id, final CharArraySet names) { final boolean[] result= {false}; ASTVisitor v= new ASTVisitor(false) { - { shouldVisitNames= true; shouldVisitAmbiguousNodes= true; } + { shouldVisitNames= true; shouldVisitAmbiguousNodes=true;} @Override public int visit(IASTName name) { if (name instanceof ICPPASTTemplateId) @@ -1613,7 +1587,7 @@ public class CPPTemplates { } private static ICPPASTInternalTemplateDeclaration getDirectlyEnclosingTemplateDeclaration( - ICPPASTInternalTemplateDeclaration tdecl) { + ICPPASTInternalTemplateDeclaration tdecl ) { final IASTNode parent= tdecl.getParent(); if (parent instanceof ICPPASTInternalTemplateDeclaration) return (ICPPASTInternalTemplateDeclaration) parent; @@ -1643,10 +1617,11 @@ public class CPPTemplates { name = dtor.getName(); } else if (simple.getDeclarators().length == 0) { IASTDeclSpecifier spec = simple.getDeclSpecifier(); - if (spec instanceof ICPPASTCompositeTypeSpecifier) + if (spec instanceof ICPPASTCompositeTypeSpecifier) { name = ((ICPPASTCompositeTypeSpecifier) spec).getName(); - else if (spec instanceof ICPPASTElaboratedTypeSpecifier) + } else if (spec instanceof ICPPASTElaboratedTypeSpecifier) { name = ((ICPPASTElaboratedTypeSpecifier) spec).getName(); + } } } else if (nestedDecl instanceof IASTFunctionDefinition) { IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator(); @@ -1662,11 +1637,10 @@ public class CPPTemplates { if (currDecl == templateDecl) { return ns[j]; } - if (currDecl instanceof ICPPASTTemplateDeclaration) { - currDecl = ((ICPPASTTemplateDeclaration) currDecl).getDeclaration(); - } else { + if (!(currDecl instanceof ICPPASTTemplateDeclaration)) { return null; } + currDecl = ((ICPPASTTemplateDeclaration) currDecl).getDeclaration(); } } } else { @@ -1691,7 +1665,7 @@ public class CPPTemplates { /** * @param id the template id containing the template arguments * @return an array of template arguments, currently modeled as IType objects. - * The empty ICPPTemplateArgument array is returned if id is null + * The empty ICPPTemplateArgument array is returned if id is {@code null} */ public static ICPPTemplateArgument[] createTemplateArgumentArray(ICPPASTTemplateId id) { ICPPTemplateArgument[] result= ICPPTemplateArgument.EMPTY_ARGUMENTS; @@ -1701,16 +1675,12 @@ public class CPPTemplates { for (int i = 0; i < args.length; i++) { IASTNode arg= args[i]; if (arg instanceof IASTTypeId) { - result[i]= new CPPTemplateArgument(CPPVisitor.createType((IASTTypeId) arg)); + result[i]= new CPPTemplateTypeArgument(CPPVisitor.createType((IASTTypeId) arg)); } else if (arg instanceof IASTExpression) { IASTExpression expr= (IASTExpression) arg; IType type= expr.getExpressionType(); IValue value= Value.create((IASTExpression) arg, Value.MAX_RECURSION_DEPTH); - result[i]= new CPPTemplateArgument(value, type); - } else if (arg instanceof ICPPASTAmbiguousTemplateArgument) { - throw new IllegalArgumentException(id.getRawSignature() - + " contains an ambiguous template argument at position " + i + " in " //$NON-NLS-1$ //$NON-NLS-2$ - + id.getContainingFilename()); + result[i]= new CPPTemplateNonTypeArgument(value, type); } else { throw new IllegalArgumentException("Unexpected type: " + arg.getClass().getName()); //$NON-NLS-1$ } @@ -1922,7 +1892,7 @@ public class CPPTemplates { CPPTemplateParameterMap map = new CPPTemplateParameterMap(argLen); for (int i = 0; i < argLen; i++) { final ICPPTemplateParameter tpar = tpars[i]; - final CPPTemplateArgument arg = uniqueArg(tpar); + final ICPPTemplateArgument arg = uniqueArg(tpar); args[i]= arg; if (tpar.isParameterPack()) { map.put(tpar, new ICPPTemplateArgument[] {arg}); @@ -1938,12 +1908,12 @@ public class CPPTemplates { return null; } - private static CPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { - final CPPTemplateArgument arg; + private static ICPPTemplateArgument uniqueArg(final ICPPTemplateParameter tpar) throws DOMException { + final ICPPTemplateArgument arg; if (tpar instanceof ICPPTemplateNonTypeParameter) { - arg = new CPPTemplateArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); + arg = new CPPTemplateNonTypeArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) tpar).getType()); } else { - arg = new CPPTemplateArgument(new UniqueType(tpar.isParameterPack())); + arg = new CPPTemplateTypeArgument(new UniqueType(tpar.isParameterPack())); } return arg; } @@ -1998,7 +1968,7 @@ public class CPPTemplates { } private static IType[] concat(final IType t, IType[] types) { - IType[] result= new IType[types.length + 1]; + IType[] result= new IType[types.length+1]; result[0]= t; System.arraycopy(types, 0, result, 1, types.length); return result; @@ -2027,28 +1997,32 @@ public class CPPTemplates { return null; } - ICPPClassTemplatePartialSpecialization bestMatch = null, spec = null; + ICPPClassTemplatePartialSpecialization bestMatch = null; CPPTemplateParameterMap bestMap= null; boolean bestMatchIsBest = true; for (ICPPClassTemplatePartialSpecialization specialization : specializations) { - spec = specialization; final CPPTemplateParameterMap map = new CPPTemplateParameterMap(args.length); - if (TemplateArgumentDeduction.fromTemplateArguments(spec.getTemplateParameters(), spec.getTemplateArguments(), args, map, point)) { - int compare = orderSpecializations(bestMatch, spec, point); + ICPPTemplateArgument[] specializationArguments = specialization.getTemplateArguments(); + if (TemplateArgumentDeduction.fromTemplateArguments(specialization.getTemplateParameters(), + specializationArguments, args, map, point) && + checkInstantiationOfArguments(specializationArguments, map, point)) { + int compare = orderSpecializations(bestMatch, specialization, point); if (compare == 0) { bestMatchIsBest = false; } else if (compare < 0) { - bestMatch = spec; + bestMatch = specialization; bestMap= map; bestMatchIsBest = true; } } } - //14.5.4.1 If none of the specializations is more specialized than all the other matching - //specializations, then the use of the class template is ambiguous and the program is ill-formed. + // 14.5.4.1 If none of the specializations is more specialized than all the other matching + // specializations, then the use of the class template is ambiguous and the program is + // ill-formed. if (!bestMatchIsBest) { - return new CPPTemplateDefinition.CPPTemplateProblem(null, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, null); + return new CPPTemplateDefinition.CPPTemplateProblem(point, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, template.getNameCharArray()); } if (bestMatch == null) @@ -2057,6 +2031,16 @@ public class CPPTemplates { return instantiatePartialSpecialization(bestMatch, args, isDef, bestMap, point); } + private static boolean checkInstantiationOfArguments(ICPPTemplateArgument[] args, + CPPTemplateParameterMap tpMap, IASTNode point) throws DOMException { + args = instantiateArguments(args, tpMap, -1, null, point); + for (ICPPTemplateArgument arg : args) { + if (!isValidArgument(arg)) + return false; + } + return true; + } + /** * Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2 * is more specialized, = 0 otherwise. @@ -2108,7 +2092,7 @@ public class CPPTemplates { final CPPTemplateParameterMap transferMap= new CPPTemplateParameterMap(tpars1Len); for (int i = 0; i < tpars1Len; i++) { final ICPPTemplateParameter param = tpars1[i]; - final CPPTemplateArgument arg = uniqueArg(param); + final ICPPTemplateArgument arg = uniqueArg(param); args[i]= arg; transferMap.put(param, arg); } @@ -2129,7 +2113,7 @@ public class CPPTemplates { } static boolean isValidType(IType t) { - for (;;) { + while (true) { if (t instanceof ISemanticProblem) { return false; } else if (t instanceof IFunctionType) { @@ -2207,7 +2191,7 @@ public class CPPTemplates { pType= instantiateType(pType, map, -1, null, point); } if (argType instanceof ICPPUnknownType || argType instanceof ISemanticProblem || isNonTypeArgumentConvertible(pType, argType, point)) { - return new CPPTemplateArgument(arg.getNonTypeValue(), pType); + return new CPPTemplateNonTypeArgument(arg.getNonTypeValue(), pType); } return null; @@ -2255,9 +2239,8 @@ public class CPPTemplates { } if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(), - ((ICPPTemplateTemplateParameter) ap).getTemplateParameters())) { + ((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) ) return false; - } } } if (!pp.isParameterPack()) @@ -2395,7 +2378,7 @@ public class CPPTemplates { public static boolean containsDependentArg(ObjectMap tpMap) { for (Object arg : tpMap.valueArray()) { - if (isDependentType((IType)arg)) + if (isDependentType((IType) arg)) return true; } return false; @@ -2429,9 +2412,9 @@ public class CPPTemplates { } } else if (!t.equals(owner)) { if (unknown instanceof ICPPUnknownClassType) { - result= new CPPUnknownClass((ICPPUnknownBinding)t, unknown.getNameCharArray()); + result= new CPPUnknownClass((ICPPUnknownBinding) t, unknown.getNameCharArray()); } else if (unknown instanceof IFunction) { - result= new CPPUnknownClass((ICPPUnknownBinding)t, unknown.getNameCharArray()); + result= new CPPUnknownClass((ICPPUnknownBinding) t, unknown.getNameCharArray()); } else { result= new CPPUnknownBinding((ICPPUnknownBinding) t, unknown.getNameCharArray()); } @@ -2439,7 +2422,7 @@ public class CPPTemplates { } else if (t instanceof ICPPClassType) { IScope s = ((ICPPClassType) t).getCompositeScope(); if (s != null) { - result= CPPSemantics.resolveUnknownName(s, unknown); + result= CPPSemantics.resolveUnknownName(s, unknown, point); if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) { ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments( ((ICPPUnknownClassInstance) unknown).getArguments(), tpMap, packOffset, within, point); @@ -2449,7 +2432,7 @@ public class CPPTemplates { } } } else if (t != owner) { - return new ProblemBinding(unknown.getUnknownName(), IProblemBinding.SEMANTIC_BAD_SCOPE); + return new ProblemBinding(unknown.getUnknownName(), point, IProblemBinding.SEMANTIC_BAD_SCOPE); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java index cb3e0dad436..4086f1bd98c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVariableReadWriteFlags.java @@ -61,7 +61,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags { IType type = CPPVisitor.createType(parent); if (type instanceof ICPPUnknownType || type instanceof ICPPClassType && - !ClassTypeHelper.hasTrivialDefaultConstructor((ICPPClassType) type)) { + !ClassTypeHelper.hasTrivialDefaultConstructor((ICPPClassType) type, parent)) { return WRITE; } return super.rwInDeclarator(parent, indirection); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index f6369015283..156131e6509 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -13,7 +13,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; import java.util.ArrayList; import java.util.Arrays; @@ -157,6 +161,7 @@ import org.eclipse.cdt.core.parser.util.AttributeUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; 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.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; @@ -191,8 +196,8 @@ 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.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownTypeScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; @@ -996,7 +1001,8 @@ public class CPPVisitor extends ASTQueries { return result; } - } else if (node instanceof IASTParameterDeclaration) { + } else if (node instanceof IASTParameterDeclaration || + node.getPropertyInParent() == ICPPASTFunctionDeclarator.NOEXCEPT_EXPRESSION) { IASTNode parent = node.getParent(); if (parent instanceof ICPPASTFunctionDeclarator) { IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent); @@ -1007,8 +1013,8 @@ public class CPPVisitor extends ASTQueries { } } else if (node instanceof IASTInitializer) { if (node instanceof ICPPASTConstructorChainInitializer) { - // The name of the member initializer is resolved in the scope of the - // owner of the ctor. + // The name of the member initializer is resolved in the scope of + // the owner of the ctor. ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node; IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent(); IBinding binding = fdef.getDeclarator().getName().resolveBinding(); @@ -2029,7 +2035,7 @@ public class CPPVisitor extends ASTQueries { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); } type = (IType) CPPTemplates.instantiate(initializer_list_template, - new ICPPTemplateArgument[] { new CPPTemplateArgument(type) }, initClause); + new ICPPTemplateArgument[] { new CPPTemplateTypeArgument(type) }, initClause); if (type instanceof IProblemBinding) { return new ProblemType(ISemanticProblem.TYPE_CANNOT_DEDUCE_AUTO_TYPE); } @@ -2058,7 +2064,7 @@ public class CPPVisitor extends ASTQueries { type = t; if (initClause instanceof ICPPASTInitializerList) { type = (IType) CPPTemplates.instantiate(initializer_list_template, - new ICPPTemplateArgument[] { new CPPTemplateArgument(type) }, initClause); + new ICPPTemplateArgument[] { new CPPTemplateTypeArgument(type) }, initClause); } return decorateType(type, declSpec, declarator); } @@ -2236,7 +2242,10 @@ public class CPPVisitor extends ASTQueries { } private static IType getStdType(final IASTNode node, char[] name) { - IBinding[] std= node.getTranslationUnit().getScope().find(STD); + if (node == null) + return null; + ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit(); + IBinding[] std= ast.getScope().find(STD); for (IBinding binding : std) { if (binding instanceof ICPPNamespace) { final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java index cd3f8035b3b..76b0fbaa3fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CVQualifier.java @@ -6,11 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; - /** * Represents the possible cv-qualification of a type. */ @@ -23,16 +22,19 @@ public enum CVQualifier { private static final int R = 4; final private int fQualifiers; + private CVQualifier(int qualifiers) { fQualifiers= qualifiers; } - + public boolean isConst() { return (fQualifiers & C) != 0; } + public boolean isVolatile() { return (fQualifiers & V) != 0; } + public boolean isRestrict() { return (fQualifiers & R) != 0; } @@ -54,7 +56,7 @@ public enum CVQualifier { } private CVQualifier fromQualifier(final int q) { - switch(q) { + switch (q) { case C|V|R: return CONST_VOLATILE_RESTRICT; case V|R: return VOLATILE_RESTRICT; case C|R: return CONST_RESTRICT; @@ -65,7 +67,7 @@ public enum CVQualifier { case 0: default: return NONE; } } - + /** * [3.9.3-4] Implements cv-qualification (partial) comparison. There is a (partial) * ordering on cv-qualifiers, so that a type can be said to be more @@ -83,12 +85,12 @@ public enum CVQualifier { * */ public int partialComparison(CVQualifier cv2) { - // same qualifications + // Same qualifications. if (this == cv2) return 0; if (!isAtLeastAsQualifiedAs(cv2)) return -1; - return fQualifiers-cv2.fQualifiers; + return fQualifiers - cv2.fQualifiers; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java index 1a63d462fee..ccf06ec82a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Conversions.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) - * Sergey Prigogin (Google) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -30,9 +30,7 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import java.util.Collections; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; -import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IBasicType; @@ -60,7 +58,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; -import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; @@ -75,8 +72,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.ReferenceBind * Routines for calculating the cost of conversions. */ public class Conversions { - public enum UDCMode {ALLOWED, FORBIDDEN, DEFER} - public enum Context {ORDINARY, IMPLICIT_OBJECT, FIRST_PARAM_OF_DIRECT_COPY_CTOR, REQUIRE_DIRECT_BINDING} + public enum UDCMode { ALLOWED, FORBIDDEN, DEFER } + public enum Context { ORDINARY, IMPLICIT_OBJECT, FIRST_PARAM_OF_DIRECT_COPY_CTOR, REQUIRE_DIRECT_BINDING } private static final char[] INITIALIZER_LIST_NAME = "initializer_list".toCharArray(); //$NON-NLS-1$ private static final char[] STD_NAME = "std".toCharArray(); //$NON-NLS-1$ @@ -135,7 +132,7 @@ public class Conversions { // [for overload resolution bit-fields are treated the same, error if selected as best match] if (valueCat == LVALUE) { // ... and "cv1 T1" is reference-compatible with "cv2 T2" - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -145,7 +142,7 @@ public class Conversions { // implicitly converted to an lvalue of type 'cv3 T3', where 'cv1 T1' is reference-compatible with // 'cv3 T3' (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) // and choosing the best one through overload resolution (13.3)), - if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { + if (T2 instanceof ICPPClassType && udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2, point) < 0) { Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, true, ctx, point); if (cost != null) { cost.setReferenceBinding(refBindingType); @@ -195,7 +192,7 @@ public class Conversions { // ... the initializer expression is an rvalue and 'cv1 T1' is reference-compatible with 'cv2 T2' // ..., then the reference is bound to the initializer expression rvalue in the first case if (valueCat.isRValue()) { - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { // [13.3.3.1.4-1] direct binding has either identity or conversion rank. if (cost.getInheritanceDistance() > 0) { @@ -212,7 +209,7 @@ public class Conversions { // resolution (13.3)), then the reference is bound to the initializer expression rvalue in the // first case and to the object that is the result of the conversion in the second case (or, // in either case, to the appropriate base class sub-object of the object). - if (udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2) < 0) { + if (udc != UDCMode.FORBIDDEN && isReferenceRelated(T1, T2, point) < 0) { Cost cost= initializationByConversionForDirectReference(cv1T1, cv2T2, (ICPPClassType) T2, false, ctx, point); if (cost != null) { cost.setReferenceBinding(refBindingType); @@ -225,7 +222,7 @@ public class Conversions { // reference-compatible with 'cv2 T2' the reference is bound to the object represented by the // rvalue (see 3.10). if (T2 instanceof IArrayType && valueCat.isRValue()) { - Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject); + Cost cost= isReferenceCompatible(cv1T1, cv2T2, isImpliedObject, point); if (cost != null) { cost.setReferenceBinding(refBindingType); return cost; @@ -239,7 +236,7 @@ public class Conversions { // 13.3.3.1.7 no temporary object when converting the implicit object parameter if (!isImpliedObject && ctx != Context.REQUIRE_DIRECT_BINDING) { - if (isReferenceRelated(T1, T2) < 0 || compareQualifications(cv1T1, cv2T2) >= 0) { + if (isReferenceRelated(T1, T2, point) < 0 || compareQualifications(cv1T1, cv2T2) >= 0) { Cost cost= nonReferenceConversion(valueCat, cv2T2, T1, udc, point); if (cost.converts()) { cost.setReferenceBinding(refBindingType); @@ -260,7 +257,7 @@ public class Conversions { */ private static Cost initializationByConversionForDirectReference(final IType cv1T1, final IType cv2T2, final ICPPClassType T2, boolean needLValue, Context ctx, IASTNode point) throws DOMException { - ICPPMethod[] fcns= SemanticUtil.getConversionOperators(T2); + ICPPMethod[] fcns= SemanticUtil.getConversionOperators(T2, point); Cost operatorCost= null; FunctionCost bestUdcCost= null; boolean ambiguousConversionOperator= false; @@ -276,14 +273,14 @@ public class Conversions { final boolean isLValueRef= t instanceof ICPPReferenceType && !((ICPPReferenceType) t).isRValueReference(); if (isLValueRef == needLValue) { // require an lvalue or rvalue IType implicitParameterType= CPPSemantics.getImplicitParameterType(op); - Cost udcCost= isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true); // expression type to implicit object type + Cost udcCost= isReferenceCompatible(getNestedType(implicitParameterType, TDEF | REF), cv2T2, true, point); // expression type to implicit object type if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost udcFuncCost= new FunctionCost(op, udcCost); - int cmp= udcFuncCost.compareTo(null, bestUdcCost, point); + FunctionCost udcFuncCost= new FunctionCost(op, udcCost, point); + int cmp= udcFuncCost.compareTo(null, bestUdcCost); if (cmp <= 0) { - Cost cost= isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false); // converted to target + Cost cost= isReferenceCompatible(cv1T1, getNestedType(t, TDEF | REF), false, point); // converted to target if (cost != null) { bestUdcCost= udcFuncCost; ambiguousConversionOperator= cmp == 0; @@ -315,7 +312,7 @@ public class Conversions { if (uqTarget instanceof ICPPClassType) { if (uqSource instanceof ICPPClassType) { // 13.3.3.1-6 Conceptual derived to base conversion - int depth= calculateInheritanceDepth(uqSource, uqTarget); + int depth= calculateInheritanceDepth(uqSource, uqTarget, point); if (depth >= 0) { if (depth == 0) { return new Cost(source, target, Rank.IDENTITY); @@ -338,7 +335,7 @@ public class Conversions { return initializationByConversion(valueCat, source, (ICPPClassType) uqSource, target, udc == UDCMode.DEFER, point); } - return checkStandardConversionSequence(uqSource, target); + return checkStandardConversionSequence(uqSource, target, point); } /** @@ -371,7 +368,7 @@ public class Conversions { return Cost.NO_CONVERSION; ICPPClassType classTarget= (ICPPClassType) noCVTarget; - if (ClassTypeHelper.isAggregateClass(classTarget)) { + if (ClassTypeHelper.isAggregateClass(classTarget, point)) { Cost cost= new Cost(arg.getTypeOrFunctionSet(point), target, Rank.IDENTITY); cost.setUserDefinedConversion(null); return cost; @@ -439,7 +436,7 @@ public class Conversions { * Note this is not a symmetric relation. * @return inheritance distance, or -1, if cv1t1 is not reference-related to cv2t2 */ - private static final int isReferenceRelated(IType cv1Target, IType cv2Source) { + private static final int isReferenceRelated(IType cv1Target, IType cv2Source, IASTNode point) { IType t= SemanticUtil.getNestedType(cv1Target, TDEF | REF); IType s= SemanticUtil.getNestedType(cv2Source, TDEF | REF); @@ -474,7 +471,7 @@ public class Conversions { s= SemanticUtil.getNestedType(((IQualifierType) s).getType(), TDEF | REF); if (t instanceof ICPPClassType && s instanceof ICPPClassType) { - return SemanticUtil.calculateInheritanceDepth(s, t); + return SemanticUtil.calculateInheritanceDepth(s, t, point); } } if (t == s || (t != null && s != null && t.isSameType(s))) { @@ -490,8 +487,8 @@ public class Conversions { * @return The cost for converting or null if cv1t1 is not * reference-compatible with cv2t2 */ - private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject) { - int inheritanceDist= isReferenceRelated(cv1Target, cv2Source); + private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject, IASTNode point) { + int inheritanceDist= isReferenceRelated(cv1Target, cv2Source, point); if (inheritanceDist < 0) return null; final int cmp= compareQualifications(cv1Target, cv2Source); @@ -515,7 +512,7 @@ public class Conversions { * [4] Standard Conversions * Computes the cost of using the standard conversion sequence from source to target. */ - private static final Cost checkStandardConversionSequence(IType source, IType target) { + private static final Cost checkStandardConversionSequence(IType source, IType target, IASTNode point) { final Cost cost= new Cost(source, target, Rank.IDENTITY); if (lvalue_to_rvalue(cost)) return cost; @@ -523,7 +520,7 @@ public class Conversions { if (promotion(cost)) return cost; - if (conversion(cost)) + if (conversion(cost, point)) return cost; if (qualificationConversion(cost)) @@ -546,7 +543,7 @@ public class Conversions { ICPPConstructor usedCtor= null; Cost bestCost= null; boolean hasInitListConstructor= false; - final ICPPConstructor[] constructors = t.getConstructors(); + final ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(t, point); ICPPConstructor[] ctors= constructors; for (ICPPConstructor ctor : ctors) { final int minArgCount = ctor.getRequiredArgumentCount(); @@ -630,7 +627,8 @@ public class Conversions { /** * 13.3.1.4 Copy-initialization of class by user-defined conversion [over.match.copy] */ - static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, boolean deferUDC, IASTNode point) throws DOMException { + static final Cost copyInitializationOfClass(ValueCategory valueCat, IType source, ICPPClassType t, + boolean deferUDC, IASTNode point) throws DOMException { if (deferUDC) { Cost c= new Cost(source, t, Rank.USER_DEFINED_CONVERSION); c.setDeferredUDC(DeferredUDC.COPY_INIT_OF_CLASS); @@ -639,7 +637,7 @@ public class Conversions { FunctionCost cost1= null; Cost cost2= null; - ICPPFunction[] ctors= t.getConstructors(); + ICPPFunction[] ctors= ClassTypeHelper.getConstructors(t, point); ctors = CPPTemplates.instantiateForFunctionCall(ctors, null, Collections.singletonList(source), Collections.singletonList(valueCat), false, point); @@ -657,7 +655,7 @@ public class Conversions { FunctionCost c1; if (ptypes.length == 0) { if (ctor.takesVarArgs()) { - c1= new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION)); + c1= new FunctionCost(ctor, new Cost(source, null, Rank.ELLIPSIS_CONVERSION), point); } else { continue; } @@ -669,9 +667,9 @@ public class Conversions { if (ctor.getRequiredArgumentCount() > 1) continue; - c1= new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, UDCMode.FORBIDDEN, Context.ORDINARY, point)); + c1= new FunctionCost(ctor, checkImplicitConversionSequence(ptype, source, valueCat, UDCMode.FORBIDDEN, Context.ORDINARY, point), point); } - int cmp= c1.compareTo(null, cost1, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= new Cost(t, t, Rank.IDENTITY); @@ -685,7 +683,7 @@ public class Conversions { final IType uqSource= getNestedType(source, TDEF | REF | CVTYPE); if (uqSource instanceof ICPPClassType) { - ICPPFunction[] ops = SemanticUtil.getConversionOperators((ICPPClassType) uqSource); + ICPPFunction[] ops = SemanticUtil.getConversionOperators((ICPPClassType) uqSource, point); ops= CPPTemplates.instantiateConversionTemplates(ops, t, point); for (final ICPPFunction f : ops) { if (f instanceof ICPPMethod && !(f instanceof IProblemBinding)) { @@ -694,15 +692,15 @@ public class Conversions { continue; final IType returnType = op.getType().getReturnType(); final IType uqReturnType= getNestedType(returnType, REF | TDEF | CVTYPE); - final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t); + final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t, point); if (dist >= 0) { IType implicitType= CPPSemantics.getImplicitParameterType(op); - final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); + final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1, point); + FunctionCost c1= new FunctionCost(op, udcCost, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= new Cost(t, t, Rank.IDENTITY); @@ -735,7 +733,7 @@ public class Conversions { c.setDeferredUDC(DeferredUDC.INIT_BY_CONVERSION); return c; } - ICPPFunction[] ops = SemanticUtil.getConversionOperators(uqSource); + ICPPFunction[] ops = SemanticUtil.getConversionOperators(uqSource, point); ops= CPPTemplates.instantiateConversionTemplates(ops, target, point); FunctionCost cost1= null; Cost cost2= null; @@ -753,12 +751,12 @@ public class Conversions { if (isExplicitConversion && c2.getRank() != Rank.IDENTITY) continue; IType implicitType= CPPSemantics.getImplicitParameterType(op); - final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true); + final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point); if (udcCost != null) { // Make sure top-level cv-qualifiers are compared udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); - FunctionCost c1= new FunctionCost(op, udcCost); - int cmp= c1.compareTo(null, cost1, point); + FunctionCost c1= new FunctionCost(op, udcCost, point); + int cmp= c1.compareTo(null, cost1); if (cmp <= 0) { cost1= c1; cost2= c2; @@ -837,14 +835,10 @@ public class Conversions { if (srcQTarget.isConst() && !srcQTarget.isVolatile()) { srcTarget= srcQTarget.getType(); if (srcTarget instanceof CPPBasicType) { - IASTExpression val = ((CPPBasicType) srcTarget).getCreatedFromExpression(); - if (val instanceof IASTLiteralExpression) { - IASTLiteralExpression lit= (IASTLiteralExpression) val; - if (lit.getKind() == IASTLiteralExpression.lk_string_literal) { - source= new CPPPointerType(srcTarget, false, false, false); - CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST); - cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3); - } + if (((CPPBasicType) srcTarget).isFromStringLiteral()) { + source= new CPPPointerType(srcTarget, false, false, false); + CVQualifier cvqTarget = getCVQualifier(targetPtrTgt).add(CVQualifier.CONST); + cost.setQualificationAdjustment(cvqTarget.partialComparison(CVQualifier.NONE) << 3); } } } @@ -1014,7 +1008,7 @@ public class Conversions { * [4.10] Pointer conversions * [4.11] Pointer to member conversions */ - private static final boolean conversion(Cost cost){ + private static final boolean conversion(Cost cost, IASTNode point) { final IType s = cost.source; final IType t = cost.target; @@ -1085,7 +1079,7 @@ public class Conversions { // to an rvalue of type "pointer to cv B", where B is a base class of D. IType srcPtrTgt= getNestedType(srcPtr.getType(), TDEF | CVTYPE | REF); if (tgtPtrTgt instanceof ICPPClassType && srcPtrTgt instanceof ICPPClassType) { - int depth= SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt); + int depth= SemanticUtil.calculateInheritanceDepth(srcPtrTgt, tgtPtrTgt, point); if (depth == -1) { cost.setRank(Rank.NO_MATCH); return true; @@ -1108,7 +1102,7 @@ public class Conversions { IType tt = tpm.getType(); if (st != null && tt != null && st.isSameType(tt)) { int depth = SemanticUtil.calculateInheritanceDepth(tpm.getMemberOfClass(), - spm.getMemberOfClass()); + spm.getMemberOfClass(), point); if (depth == -1) { cost.setRank(Rank.NO_MATCH); return true; @@ -1133,12 +1127,9 @@ public class Conversions { if (basicType.getKind() == Kind.eNullPtr) return true; - IASTExpression exp = basicType.getCreatedFromExpression(); - if (exp != null) { - Long val= Value.create(exp, Value.MAX_RECURSION_DEPTH).numericalValue(); - if (val != null && val == 0) { - return true; - } + Long val = basicType.getAssociatedNumericalValue(); + if (val != null && val == 0) { + return true; } } return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java index e054cc9ddbd..cacff06b092 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java @@ -6,22 +6,19 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) - * Andrew Ferguson (Symbian) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.internal.core.dom.parser.ArithmeticConversion; -import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; /** @@ -114,7 +111,6 @@ public class Cost { public void setRank(Rank rank) { fRank= rank; } - public ReferenceBinding getReferenceBinding() { return fReferenceBinding; @@ -123,7 +119,6 @@ public class Cost { public void setReferenceBinding(ReferenceBinding binding) { fReferenceBinding= binding; } - public boolean isAmbiguousUDC() { return fAmbiguousUDC; @@ -274,14 +269,10 @@ public class Cost { if (targetKind != Kind.eInt && targetKind != Kind.eFloat && targetKind != Kind.eDouble) { return true; } - IASTExpression val = ((CPPBasicType) source).getCreatedFromExpression(); - if (val instanceof IASTLiteralExpression) { - // mstodo extend to constant expressions - Long l= Value.create(val, Value.MAX_RECURSION_DEPTH).numericalValue(); - if (l != null) { - long n= l.longValue(); - return !ArithmeticConversion.fitsIntoType(basicTarget, n); - } + Long val= ((CPPBasicType) source).getAssociatedNumericalValue(); + if (val != null) { + long n= val.longValue(); + return !ArithmeticConversion.fitsIntoType(basicTarget, n); } } return true; @@ -303,7 +294,7 @@ public class Cost { public void setSelectedFunction(ICPPFunction function) { fSelectedFunction= function; } - + public ICPPFunction getSelectedFunction() { return fSelectedFunction; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java index 0f119910e85..7eb375ebeb2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java @@ -7,28 +7,55 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_assign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryAndAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryOrAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_binaryXorAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_divideAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_equals; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_greaterEqual; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_greaterThan; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_lessEqual; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_lessThan; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_logicalAnd; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_logicalOr; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_minus; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_minusAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_moduloAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_multiplyAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_notequals; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_plus; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_plusAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_pmarrow; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_pmdot; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_shiftLeftAssign; +import static org.eclipse.cdt.core.dom.ast.IASTBinaryExpression.op_shiftRightAssign; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPASTBinaryExpression; +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.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; +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; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -102,7 +129,43 @@ public class EvalBinary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (getOverload(point) != null) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + IValue v1 = fArg1.getValue(point); + if (v1 == Value.UNKNOWN) + return Value.UNKNOWN; + IValue v2 = fArg2.getValue(point); + if (v2 == Value.UNKNOWN) + return Value.UNKNOWN; + + switch (fOperator) { + case op_equals: + if (v1.equals(v2)) + return Value.create(1); + break; + case op_notequals: + if (v1.equals(v2)) + return Value.create(0); + break; + } + + Long num1 = v1.numericalValue(); + if (num1 != null) { + if (num1 == 0) { + if (fOperator == op_logicalAnd) + return v1; + } else if (fOperator == op_logicalOr) { + return v1; + } + Long num2 = v2.numericalValue(); + if (num2 != null) { + return Value.evaluateBinaryExpression(fOperator, num1, num2); + } + } + return Value.create(this); } @Override @@ -129,25 +192,25 @@ public class EvalBinary extends CPPEvaluation { switch (fOperator) { case op_arrayAccess: - case IASTBinaryExpression.op_assign: - case IASTBinaryExpression.op_binaryAndAssign: - case IASTBinaryExpression.op_binaryOrAssign: - case IASTBinaryExpression.op_binaryXorAssign: - case IASTBinaryExpression.op_divideAssign: - case IASTBinaryExpression.op_minusAssign: - case IASTBinaryExpression.op_moduloAssign: - case IASTBinaryExpression.op_multiplyAssign: - case IASTBinaryExpression.op_plusAssign: - case IASTBinaryExpression.op_shiftLeftAssign: - case IASTBinaryExpression.op_shiftRightAssign: + case op_assign: + case op_binaryAndAssign: + case op_binaryOrAssign: + case op_binaryXorAssign: + case op_divideAssign: + case op_minusAssign: + case op_moduloAssign: + case op_multiplyAssign: + case op_plusAssign: + case op_shiftLeftAssign: + case op_shiftRightAssign: return LVALUE; - case IASTBinaryExpression.op_pmdot: + case op_pmdot: if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return fArg1.getValueCategory(point); break; - case IASTBinaryExpression.op_pmarrow: + case op_pmarrow: if (!(getTypeOrFunctionSet(point) instanceof ICPPFunctionType)) return LVALUE; break; @@ -215,17 +278,17 @@ public class EvalBinary extends CPPEvaluation { } return ProblemType.UNKNOWN_FOR_EXPRESSION; - case IASTBinaryExpression.op_lessEqual: - case IASTBinaryExpression.op_lessThan: - case IASTBinaryExpression.op_greaterEqual: - case IASTBinaryExpression.op_greaterThan: - case IASTBinaryExpression.op_logicalAnd: - case IASTBinaryExpression.op_logicalOr: - case IASTBinaryExpression.op_equals: - case IASTBinaryExpression.op_notequals: + case op_lessEqual: + case op_lessThan: + case op_greaterEqual: + case op_greaterThan: + case op_logicalAnd: + case op_logicalOr: + case op_equals: + case op_notequals: return CPPBasicType.BOOLEAN; - case IASTBinaryExpression.op_plus: + case op_plus: if (type1 instanceof IPointerType) { return ExpressionTypes.restoreTypedefs(type1, originalType1); } @@ -234,7 +297,7 @@ public class EvalBinary extends CPPEvaluation { } break; - case IASTBinaryExpression.op_minus: + case op_minus: if (type1 instanceof IPointerType) { if (type2 instanceof IPointerType) { return CPPVisitor.getPointerDiffType(point); @@ -243,13 +306,13 @@ public class EvalBinary extends CPPEvaluation { } break; - case ICPPASTBinaryExpression.op_pmarrow: - case ICPPASTBinaryExpression.op_pmdot: + case op_pmarrow: + case op_pmdot: if (type2 instanceof ICPPPointerToMemberType) { IType t= ((ICPPPointerToMemberType) type2).getType(); if (t instanceof ICPPFunctionType) return t; - if (fOperator == ICPPASTBinaryExpression.op_pmdot && fArg1.getValueCategory(point) == PRVALUE) { + if (fOperator == op_pmdot && fArg1.getValueCategory(point) == PRVALUE) { return prvalueType(t); } return glvalueType(t); @@ -273,4 +336,24 @@ public class EvalBinary extends CPPEvaluation { ICPPEvaluation arg2= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalBinary(op, arg1, arg2); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation arg1 = fArg1.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation arg2 = fArg2.instantiate(tpMap, packOffset, within, 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)); + } + + @Override + public boolean referencesTemplateParameter() { + return fArg1.referencesTemplateParameter() || fArg2.referencesTemplateParameter(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java index ae2d6bd9878..707e19f45e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinaryTypeId.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,11 +19,16 @@ 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; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +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; 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.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; /** @@ -74,7 +80,16 @@ public class EvalBinaryTypeId extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + switch (fOperator) { + case __is_base_of: + if (!(fType1 instanceof ICPPClassType) || !(fType1 instanceof ICPPClassType)) + return Value.UNKNOWN; + return Value.create(ClassTypeHelper.isSubclass((ICPPClassType) fType2, (ICPPClassType) fType1)); + } + return Value.create(this); } @Override @@ -110,4 +125,25 @@ public class EvalBinaryTypeId extends CPPEvaluation { IType arg2= buffer.unmarshalType(); return new EvalBinaryTypeId(Operator.values()[op], arg1, arg2); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type1 = CPPTemplates.instantiateType(fType1, tpMap, packOffset, within, point); + IType type2 = CPPTemplates.instantiateType(fType2, tpMap, packOffset, within, point); + if (type1 == fType1 && type2 == fType2) + return this; + return new EvalBinaryTypeId(fOperator, type1, type2); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.combinePackSize(CPPTemplates.determinePackSize(fType1, tpMap), + CPPTemplates.determinePackSize(fType2, tpMap)); + } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java index 2f75c840940..fbb50500da8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinding.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -22,11 +23,21 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IType; 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.ICPPMethod; +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; 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.ICPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.IInternalVariable; 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.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; @@ -40,7 +51,6 @@ public class EvalBinding extends CPPEvaluation { private boolean fIsTypeDependent; private boolean fCheckedIsTypeDependent; - public EvalBinding(IBinding binding, IType type) { fBinding= binding; fType= type; @@ -75,20 +85,19 @@ public class EvalBinding extends CPPEvaluation { } private boolean computeIsTypeDependent() { - if (fBinding instanceof ICPPUnknownBinding) - return true; - IType t= null; - if (fBinding instanceof IEnumerator) { + 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 IFunction) { - t= ((IFunction) fBinding).getType(); } else if (fBinding instanceof ICPPUnknownBinding) { return true; + } else if (fBinding instanceof IFunction) { + t= ((IFunction) fBinding).getType(); } else { return false; } @@ -114,12 +123,12 @@ public class EvalBinding extends CPPEvaluation { if (fBinding instanceof IVariable) { return Value.isDependentValue(((IVariable) fBinding).getInitialValue()); } - if (fBinding instanceof IFunction) { - return false; - } if (fBinding instanceof ICPPUnknownBinding) { return true; } + if (fBinding instanceof IFunction) { + return false; + } return false; } @@ -151,14 +160,28 @@ public class EvalBinding extends CPPEvaluation { final IFunctionType type = ((IFunction) fBinding).getType(); if (CPPTemplates.isDependentType(type)) return new TypeOfDependentExpression(this); - return SemanticUtil.mapToAST(type, point); + return SemanticUtil.mapToAST(type, point); } return ProblemType.UNKNOWN_FOR_EXPRESSION; } @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + IValue value= null; + if (fBinding instanceof IInternalVariable) { + value= ((IInternalVariable) fBinding).getInitialValue(Value.MAX_RECURSION_DEPTH); + } else if (fBinding instanceof IVariable) { + value= ((IVariable) fBinding).getInitialValue(); + } else if (fBinding instanceof IEnumerator) { + value= ((IEnumerator) fBinding).getValue(); + } + if (value == null) + value = Value.UNKNOWN; + + return value; } @Override @@ -184,4 +207,75 @@ public class EvalBinding extends CPPEvaluation { 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) { + IEnumerator enumerator = (IEnumerator) binding; + IType originalType = enumerator.getType(); + IType type = CPPTemplates.instantiateType(originalType, tpMap, packOffset, within, point); + IValue originalValue = enumerator.getValue(); + IValue value = CPPTemplates.instantiateValue(originalValue, tpMap, packOffset, within, maxdepth, point); + // 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); + if (argument != null) { + IValue value = argument.getNonTypeValue(); + return new EvalFixed(null, ValueCategory.PRVALUE, value); + } + // 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(); + 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); + } + } + if (binding == fBinding) + return this; + return new EvalBinding(binding, getFixedType()); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + if (fBinding instanceof IEnumerator) { + return CPPTemplates.determinePackSize(((IEnumerator) fBinding).getValue(), tpMap); + } + if (fBinding instanceof ICPPTemplateNonTypeParameter) { + return CPPTemplates.determinePackSize((ICPPTemplateNonTypeParameter) fBinding, tpMap); + } + if (fBinding instanceof ICPPUnknownBinding) { + return CPPTemplates.determinePackSize((ICPPUnknownBinding) fBinding, tpMap); + } + + IBinding binding = fBinding; + if (fBinding instanceof ICPPSpecialization) { + binding = ((ICPPSpecialization) fBinding).getSpecializedBinding(); + } + + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + if (binding instanceof ICPPTemplateDefinition) { + ICPPTemplateParameter[] parameters = ((ICPPTemplateDefinition) binding).getTemplateParameters(); + for (ICPPTemplateParameter param : parameters) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(param, tpMap)); + } + } + + return r; + } + + @Override + public boolean referencesTemplateParameter() { + return fBinding instanceof ICPPTemplateParameter; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index 31e0f1f80fc..9328c13ddcf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,7 +19,9 @@ 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; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +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; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -123,12 +126,18 @@ public class EvalComma extends CPPEvaluation { return typeFromFunctionCall(last); } } - return fArguments[fArguments.length-1].getTypeOrFunctionSet(point); + return fArguments[fArguments.length - 1].getTypeOrFunctionSet(point); } @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + ICPPFunction[] overloads = getOverloads(point); + if (overloads.length > 0) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + return fArguments[fArguments.length - 1].getValue(point); } @Override @@ -140,7 +149,7 @@ public class EvalComma extends CPPEvaluation { return valueCategoryFromFunctionCall(last); } } - return fArguments[fArguments.length-1].getValueCategory(point); + return fArguments[fArguments.length - 1].getValueCategory(point); } @Override @@ -160,4 +169,41 @@ public class EvalComma extends CPPEvaluation { } return new EvalComma(args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = fArguments; + for (int i = 0; i < fArguments.length; i++) { + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, 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; + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java index 8cae8cb319a..dcc6c627d06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalCompound.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -16,14 +17,16 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPTemplateParameterMap; 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.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; /** - * Performs evaluation of an expression. + * Performs evaluation of a compound statement expression. Most but not all methods + * delegate to the evaluation of the last expression in the compound one. */ public class EvalCompound extends CPPEvaluation { private final ICPPEvaluation fDelegate; @@ -63,7 +66,7 @@ public class EvalCompound extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + return fDelegate.getValue(point); } @Override @@ -81,4 +84,23 @@ public class EvalCompound extends CPPEvaluation { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalCompound(arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation delegate = fDelegate.instantiate(tpMap, packOffset, within, maxdepth, point); + if (delegate == fDelegate) + return this; + return new EvalCompound(delegate); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return fDelegate.determinePackSize(tpMap); + } + + @Override + public boolean referencesTemplateParameter() { + return fDelegate.referencesTemplateParameter(); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java index d4caae8ea52..7d564ad1ecb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalConditional.java @@ -7,13 +7,17 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ 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.core.dom.ast.IASTExpression.ValueCategory.XVALUE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -23,8 +27,10 @@ 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.ICPPBasicType; +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.ICPPTemplateParameterMap; 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; @@ -49,13 +55,12 @@ public class EvalConditional extends CPPEvaluation { private IType fType; private ICPPFunction fOverload; - - public EvalConditional(ICPPEvaluation arg1, ICPPEvaluation arg2, ICPPEvaluation arg3, + public EvalConditional(ICPPEvaluation condition, ICPPEvaluation positive, ICPPEvaluation negative, boolean positiveThrows, boolean negativeThrows) { // Gnu-extension: Empty positive expression is replaced by condition. - fCondition= arg1; - fPositive= arg2; - fNegative= arg3; + fCondition= condition; + fPositive= positive; + fNegative= negative; fPositiveThrows= positiveThrows; fNegativeThrows= negativeThrows; } @@ -103,7 +108,18 @@ public class EvalConditional extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + IValue condValue = fCondition.getValue(point); + if (condValue == Value.UNKNOWN) + return Value.UNKNOWN; + Long cond = condValue.numericalValue(); + if (cond != null) { + if (cond.longValue() != 0) { + return fPositive == null ? condValue : fPositive.getValue(point); + } else { + return fNegative.getValue(point); + } + } + return Value.create(this); } @Override @@ -252,7 +268,7 @@ public class EvalConditional extends CPPEvaluation { } // Both are class types and one derives from the other if (uqt1 instanceof ICPPClassType && uqt2 instanceof ICPPClassType) { - int dist= SemanticUtil.calculateInheritanceDepth(uqt1, uqt2); + int dist= SemanticUtil.calculateInheritanceDepth(uqt1, uqt2, point); if (dist >= 0) { CVQualifier cv1 = SemanticUtil.getCVQualifier(t1); CVQualifier cv2 = SemanticUtil.getCVQualifier(t2); @@ -263,7 +279,7 @@ public class EvalConditional extends CPPEvaluation { } return Cost.NO_CONVERSION; } - if (SemanticUtil.calculateInheritanceDepth(uqt2, uqt1) >= 0) + if (SemanticUtil.calculateInheritanceDepth(uqt2, uqt1, point) >= 0) return Cost.NO_CONVERSION; } // Unrelated class types or just one class: @@ -307,4 +323,32 @@ public class EvalConditional extends CPPEvaluation { ICPPEvaluation neg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalConditional(cond, pos, neg, pth, nth); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation condition = fCondition.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation positive = fPositive == null ? + null : fPositive.instantiate(tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation negative = fNegative.instantiate(tpMap, packOffset, within, 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); + r = CPPTemplates.combinePackSize(r, fNegative.determinePackSize(tpMap)); + if (fPositive != null) + r = CPPTemplates.combinePackSize(r, fPositive.determinePackSize(tpMap)); + return r; + } + + @Override + public boolean referencesTemplateParameter() { + return fCondition.referencesTemplateParameter() || + (fPositive != null && fPositive.referencesTemplateParameter()) || + fNegative.referencesTemplateParameter(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java index c6985aed4c7..22d07d9238a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFixed.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -18,10 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPTemplateParameterMap; 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.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; @@ -41,6 +45,14 @@ public class EvalFixed extends CPPEvaluation { private boolean fCheckedIsValueDependent; public EvalFixed(IType type, ValueCategory cat, IValue value) { + if (type instanceof CPPBasicType) { + Long num = value.numericalValue(); + if (num != null) { + CPPBasicType t = (CPPBasicType) type.clone(); + t.setAssociatedNumericalValue(num); + type = t; + } + } fType= type; fValueCategory= cat; fValue= value; @@ -145,4 +157,24 @@ public class EvalFixed extends CPPEvaluation { value= readValue ? buffer.unmarshalValue() : Value.UNKNOWN; return new EvalFixed(type, cat, value); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type = CPPTemplates.instantiateType(fType, tpMap, packOffset, within, point); + IValue value = CPPTemplates.instantiateValue(fValue, tpMap, packOffset, within, maxdepth, point); + if (type == fType && value == fValue) + return this; + return new EvalFixed(type, fValueCategory, value); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fValue, tpMap); + } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index 38c741f9e38..6bf4ddc8f91 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -17,6 +18,8 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +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.IFunctionType; @@ -24,8 +27,10 @@ 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.ICPPTemplateParameterMap; 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; @@ -45,6 +50,10 @@ public class EvalFunctionCall extends CPPEvaluation { fArguments= args; } + /** + * Returns arguments of the function call. The first argument is the function name, the rest + * are arguments passed to the function. + */ public ICPPEvaluation[] getArguments() { return fArguments; } @@ -132,7 +141,8 @@ public class EvalFunctionCall extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + // TODO(sprigogin): Simulate execution of a function call if the value is not dependent. + return Value.create(this); } @Override @@ -167,6 +177,48 @@ public class EvalFunctionCall extends CPPEvaluation { for (int i = 0; i < args.length; i++) { args[i]= (ICPPEvaluation) buffer.unmarshalEvaluation(); } - return new EvalComma(args); + return new EvalFunctionCall(args); + } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = fArguments; + for (int i = 0; i < fArguments.length; i++) { + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, 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; + + if (args[0] instanceof EvalFunctionSet && getOverload(point) == null) { + // Resolve the function using the parameters of the function call. + args[0] = ((EvalFunctionSet) args[0]).resolveFunction(Arrays.copyOfRange(args, 1, args.length), point); + } + return new EvalFunctionCall(args); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java index c2a98168cc7..881db03f857 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionSet.java @@ -7,20 +7,29 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import java.util.Arrays; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.DOMException; 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.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.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +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; import org.eclipse.cdt.internal.core.dom.parser.Value; +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; @@ -106,7 +115,10 @@ public class EvalFunctionSet extends CPPEvaluation { buffer.marshalBinding(binding); } if (args != null) { - // mstodo marshall arguments + buffer.putShort((short) args.length); + for (ICPPTemplateArgument arg : args) { + buffer.marshalTemplateArgument(arg); + } } } @@ -119,8 +131,80 @@ public class EvalFunctionSet extends CPPEvaluation { } ICPPTemplateArgument[] args= null; if ((firstByte & ITypeMarshalBuffer.FLAG2) != 0) { - // mstodo marshall arguments + int len= buffer.getShort(); + args = new ICPPTemplateArgument[len]; + for (int i = 0; i < args.length; i++) { + args[i]= buffer.unmarshalTemplateArgument(); + } } return new EvalFunctionSet(new CPPFunctionSet(bindings, args, null), addressOf); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPTemplateArgument[] originalArguments = fFunctionSet.getTemplateArguments(); + ICPPTemplateArgument[] arguments = originalArguments; + arguments = instantiateArguments(originalArguments, tpMap, packOffset, within, point); + + IBinding originalOwner = fFunctionSet.getOwner(); + IBinding owner = originalOwner; + if (originalOwner instanceof ICPPUnknownBinding) { + owner = resolveUnknown((ICPPUnknownBinding) owner, tpMap, packOffset, within, point); + } else if (owner instanceof IType) { + IType type = CPPTemplates.instantiateType((IType) owner, tpMap, packOffset, within, point); + if (type instanceof IBinding) + owner = (IBinding) type; + } + ICPPFunction[] originalFunctions = fFunctionSet.getBindings(); + ICPPFunction[] functions = originalFunctions; + if (owner instanceof ICPPClassSpecialization && owner != originalOwner) { + functions = new ICPPFunction[originalFunctions.length]; + for (int i = 0; i < originalFunctions.length; i++) { + functions[i] = (ICPPFunction) CPPTemplates.createSpecialization((ICPPClassSpecialization) owner, + originalFunctions[i], point); + } + } + if (Arrays.equals(arguments, originalArguments) && functions == originalFunctions) + return this; + return new EvalFunctionSet(new CPPFunctionSet(functions, arguments, null), fAddressOf); + } + + /** + * Attempts to resolve the function using the parameters of a function call. + * + * @param args the arguments of a function call + * @param point the name lookup context + * @return the resolved or the original evaluation depending on whether function resolution + * succeeded or not + */ + public ICPPEvaluation resolveFunction(ICPPEvaluation[] args, IASTNode point) { + ICPPFunction[] functions = fFunctionSet.getBindings(); + LookupData data = new LookupData(functions[0].getNameCharArray(), + fFunctionSet.getTemplateArguments(), point); + data.setFunctionArguments(false, args); + try { + IBinding binding = CPPSemantics.resolveFunction(data, functions, true); + if (binding instanceof ICPPFunction && !(binding instanceof ICPPUnknownBinding)) + return new EvalBinding(binding, null); + } catch (DOMException e) { + CCorePlugin.log(e); + } + return this; + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.PACK_SIZE_NOT_FOUND; + ICPPTemplateArgument[] templateArguments = fFunctionSet.getTemplateArguments(); + for (ICPPTemplateArgument arg : templateArguments) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 366e8f6e7a2..ae55002ba98 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -7,12 +7,14 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; @@ -30,12 +32,17 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; +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; import org.eclipse.cdt.internal.core.dom.parser.Value; @@ -51,7 +58,8 @@ public class EvalID extends CPPEvaluation { private final boolean fQualified; private final ICPPTemplateArgument[] fTemplateArgs; - public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, boolean qualified, ICPPTemplateArgument[] templateArgs) { + public EvalID(ICPPEvaluation fieldOwner, IBinding nameOwner, char[] simpleID, boolean addressOf, + boolean qualified, ICPPTemplateArgument[] templateArgs) { fFieldOwner= fieldOwner; fName= simpleID; fNameOwner= nameOwner; @@ -60,6 +68,9 @@ public class EvalID extends CPPEvaluation { fTemplateArgs= templateArgs; } + /** + * Returns the field owner expression, or {@code null}. + */ public ICPPEvaluation getFieldOwner() { return fFieldOwner; } @@ -80,6 +91,9 @@ public class EvalID extends CPPEvaluation { return fQualified; } + /** + * Returns the template arguments, or {@code null} if there are no template arguments. + */ public ICPPTemplateArgument[] getTemplateArgs() { return fTemplateArgs; } @@ -111,7 +125,17 @@ public class EvalID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + // Name lookup is not needed here because it was already done in the "instantiate" method. +// IBinding nameOwner = fNameOwner; +// if (nameOwner == null && fFieldOwner != null) +// nameOwner = (IBinding) fFieldOwner.getTypeOrFunctionSet(point); +// +// if (nameOwner instanceof ICPPClassType) { +// ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, fTemplateArgs, point); +// if (eval != null) +// return eval.getValue(point); +// } + return Value.create(this); } @Override @@ -134,7 +158,10 @@ public class EvalID extends CPPEvaluation { buffer.putCharArray(fName); buffer.marshalBinding(fNameOwner); if (fTemplateArgs != null) { - // mstodo marshall arguments + buffer.putShort((short) fTemplateArgs.length); + for (ICPPTemplateArgument arg : fTemplateArgs) { + buffer.marshalTemplateArgument(arg); + } } } @@ -146,7 +173,11 @@ public class EvalID extends CPPEvaluation { IBinding nameOwner= buffer.unmarshalBinding(); ICPPTemplateArgument[] args= null; if ((firstByte & ITypeMarshalBuffer.FLAG3) != 0) { - // mstodo marshall arguments + int len= buffer.getShort(); + args = new ICPPTemplateArgument[len]; + for (int i = 0; i < args.length; i++) { + args[i]= buffer.unmarshalTemplateArgument(); + } } return new EvalID(fieldOwner, nameOwner, name, addressOf, qualified, args); } @@ -242,4 +273,79 @@ public class EvalID extends CPPEvaluation { } return false; } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPTemplateArgument[] templateArgs = fTemplateArgs; + if (templateArgs != null) { + templateArgs = instantiateArguments(templateArgs, tpMap, packOffset, within, point); + } + + ICPPEvaluation fieldOwner = fFieldOwner; + if (fieldOwner != null) { + fieldOwner = fieldOwner.instantiate(tpMap, packOffset, within, maxdepth, point); + } + + IBinding nameOwner = fNameOwner; + if (nameOwner instanceof ICPPClassTemplate) { + nameOwner = resolveUnknown(CPPTemplates.createDeferredInstance((ICPPClassTemplate) nameOwner), + tpMap, packOffset, within, point); + } else if (nameOwner instanceof IType) { + IType type = CPPTemplates.instantiateType((IType) nameOwner, tpMap, packOffset, within, point); + if (type instanceof IBinding) + nameOwner = (IBinding) type; + } + + if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding) + return this; + + if (templateArgs == fTemplateArgs && fieldOwner == fFieldOwner && nameOwner == fNameOwner) + return this; + + ICPPEvaluation eval = resolveName((ICPPClassType) nameOwner, templateArgs, point); + if (eval != null) + return eval; + + return new EvalID(fieldOwner, nameOwner, fName, fAddressOf, fQualified, templateArgs); + } + + private ICPPEvaluation resolveName(ICPPClassType nameOwner, ICPPTemplateArgument[] templateArgs, + IASTNode point) { + LookupData data = new LookupData(fName, templateArgs, point); + data.qualified = fQualified; + try { + CPPSemantics.lookup(data, nameOwner.getCompositeScope()); + } catch (DOMException e) { + } + IBinding[] bindings = data.getFoundBindings(); + if (bindings.length > 1 && bindings[0] instanceof ICPPFunction) { + ICPPFunction[] functions = new ICPPFunction[bindings.length]; + System.arraycopy(bindings, 0, functions, 0, bindings.length); + return new EvalFunctionSet(new CPPFunctionSet(functions, templateArgs, null), fAddressOf); + } + IBinding binding = bindings.length == 1 ? bindings[0] : null; + if (binding instanceof IEnumerator) { + return new EvalBinding(binding, null); + } else if (binding instanceof ICPPMember) { + return new EvalMemberAccess(nameOwner, ValueCategory.PRVALUE, binding, false); + } else if (binding instanceof CPPFunctionSet) { + return new EvalFunctionSet((CPPFunctionSet) binding, fAddressOf); + } + return null; + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = fFieldOwner.determinePackSize(tpMap); + for (ICPPTemplateArgument arg : fTemplateArgs) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + return fFieldOwner.referencesTemplateParameter(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java index d54b0fb9bca..02eb709506e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalInitList.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -16,6 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPTemplateParameterMap; 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.Value; @@ -71,7 +74,9 @@ public class EvalInitList extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + return Value.UNKNOWN; // TODO(sprigogin): Is this correct? } @Override @@ -94,6 +99,43 @@ public class EvalInitList extends CPPEvaluation { for (int i = 0; i < args.length; i++) { args[i]= (ICPPEvaluation) buffer.unmarshalEvaluation(); } - return new EvalComma(args); + return new EvalInitList(args); + } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] clauses = fClauses; + for (int i = 0; i < fClauses.length; i++) { + ICPPEvaluation clause = fClauses[i].instantiate(tpMap, packOffset, within, 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; + for (ICPPEvaluation arg : fClauses) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation clause : fClauses) { + if (clause.referencesTemplateParameter()) + return true; + } + return false; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java index 84c8d69ea80..7e164f70ecd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalMemberAccess.java @@ -7,14 +7,21 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.XVALUE; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; import java.util.Collection; @@ -29,10 +36,12 @@ 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; +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.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +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; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; @@ -245,7 +254,16 @@ public class EvalMemberAccess extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (fMember instanceof IEnumerator) { + return ((IEnumerator) fMember).getValue(); + } + if (fMember instanceof IVariable) { + return ((IVariable) fMember).getInitialValue(); + } + if (fMember instanceof IFunction) { + return Value.UNKNOWN; + } + return Value.create(this); } @Override @@ -301,4 +319,28 @@ public class EvalMemberAccess extends CPPEvaluation { IBinding member= buffer.unmarshalBinding(); return new EvalMemberAccess(ownerType, ownerValueCat, member, isDeref); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType ownerType = CPPTemplates.instantiateType(fOwnerType, tpMap, packOffset, within, point); + if (ownerType == fOwnerType) + return this; + + IBinding member = fMember; + if (ownerType instanceof ICPPClassSpecialization) { + member = CPPTemplates.createSpecialization((ICPPClassSpecialization) ownerType, fMember, point); + } + return new EvalMemberAccess(ownerType, fOwnerValueCategory, member, fIsPointerDeref); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fOwnerType, tpMap); + } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index e2e41b728b1..41a0fce27aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -17,6 +18,9 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.ICPPTemplateParameterMap; 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.Value; @@ -70,7 +74,20 @@ public class EvalTypeId extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + if (fArguments == null) + return Value.UNKNOWN; + + if (isTypeDependent()) + return Value.create(this); + if (fOutputType instanceof ICPPClassType) { + // TODO(sprigogin): Simulate execution of a ctor call. + return Value.UNKNOWN; + } + if (fArguments.length == 1) + return fArguments[0].getValue(point); + return Value.UNKNOWN; } @Override @@ -125,4 +142,44 @@ public class EvalTypeId extends CPPEvaluation { } return new EvalTypeId(type, args); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation[] args = fArguments; + if (fArguments != null) { + for (int i = 0; i < fArguments.length; i++) { + ICPPEvaluation arg = fArguments[i].instantiate(tpMap, packOffset, within, 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; + } + } + } + IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); + if (args == fArguments && type == fInputType) + return this; + return new EvalTypeId(type, args); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + int r = CPPTemplates.determinePackSize(fInputType, tpMap); + for (ICPPEvaluation arg : fArguments) { + r = CPPTemplates.combinePackSize(r, arg.determinePackSize(tpMap)); + } + return r; + } + + @Override + public boolean referencesTemplateParameter() { + for (ICPPEvaluation arg : fArguments) { + if (arg.referencesTemplateParameter()) + return true; + } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java index ca5bef22dfc..7a74dc34041 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnary.java @@ -7,28 +7,49 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.*; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_alignOf; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_amper; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_minus; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_noexcept; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_not; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_plus; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_postFixDecr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_postFixIncr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_prefixDecr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_prefixIncr; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_sizeof; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_sizeofParameterPack; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_star; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_throw; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_tilde; +import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_typeid; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueTypeWithResolvedTypedefs; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; 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.ICPPFunction; +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; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; @@ -90,12 +111,14 @@ public class EvalUnary extends CPPEvaluation { @Override public boolean isValueDependent() { - switch(fOperator) { + switch (fOperator) { case op_alignOf: case op_sizeof: case op_sizeofParameterPack: case op_typeid: return fArgument.isTypeDependent(); + case op_noexcept: + return fArgument.referencesTemplateParameter(); case op_throw: return false; default: @@ -124,7 +147,7 @@ public class EvalUnary extends CPPEvaluation { return null; ICPPEvaluation[] args; - if (fOperator == IASTUnaryExpression.op_postFixDecr || fOperator == IASTUnaryExpression.op_postFixIncr) { + if (fOperator == op_postFixDecr || fOperator == op_postFixIncr) { args = new ICPPEvaluation[] { fArgument, ZERO_EVAL }; } else { args = new ICPPEvaluation[] { fArgument }; @@ -167,6 +190,7 @@ public class EvalUnary extends CPPEvaluation { return type; } return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION); + case op_noexcept: case op_not: return CPPBasicType.BOOLEAN; case op_postFixDecr: @@ -185,7 +209,39 @@ public class EvalUnary extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + if (getOverload(point) != null) { + // TODO(sprigogin): Simulate execution of a function call. + return Value.create(this); + } + + switch (fOperator) { + case op_sizeof: { + SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignOf: { + SizeAndAlignment info = getSizeAndAlignment(fArgument.getTypeOrFunctionSet(point), point); + return info == null ? Value.UNKNOWN : Value.create(info.alignment); + } + case op_noexcept: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_sizeofParameterPack: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_typeid: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_throw: + return Value.UNKNOWN; // TODO(sprigogin): Implement + } + + IValue val = fArgument.getValue(point); + Long num = val.numericalValue(); + if (num != null) { + return Value.evaluateUnaryExpression(fOperator, num); + } + return Value.create(this); } @Override @@ -217,4 +273,23 @@ public class EvalUnary extends CPPEvaluation { ICPPEvaluation arg= (ICPPEvaluation) buffer.unmarshalEvaluation(); return new EvalUnary(op, arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + ICPPEvaluation argument = fArgument.instantiate(tpMap, packOffset, within, maxdepth, point); + if (argument == fArgument) + return this; + return new EvalUnary(fOperator, argument); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return fArgument.determinePackSize(tpMap); + } + + @Override + public boolean referencesTemplateParameter() { + return fArgument.referencesTemplateParameter(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java index 9caf7ec00f4..241fb626f72 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java @@ -7,22 +7,49 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; -import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.*; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_alignof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_nothrow_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_assign; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_constructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_copy; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_virtual_destructor; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_abstract; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_class; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_empty; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_enum; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_literal_type; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_pod; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_polymorphic; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_standard_layout; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_trivial; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_union; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_sizeof; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeid; +import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_typeof; import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumeration; 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.ICPPTemplateParameterMap; 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.SizeofCalculator.SizeAndAlignment; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.core.runtime.CoreException; public class EvalUnaryTypeID extends CPPEvaluation { @@ -76,8 +103,11 @@ public class EvalUnaryTypeID extends CPPEvaluation { case op_is_class: case op_is_empty: case op_is_enum: + case op_is_literal_type: case op_is_pod: case op_is_polymorphic: + case op_is_standard_layout: + case op_is_trivial: case op_is_union: return CPPTemplates.isDependentType(fOrigType); @@ -113,8 +143,11 @@ public class EvalUnaryTypeID extends CPPEvaluation { case op_is_class: case op_is_empty: case op_is_enum: + case op_is_literal_type: case op_is_pod: case op_is_polymorphic: + case op_is_standard_layout: + case op_is_trivial: case op_is_union: return CPPBasicType.BOOLEAN; case op_typeof: @@ -127,7 +160,58 @@ public class EvalUnaryTypeID extends CPPEvaluation { @Override public IValue getValue(IASTNode point) { - return Value.create(this, point); + if (isValueDependent()) + return Value.create(this); + + switch (fOperator) { + case op_sizeof: { + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); + return info == null ? Value.UNKNOWN : Value.create(info.size); + } + case op_alignof: { + SizeAndAlignment info = getSizeAndAlignment(fOrigType, point); + return info == null ? Value.UNKNOWN : Value.create(info.alignment); + } + case op_typeid: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_nothrow_copy: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_nothrow_constructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_assign: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_constructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_copy: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_trivial_destructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_has_virtual_destructor: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_abstract: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_class: + return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() != ICompositeType.k_union); + case op_is_empty: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_enum: + return Value.create(fOrigType instanceof IEnumeration); + case op_is_literal_type: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_pod: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_polymorphic: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_standard_layout: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_trivial: + return Value.UNKNOWN; // TODO(sprigogin): Implement + case op_is_union: + return Value.create(fOrigType instanceof ICompositeType && ((ICompositeType) fOrigType).getKey() == ICompositeType.k_union); + case op_typeof: + return Value.UNKNOWN; // TODO(sprigogin): Implement + } + return Value.create(this); } @Override @@ -139,7 +223,7 @@ public class EvalUnaryTypeID extends CPPEvaluation { public void marshal(ITypeMarshalBuffer buffer, boolean includeValue) throws CoreException { buffer.putByte(ITypeMarshalBuffer.EVAL_UNARY_TYPE_ID); buffer.putByte((byte) fOperator); - buffer.marshalType(fType); + buffer.marshalType(fOrigType); } public static ISerializableEvaluation unmarshal(int firstByte, ITypeMarshalBuffer buffer) throws CoreException { @@ -147,4 +231,23 @@ public class EvalUnaryTypeID extends CPPEvaluation { IType arg= buffer.unmarshalType(); return new EvalUnaryTypeID(op, arg); } + + @Override + public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, + ICPPClassSpecialization within, int maxdepth, IASTNode point) { + IType type = CPPTemplates.instantiateType(fOrigType, tpMap, packOffset, within, point); + if (type == fOrigType) + return this; + return new EvalUnaryTypeID(fOperator, type); + } + + @Override + public int determinePackSize(ICPPTemplateParameterMap tpMap) { + return CPPTemplates.determinePackSize(fOrigType, tpMap); + } + + @Override + public boolean referencesTemplateParameter() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java index ef6dd69e55a..81ba5a75dd5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FunctionCost.java @@ -40,18 +40,21 @@ class FunctionCost { private final ICPPFunction fFunction; private final Cost[] fCosts; private final ValueCategory[] fValueCategories; + private final IASTNode fPoint; private boolean fIsDirectCopyCtor; - public FunctionCost(ICPPFunction fn, int paramCount) { + public FunctionCost(ICPPFunction fn, int paramCount, IASTNode point) { fFunction= fn; fCosts= new Cost[paramCount]; fValueCategories= new ValueCategory[paramCount]; + fPoint = point; } - public FunctionCost(ICPPFunction fn, Cost cost) { + public FunctionCost(ICPPFunction fn, Cost cost, IASTNode point) { fFunction= fn; fCosts= new Cost[] {cost}; fValueCategories= null; // no udc will be performed + fPoint = point; } public int getLength() { @@ -127,9 +130,8 @@ class FunctionCost { /** * Compares this function call cost to another one. - * @param point */ - public int compareTo(IASTTranslationUnit tu, FunctionCost other, IASTNode point) throws DOMException { + public int compareTo(IASTTranslationUnit tu, FunctionCost other) throws DOMException { if (other == null) return -1; @@ -169,7 +171,7 @@ class FunctionCost { haveBetter = true; } else if (isTemplate && otherIsTemplate) { TypeSelection ts= SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS; - int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, point); + int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, fPoint); if (order < 0) { haveBetter= true; } else if (order > 0) { @@ -215,10 +217,10 @@ class FunctionCost { if (!parameterTypesMatch(ft1, ft2)) return 0; - int diff= SemanticUtil.calculateInheritanceDepth(o2, o1); + int diff= SemanticUtil.calculateInheritanceDepth(o2, o1, fPoint); if (diff >= 0) return diff; - return -SemanticUtil.calculateInheritanceDepth(o1, o2); + return -SemanticUtil.calculateInheritanceDepth(o1, o2, fPoint); } private boolean parameterTypesMatch(final ICPPFunctionType ft1, final ICPPFunctionType ft2) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index cd03ac12cc5..3d9dadf4b01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 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 @@ -62,7 +62,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; 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.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +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.OverloadableOperator; @@ -100,12 +101,12 @@ public class SemanticUtil { * @param clazz * @return an array of conversion operators. */ - public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz) throws DOMException { + public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz, IASTNode point) throws DOMException { ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; if (clazz instanceof ICPPDeferredClassInstance) { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getTemplateDefinition(); } - ICPPMethod[] decs= clazz.getDeclaredMethods(); + ICPPMethod[] decs= ClassTypeHelper.getDeclaredMethods(clazz, point); if (decs != null) { for (ICPPMethod method : decs) { if (isConversionOperator(method)) { @@ -123,11 +124,11 @@ public class SemanticUtil { * @param clazz * @return an array of conversion operators. */ - public static ICPPMethod[] getConversionOperators(ICPPClassType clazz) throws DOMException { + public static ICPPMethod[] getConversionOperators(ICPPClassType clazz, IASTNode point) throws DOMException { ICPPMethod[] methods= ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - ObjectSet ancestry= inheritanceClosure(clazz); + ObjectSet ancestry= inheritanceClosure(clazz, point); for (int i = 0; i < ancestry.size(); i++) { - methods= ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i))); + methods= ArrayUtil.addAll(methods, getDeclaredConversionOperators(ancestry.keyAt(i), point)); } return methods; } @@ -137,7 +138,7 @@ public class SemanticUtil { * @return the root and all its ancestor classes * @throws DOMException */ - public static ObjectSet inheritanceClosure(ICPPClassType root) throws DOMException { + public static ObjectSet inheritanceClosure(ICPPClassType root, IASTNode point) throws DOMException { ObjectSet done= new ObjectSet(2); ObjectSet current= new ObjectSet(2); current.put(root); @@ -148,8 +149,8 @@ public class SemanticUtil { for (int i = 0; i < current.size(); i++) { ICPPClassType clazz= current.keyAt(i); done.put(clazz); - - for (ICPPBase base : clazz.getBases()) { + + for (ICPPBase base : ClassTypeHelper.getBases(clazz, point)) { IBinding binding= base.getBaseClass(); if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { ICPPClassType ct= (ICPPClassType) binding; @@ -165,7 +166,7 @@ public class SemanticUtil { return done; } - + /** * @param method * @return true if the specified method is a conversion operator @@ -511,7 +512,7 @@ public class SemanticUtil { final IType type= arg.getTypeValue(); final IType newType= getSimplifiedType(type); if (newType != type) { - return new CPPTemplateArgument(newType); + return new CPPTemplateTypeArgument(newType); } } return arg; @@ -622,11 +623,11 @@ public class SemanticUtil { * @return the number of edges in the inheritance graph, or -1 if the specified classes have * no inheritance relation */ - public static final int calculateInheritanceDepth(IType type, IType baseClass) { - return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), type, baseClass); + public static final int calculateInheritanceDepth(IType type, IType baseClass, IASTNode point) { + return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), type, baseClass, point); } - private static final int calculateInheritanceDepth(int maxdepth, Set hashSet, IType type, IType baseClass) { + private static final int calculateInheritanceDepth(int maxdepth, Set hashSet, IType type, IType baseClass, IASTNode point) { if (type == baseClass || type.isSameType(baseClass)) { return 0; } @@ -637,7 +638,7 @@ public class SemanticUtil { clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding(); } - for (ICPPBase cppBase : clazz.getBases()) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(clazz, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof IType && hashSet.add(base)) { IType tbase= (IType) base; @@ -648,7 +649,7 @@ public class SemanticUtil { } if (tbase instanceof ICPPClassType) { - int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass); + int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass, point); if (n > 0) return n + 1; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index cdc2cdfa66a..14d895b84ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -60,8 +61,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; 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.CPPReferenceType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; +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; @@ -70,9 +73,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; */ public class TemplateArgumentDeduction { /** - * Deduce arguments for a template function from the template id + the template function parameters. + * Deduce arguments for a template function from the template id and the template function + * parameters. * 14.8.2.1 - * @param point */ static ICPPTemplateArgument[] deduceForFunctionCall(ICPPFunctionTemplate template, ICPPTemplateArgument[] tmplArgs, List fnArgs, List argIsLValue, @@ -235,7 +238,7 @@ public class TemplateArgumentDeduction { ICPPTemplateInstance pInst = (ICPPTemplateInstance) pcheck; ICPPClassTemplate pTemplate= getPrimaryTemplate(pInst); if (pTemplate != null) { - ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate); + ICPPClassType aInst= findBaseInstance((ICPPClassType) argcheck, pTemplate, point); if (aInst != null && aInst != argcheck) { par= pcheck; arg= aInst; @@ -290,7 +293,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a user defined conversion template * 14.8.2.3 - * @param point */ static ICPPTemplateArgument[] deduceForConversion(ICPPFunctionTemplate template, IType conversionType, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -325,7 +327,6 @@ public class TemplateArgumentDeduction { /** * Deduce arguments for a function declaration * 14.8.2.6 - * @param point */ static ICPPTemplateArgument[] deduceForDeclaration(ICPPFunctionTemplate template, ICPPTemplateArgument[] args, ICPPFunctionType ftype, CPPTemplateParameterMap map, IASTNode point) throws DOMException { @@ -360,7 +361,6 @@ public class TemplateArgumentDeduction { /** * Deduces the mapping for the template parameters from the function parameters, * returns false if there is no mapping. - * @param point */ static int deduceForPartialOrdering(ICPPTemplateParameter[] tmplPars, IType[] fnPars, IType[] fnArgs, IASTNode point) { try { @@ -423,7 +423,6 @@ public class TemplateArgumentDeduction { /** * Adds the explicit arguments to the map. - * @param point */ private static boolean addExplicitArguments(final ICPPTemplateParameter[] tmplParams, ICPPTemplateArgument[] tmplArgs, CPPTemplateParameterMap map, IASTNode point) { @@ -481,13 +480,14 @@ public class TemplateArgumentDeduction { } /** - * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of the deduced A. + * 14.8.2.1.3 If P is a class and has the form template-id, then A can be a derived class of + * the deduced A. */ - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate) throws DOMException { - return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet()); + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, IASTNode point) throws DOMException { + return findBaseInstance(a, pTemplate, CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet(), point); } - private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled) throws DOMException { + private static ICPPClassType findBaseInstance(ICPPClassType a, ICPPClassTemplate pTemplate, int maxdepth, HashSet handled, IASTNode point) throws DOMException { if (a instanceof ICPPTemplateInstance) { final ICPPTemplateInstance inst = (ICPPTemplateInstance) a; ICPPClassTemplate tmpl= getPrimaryTemplate(inst); @@ -495,10 +495,10 @@ public class TemplateArgumentDeduction { return a; } if (maxdepth-- > 0) { - for (ICPPBase cppBase : a.getBases()) { + for (ICPPBase cppBase : ClassTypeHelper.getBases(a, point)) { IBinding base= cppBase.getBaseClass(); if (base instanceof ICPPClassType && handled.add(base)) { - final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled); + final ICPPClassType inst= findBaseInstance((ICPPClassType) base, pTemplate, maxdepth, handled, point); if (inst != null) return inst; } @@ -546,7 +546,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from pairs of template arguments. - * @param point */ public static boolean fromTemplateArguments(final ICPPTemplateParameter[] pars, final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, @@ -639,7 +638,6 @@ public class TemplateArgumentDeduction { /** * Deduces the template parameter mapping from one pair of template arguments. - * @param point */ private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgument a, IASTNode point) throws DOMException { if (p.isNonTypeValue() != a.isNonTypeValue()) @@ -723,7 +721,7 @@ public class TemplateArgumentDeduction { if (parID >= 0) { ICPPTemplateArgument old= fDeducedArgs.getArgument(parID, fPackOffset); if (old == null) { - if (!deduce(parID, new CPPTemplateArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) { + if (!deduce(parID, new CPPTemplateNonTypeArgument(as, new CPPBasicType(ICPPBasicType.Kind.eInt, 0)))) { return false; } } else if (!as.equals(old.getNonTypeValue())) { @@ -764,7 +762,7 @@ public class TemplateArgumentDeduction { } if (a == null) return false; - return deduce(((ICPPTemplateParameter)p).getParameterID(), new CPPTemplateArgument(a)); + return deduce(((ICPPTemplateParameter)p).getParameterID(), new CPPTemplateTypeArgument(a)); } else if (p instanceof ICPPTemplateInstance) { if (!(a instanceof ICPPTemplateInstance)) return false; @@ -792,7 +790,7 @@ public class TemplateArgumentDeduction { if (current != null) { if (current.isNonTypeValue() || !current.getTypeValue().isSameType(aTemplate)) return false; - } else if (!deduce(tparId, new CPPTemplateArgument(aTemplate))) { + } else if (!deduce(tparId, new CPPTemplateTypeArgument(aTemplate))) { return false; } } else if (!aTemplate.isSameType(pTemplate)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index bf7a28e139c..37ed8922ed2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPointer; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; @@ -142,7 +143,7 @@ public class DeclaratorWriter extends NodeWriter { if (funcDec.isPureVirtual()) { scribe.print(PURE_VIRTUAL); } - writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification()); + writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification(), funcDec.getNoexceptExpression()); if (funcDec.getTrailingReturnType() != null) { scribe.printSpace(); scribe.print(ARROW_OPERATOR); @@ -151,7 +152,8 @@ public class DeclaratorWriter extends NodeWriter { } } - protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) { + protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions, + ICPPASTExpression noexceptExpression) { if (exceptions != ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION) { scribe.printSpace(); scribe.printStringSpace(Keywords.THROW); @@ -159,6 +161,16 @@ public class DeclaratorWriter extends NodeWriter { writeNodeList(exceptions); scribe.print(')'); } + if (noexceptExpression != null) { + scribe.printSpace(); + scribe.print(Keywords.NOEXCEPT); + if (noexceptExpression != ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT) { + scribe.printSpace(); + scribe.print('('); + noexceptExpression.accept(visitor); + scribe.print(')'); + } + } } protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paramDecls) { @@ -266,7 +278,7 @@ public class DeclaratorWriter extends NodeWriter { protected void writeKnRParameterDeclarations(ICASTKnRFunctionDeclarator knrFunct, IASTDeclaration[] knrDeclarations) { - for (int i = 0; i < knrDeclarations.length; ++i) { + for (int i = 0; i < knrDeclarations.length; ++i) { scribe.noNewLines(); knrDeclarations[i].accept(visitor); scribe.newLines(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java index b5d416a7721..88d8869e8f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; @@ -22,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor; @@ -62,19 +64,21 @@ public class ModifiedASTDeclaratorWriter extends DeclaratorWriter { @Override protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, - IASTTypeId[] exceptions) { + IASTTypeId[] exceptions, ICPPASTExpression noexceptExpression) { IASTTypeId[] modifiedExceptions = modificationHelper.createModifiedChildArray(funcDec, exceptions, IASTTypeId.class, commentMap); - // it makes a difference whether the exception array is identical to - // ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION + // It makes a difference whether the exception array is identical to + // ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION or not. if (modifiedExceptions.length == 0 && exceptions == ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION) { modifiedExceptions= ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION; } - - super.writeExceptionSpecification(funcDec, modifiedExceptions); + + noexceptExpression = modificationHelper.getNodeAfterReplacement(noexceptExpression); + + super.writeExceptionSpecification(funcDec, modifiedExceptions, noexceptExpression); } - + @Override protected void writeKnRParameterDeclarations(ICASTKnRFunctionDeclarator knrFunct, IASTDeclaration[] knrDeclarations) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java index c037e381213..348ccf74905 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexType.java @@ -6,9 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.index; import org.eclipse.cdt.core.dom.ast.IType; @@ -18,5 +17,4 @@ import org.eclipse.cdt.core.dom.ast.IType; * @since 4.0 */ public interface IIndexType extends IType { - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index 482571a9c84..1108417de68 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -233,7 +233,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { throw new CompositingNotImplementedError(); } - private ICPPEvaluation getCompositeEvaluation(ICPPEvaluation eval) { + public ICPPEvaluation getCompositeEvaluation(ICPPEvaluation eval) { if (eval == null) return null; if (eval instanceof EvalBinary) { @@ -425,16 +425,13 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { public IValue getCompositeValue(IValue v) { if (v == null) return null; - - IBinding[] b= v.getUnknownBindings(); - if (b.length == 0) + + ICPPEvaluation eval = v.getEvaluation(); + if (eval == null) return v; - - ICPPUnknownBinding[] b2= new ICPPUnknownBinding[b.length]; - for (int i = 0; i < b2.length; i++) { - b2[i]= (ICPPUnknownBinding) getCompositeBinding((IIndexFragmentBinding) b[i]); - } - return Value.fromInternalRepresentation(v.getInternalExpression(), b2); + + eval = getCompositeEvaluation(eval); + return Value.fromInternalRepresentation(eval); } private ICPPNamespace[] getNamespaces(IBinding rbinding) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java index ab9e34545f0..9de1673b314 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -43,8 +43,8 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope { public ICPPMethod[] getImplicitMethods() { ICPPClassScope rscope = (ICPPClassScope) ((ICPPClassType)rbinding).getCompositeScope(); ICPPMethod[] result = rscope.getImplicitMethods(); - for(int i=0; i> fInProgress= new ThreadLocal>(); - public CompositeCPPClassSpecialization(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); } @@ -80,11 +82,11 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple specializationMap= (ObjectMap) cached; } else { final ObjectMap newMap= new ObjectMap(2); - // in any fragment explicit specializations may be defined. + // In any fragment explicit specializations may be defined. IIndexFragmentBinding[] frags= cf.findEquivalentBindings(rbinding); for (IIndexFragmentBinding fb : frags) { if (fb instanceof ICPPClassType) { - final ICPPClassType[] nested = ((ICPPClassType)fb).getNestedClasses(); + final ICPPClassType[] nested = ClassTypeHelper.getNestedClasses((ICPPClassType) fb, point); if (nested.length > 0) { for (ICPPClassType ct : nested) { if (ct instanceof ICPPClassSpecialization && @@ -130,56 +132,131 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple @Override public final ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); + } + + @Override + public final ICPPBase[] getBases(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getBases(); + return ((ICPPClassSpecializationScope) scope).getBases(point); } - return super.getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases((ICPPClassType) rbinding, point); + return wrapBases(bases); } @Override public final ICPPConstructor[] getConstructors() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); + } + + @Override + public final ICPPConstructor[] getConstructors(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getConstructors(); + return ((ICPPClassSpecializationScope) scope).getConstructors(point); } - return super.getConstructors(); + ICPPConstructor[] result = ClassTypeHelper.getConstructors((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public ICPPMethod[] getMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public final ICPPMethod[] getDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); + } + + @Override + public final ICPPMethod[] getDeclaredMethods(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } - return super.getDeclaredMethods(); + ICPPMethod[] result = ClassTypeHelper.getDeclaredMethods((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); + } + + @Override + public final ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); } @Override public final ICPPField[] getDeclaredFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); + } + + @Override + public final ICPPField[] getDeclaredFields(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredFields(); + return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); } - return super.getDeclaredFields(); + ICPPField[] result = ClassTypeHelper.getDeclaredFields((ICPPClassType) rbinding, point); + return wrapBindings(result); + } + + @Override + public IField[] getFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); + } + + @Override + public final IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); } @Override public final IBinding[] getFriends() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); + } + + @Override + public final IBinding[] getFriends(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getFriends(); + return ((ICPPClassSpecializationScope) scope).getFriends(point); } - return super.getFriends(); + IBinding[] result = ClassTypeHelper.getFriends((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override public final ICPPClassType[] getNestedClasses() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); + } + + @Override + public final ICPPClassType[] getNestedClasses(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getNestedClasses(); + return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); } - return super.getNestedClasses(); + ICPPClassType[] result = ClassTypeHelper.getNestedClasses((ICPPClassType) rbinding, point); + return wrapBindings(result); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 4776ac8bdf6..b00a7b572dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -8,11 +8,14 @@ * Contributors: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; @@ -67,8 +70,14 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPMethod[] getImplicitMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getImplicitMethods(null); + } + + @Override + public ICPPMethod[] getImplicitMethods(IASTNode point) { createDelegate(); - return fDelegate.getImplicitMethods(); + return fDelegate.getImplicitMethods(point); } @Override @@ -97,37 +106,43 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme @Override public ICPPConstructor[] getConstructors() { - createDelegate(); - return fDelegate.getConstructors(); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); } @Override - public ICPPMethod[] getDeclaredMethods() { + public ICPPConstructor[] getConstructors(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredMethods(); + return fDelegate.getConstructors(point); } @Override - public ICPPBase[] getBases() { + public ICPPMethod[] getDeclaredMethods(IASTNode point) { createDelegate(); - return fDelegate.getBases(); + return fDelegate.getDeclaredMethods(point); } @Override - public ICPPField[] getDeclaredFields() { + public ICPPBase[] getBases(IASTNode point) { createDelegate(); - return fDelegate.getDeclaredFields(); + return fDelegate.getBases(point); } @Override - public IBinding[] getFriends() { + public ICPPField[] getDeclaredFields(IASTNode point) { createDelegate(); - return fDelegate.getFriends(); + return fDelegate.getDeclaredFields(point); } @Override - public ICPPClassType[] getNestedClasses() { + public IBinding[] getFriends(IASTNode point) { createDelegate(); - return fDelegate.getNestedClasses(); + return fDelegate.getFriends(point); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { + createDelegate(); + return fDelegate.getNestedClasses(point); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java index 1418d866aa9..9570ec658cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecializationSpecialization.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java index f6a197b91f7..9866bac677a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassType.java @@ -1,16 +1,19 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems 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 Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import java.util.Arrays; + import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; @@ -42,8 +45,8 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType } @Override - public final ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + public ICPPMethod[] getAllDeclaredMethods() { + return ClassTypeHelper.getAllDeclaredMethods(this, null); } private class CPPBaseDelegate implements ICPPBase { @@ -65,7 +68,7 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType if (baseClass != null) { return baseClass; } else { - return cf.getCompositeBinding((IIndexFragmentBinding)base.getBaseClass()); + return cf.getCompositeBinding((IIndexFragmentBinding) base.getBaseClass()); } } @@ -101,68 +104,48 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType @Override public ICPPBase[] getBases() { - final ICPPBase[] preresult = ((ICPPClassType) rbinding).getBases(); - ICPPBase[] result = new ICPPBase[preresult.length]; - for (int i= 0; i < preresult.length; i++) { - result[i] = new CPPBaseDelegate(preresult[i]); - } - return result; + ICPPBase[] bases = ((ICPPClassType) rbinding).getBases(); + return wrapBases(bases); } @Override public ICPPConstructor[] getConstructors() { ICPPConstructor[] result = ((ICPPClassType) rbinding).getConstructors(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPConstructor) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPField[] getDeclaredFields() { ICPPField[] result = ((ICPPClassType) rbinding).getDeclaredFields(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPField) cf.getCompositeBinding((IIndexFragmentBinding)result[i]); - } - return result; + return wrapBindings(result); } @Override public ICPPMethod[] getDeclaredMethods() { ICPPMethod[] result = ((ICPPClassType) rbinding).getDeclaredMethods(); - for (int i= 0; i < result.length; i++) { - result[i]= (ICPPMethod) cf.getCompositeBinding((IIndexFragmentBinding)result[i]); - } - return result; + return wrapBindings(result); } @Override - public final IField[] getFields() { - return ClassTypeHelper.getFields(this); + public IField[] getFields() { + return ClassTypeHelper.getFields(this, null); } @Override public IBinding[] getFriends() { IBinding[] preResult = ((ICPPClassType) rbinding).getFriends(); - IBinding[] result = new IBinding[preResult.length]; - for (int i= 0; i < preResult.length; i++) { - result[i] = cf.getCompositeBinding((IIndexFragmentBinding) preResult[i]); - } - return result; + return wrapBindings(preResult); } @Override - public final ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + public ICPPMethod[] getMethods() { + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPClassType[] getNestedClasses() { ICPPClassType[] result = ((ICPPClassType) rbinding).getNestedClasses(); - for (int i= 0; i < result.length; i++) { - result[i] = (ICPPClassType) cf.getCompositeBinding((IIndexFragmentBinding) result[i]); - } - return result; + return wrapBindings(result); } @Override @@ -184,4 +167,21 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType public boolean isAnonymous() { return ((ICPPClassType) rbinding).isAnonymous(); } + + protected ICPPBase[] wrapBases(final ICPPBase[] bases) { + ICPPBase[] result = new ICPPBase[bases.length]; + for (int i= 0; i < bases.length; i++) { + result[i] = new CPPBaseDelegate(bases[i]); + } + return result; + } + + @SuppressWarnings("unchecked") + protected T[] wrapBindings(T[] bindings) { + T[] result = Arrays.copyOf(bindings, bindings.length); + for (int i= 0; i < bindings.length; i++) { + result[i] = (T) cf.getCompositeBinding((IIndexFragmentBinding) bindings[i]); + } + return result; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java index a95fb3f576e..06cc8f1fc69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/TemplateInstanceUtil.java @@ -1,14 +1,15 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems 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 Ferguson (Symbian) - Initial implementation - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) - Initial implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -16,7 +17,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; @@ -26,15 +26,18 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +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.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; /** - * For implementation re-use in the absence of multiple inheritance + * For implementation re-use in the absence of multiple inheritance. */ public class TemplateInstanceUtil { + public static ICPPTemplateParameterMap getTemplateParameterMap(ICompositesFactory cf, ICPPTemplateInstance rbinding) { ICPPTemplateParameterMap preresult= rbinding.getTemplateParameterMap(); Integer[] keys= preresult.getAllParameterPositions(); @@ -50,8 +53,8 @@ public class TemplateInstanceUtil { result.put(key, convert(cf, pack)); } } - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); } return result; } @@ -90,22 +93,18 @@ public class TemplateInstanceUtil { } static ICPPTemplateArgument convert(ICompositesFactory cf, ICPPTemplateArgument arg) throws DOMException { - if (arg == null) - return null; - if (arg.isNonTypeValue()) { - final IType t= arg.getTypeOfNonTypeValue(); - final IType t2= cf.getCompositeType(t); - final IValue v= arg.getNonTypeValue(); - final IValue v2= cf.getCompositeValue(v); - if (t != t2 || v != v2) { - return new CPPTemplateArgument(v2, t2); + if (arg instanceof CPPTemplateTypeArgument) { + final IType typeValue = arg.getTypeValue(); + IType t= cf.getCompositeType(typeValue); + if (t != typeValue) { + return new CPPTemplateTypeArgument(t); + } + } else if (arg instanceof CPPTemplateNonTypeArgument) { + ICPPEvaluation eval = ((CPPTemplateNonTypeArgument) arg).getEvaluation(); + ICPPEvaluation eval2 = ((CPPCompositesFactory) cf).getCompositeEvaluation(eval); + if (eval2 != eval) { + return new CPPTemplateNonTypeArgument(eval2); } - return arg; - } - final IType typeValue = arg.getTypeValue(); - IType t= cf.getCompositeType(typeValue); - if (t != typeValue) { - return new CPPTemplateArgument(t); } return arg; } @@ -113,8 +112,8 @@ public class TemplateInstanceUtil { @Deprecated public static ObjectMap getArgumentMap(ICompositesFactory cf, IIndexBinding rbinding) { ICPPSpecialization specn= (ICPPSpecialization) rbinding; - IBinding specd= ((CPPCompositesFactory)cf).findOneBinding(specn.getSpecializedBinding()); - if(specd == null) + IBinding specd= ((CPPCompositesFactory) cf).findOneBinding(specn.getSpecializedBinding()); + if (specd == null) specd= specn.getSpecializedBinding(); ObjectMap preresult= specn.getArgumentMap(); @@ -122,14 +121,13 @@ public class TemplateInstanceUtil { Object[] keys= preresult.keyArray(); Object[] keysToAdapt= keys; - if(specd instanceof ICPPTemplateDefinition) { - keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters(); + if (specd instanceof ICPPTemplateDefinition) { + keysToAdapt= ((ICPPTemplateDefinition) specd).getTemplateParameters(); } - for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) { + for (int i= 0; i < keys.length && i < keysToAdapt.length; i++) { IType type= (IType) preresult.get(keys[i]); result.put( - cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]), - cf.getCompositeType(type)); + cf.getCompositeBinding((IIndexFragmentBinding) keysToAdapt[i]), cf.getCompositeType(type)); } return result; @@ -144,15 +142,15 @@ public class TemplateInstanceUtil { public static IType[] getArguments(ICompositesFactory cf, ICPPClassTemplatePartialSpecialization rbinding) { try { return getArguments(cf, rbinding.getArguments()); - } catch(DOMException de) { - CCorePlugin.log(de); + } catch (DOMException e) { + CCorePlugin.log(e); return IType.EMPTY_TYPE_ARRAY; } } @Deprecated private static IType[] getArguments(ICompositesFactory cf, IType[] result) { - for(int i=0; i elements = new ArrayList(); + + // Quote includes first + if (info instanceof IExtendedScannerInfo) { final IExtendedScannerInfo einfo= (IExtendedScannerInfo) info; - final String[] quoteIncludeSearchPath= einfo.getLocalIncludePath(); - if (quoteIncludeSearchPath != null && quoteIncludeSearchPath.length > 0) { - includeSearchPath= new IncludeSearchPathElement[quoteIncludeSearchPath.length + searchPath.length]; - for (String path : quoteIncludeSearchPath) { - includeSearchPath[idx++]= new IncludeSearchPathElement(makeAbsolute(directory, path), true); + final String[] paths= einfo.getLocalIncludePath(); + if (paths != null) { + for (String path : paths) { + if ("-".equals(path)) { //$NON-NLS-1$ + inhibitUseOfCurrentFileDirectory= true; + } else { + elements.add(new IncludeSearchPathElement(makeAbsolute(directory, path), true)); + } } } } - if (includeSearchPath == null) { - includeSearchPath= new IncludeSearchPathElement[searchPath.length]; - } - for (String path : searchPath) { - includeSearchPath[idx++]= new IncludeSearchPathElement(makeAbsolute(directory, path), false); - } - return includeSearchPath; + // Regular includes + String[] paths= info.getIncludePaths(); + if (paths != null) { + for (String path : paths) { + if ("-".equals(path)) { //$NON-NLS-1$ + inhibitUseOfCurrentFileDirectory= true; + } else { + elements.add(new IncludeSearchPathElement(makeAbsolute(directory, path), false)); + } + } + } + return new IncludeSearchPath(elements, inhibitUseOfCurrentFileDirectory); } private static String makeAbsolute(File directory, String includePath) { @@ -1074,8 +1084,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return tester.checkFile(absoluteInclusionPath, false, null); } - if (currentFile != null && quoteInclude && !includeNext) { - // Check to see if we find a match in the current directory + if (currentFile != null && quoteInclude && !includeNext && !fIncludeSearchPath.isInhibitUseOfCurrentFileDirectory()) { + // Check to see if we find a match in the directory of the current file final File currentDir= new File(currentFile).getParentFile(); if (currentDir != null) { final String fileLocation = ScannerUtility.createReconciledPath( @@ -1103,7 +1113,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } } - for (IncludeSearchPathElement path : fIncludeSearchPath) { + for (IncludeSearchPathElement path : fIncludeSearchPath.getElements()) { if (searchAfter != null) { if (searchAfter.equals(path)) { searchAfter= null; @@ -1146,7 +1156,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } private IncludeSearchPathElement findFileInIncludePath(String file, String includeDirective) { - for (IncludeSearchPathElement path : fIncludeSearchPath) { + for (IncludeSearchPathElement path : fIncludeSearchPath.getElements()) { String fileLocation = path.getLocation(includeDirective); if (file.equals(fileLocation)) { return path; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPath.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPath.java new file mode 100644 index 00000000000..6345deffafd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeSearchPath.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.parser.scanner; + +import java.util.List; + + +/** + * Represents the include search path + */ +public final class IncludeSearchPath { + private final boolean fInhibitUseOfCurrentFileDirectory; + private final IncludeSearchPathElement[] fElements; + + + IncludeSearchPath(List elements, boolean inhibitUseOfCurrentFileDirectory) { + fElements= elements.toArray(new IncludeSearchPathElement[elements.size()]); + fInhibitUseOfCurrentFileDirectory= inhibitUseOfCurrentFileDirectory; + } + + /** + * @return the elements of the include search path. + */ + public IncludeSearchPathElement[] getElements() { + return fElements; + } + + /** + * @return whether the use of the directory of the current file is inhibited. + */ + public boolean isInhibitUseOfCurrentFileDirectory() { + return fInhibitUseOfCurrentFileDirectory; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java index 2328b67a60d..3d3915eae69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/KeywordSets.java @@ -189,6 +189,7 @@ public class KeywordSets { EXPRESSION_CPP.add(Keywords.REINTERPRET_CAST); EXPRESSION_CPP.add(Keywords.CONST_CAST); EXPRESSION_CPP.add(Keywords.TYPEID); + EXPRESSION_CPP.add(Keywords.NOEXCEPT); EXPRESSION_CPP.add(Keywords.TRUE); EXPRESSION_CPP.add(Keywords.FALSE); EXPRESSION_CPP.add(Keywords.THIS); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 351dfbdd294..b758058f937 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -218,19 +218,20 @@ public class PDOM extends PlatformObject implements IPDOM { * 124.0 - GCC attributes and NO_RETURN flag for functions. * #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <> * - * CDT 8.2 development - * 130.0 - Dependent expressions, bug 299911 + * CDT 8.2 development (versions not supported on the 8.1.x branch) + * 130.0 - Dependent expressions, bug 299911. + * 131.0 - Dependent expressions part 2, bug 299911. */ - private static final int MIN_SUPPORTED_VERSION= version(130, 0); - private static final int MAX_SUPPORTED_VERSION= version(130, Short.MAX_VALUE); - private static final int DEFAULT_VERSION = version(130, 0); + private static final int MIN_SUPPORTED_VERSION= version(131, 0); + private static final int MAX_SUPPORTED_VERSION= version(131, Short.MAX_VALUE); + private static final int DEFAULT_VERSION = version(131, 0); private static int version(int major, int minor) { return (major << 16) + minor; } /** - * Returns the version that shall be used when creating new databases + * Returns the version that shall be used when creating new databases. */ public static int getDefaultVersion() { return DEFAULT_VERSION; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 6a90fe119aa..609d2d334bf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -100,7 +100,9 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.IPreferencesService; @@ -149,12 +151,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final PDOMIndexerJob fIndexerJob; private IPDOMIndexerTask fCurrentTask; private int fSourceCount, fHeaderCount, fTickCount; - + private final ArrayDeque fChangeEvents= new ArrayDeque(); private final Job fNotificationJob; - private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); - + private final AtomicMultiSet fFilesIndexedUnconditionlly= new AtomicMultiSet(); + /** * Stores mapping from pdom to project, used to serialize creation of new pdoms. */ @@ -162,7 +164,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private Map fFileToProject= new HashMap(); private ListenerList fChangeListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList(); - + private IndexChangeEvent fIndexChangeEvent= new IndexChangeEvent(); private IndexerStateEvent fIndexerStateEvent= new IndexerStateEvent(); @@ -172,17 +174,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private final ICProjectDescriptionListener fProjectDescriptionListener; private final JobChangeListener fJobChangeListener; private final IPreferenceChangeListener fPreferenceChangeListener; - + private IndexFactory fIndexFactory= new IndexFactory(this); private IndexProviderManager fIndexProviderManager = new IndexProviderManager(); - + /** - * Serializes creation of new indexer, when acquiring the lock you are + * Serializes creation of new indexer, when acquiring the lock you are * not allowed to hold a lock on fPDOMs. */ private Map fUpdatePolicies= new HashMap(); private Set fClosingProjects= new HashSet(); - + private Map fPrefListeners= new HashMap(); private List fSetupParticipants= new ArrayList(); private Set fPostponedProjects= new HashSet(); @@ -190,7 +192,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private boolean fInShutDown; boolean fTraceIndexerSetup; - + public PDOMManager() { PDOM.sDEBUG_LOCKS= "true".equals(Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/index/locks")); //$NON-NLS-1$//$NON-NLS-2$ addIndexerSetupParticipant(new WaitForRefreshJobs()); @@ -206,7 +208,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob= new PDOMIndexerJob(this); fNotificationJob= createNotifyJob(); } - + public Job startup() { fInShutDown= false; Job postStartupJob= new Job(CCorePlugin.getResourceString("CCorePlugin.startupJob")) { //$NON-NLS-1$ @@ -221,10 +223,10 @@ public class PDOMManager implements IWritableIndexManager, IListener { } }; postStartupJob.setSystem(true); - return postStartupJob; + return postStartupJob; } - /** + /** * Called from a job after plugin start. */ protected void postStartup() { @@ -236,7 +238,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { adjustCacheSize(); updatePathCanonicalizationStrategy(); fIndexProviderManager.startup(); - + fTraceIndexerSetup= String.valueOf(true).equals(Platform.getDebugOption(TRACE_INDEXER_SETUP)); final CoreModel model = CoreModel.getDefault(); ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD); @@ -270,7 +272,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fTaskQueue.clear(); jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(null, false); @@ -292,7 +294,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { reindexAll(); } } - + protected void adjustCacheSize() { IPreferencesService prefs = Platform.getPreferencesService(); int cachePct= prefs.getInt(CCorePlugin.PLUGIN_ID, CCorePreferenceConstants.INDEX_DB_CACHE_SIZE_PCT, 10, null); @@ -315,7 +317,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Returns the pdom for the project. + * Returns the pdom for the project. * @throws CoreException */ public IPDOM getPDOM(ICProject project) throws CoreException { @@ -329,9 +331,9 @@ public class PDOMManager implements IWritableIndexManager, IListener { return pdom; } } - + /** - * Returns the pdom for the project. The call to the method may cause + * Returns the pdom for the project. The call to the method may cause * opening the database. In case there is a version mismatch the data * base is cleared, in case it does not exist it is created. In any * case a pdom ready to use is returned. @@ -392,7 +394,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } pdom.setASTFilePathResolver(new ProjectIndexerInputAdapter(project, false)); pdom.addListener(this); - + fFileToProject.put(dbFile, project); fProjectToPDOM.put(rproject, pdom); if (pdomProxy instanceof PDOMProxy) { @@ -440,7 +442,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void setDefaultIndexerId(String indexerId) { IndexerPreferences.setDefaultIndexerId(indexerId); } - + @Override public String getIndexerId(ICProject project) { IProject prj= project != null ? project.getProject() : null; @@ -453,7 +455,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { IndexerPreferences.set(prj, IndexerPreferences.KEY_INDEXER_ID, indexerId); CCoreInternals.savePreferences(prj, IndexerPreferences.getScope(prj) == IndexerPreferences.SCOPE_PROJECT_SHARED); } - + protected void onPreferenceChange(ICProject cproject, PreferenceChangeEvent event) { if (IndexerPreferences.KEY_UPDATE_POLICY.equals(event.getKey())) { changeUpdatePolicy(cproject); @@ -484,17 +486,17 @@ public class PDOMManager implements IWritableIndexManager, IListener { private void changeIndexer(ICProject cproject) throws CoreException { assert !Thread.holdsLock(fProjectToPDOM); - + // if there is no indexer, don't touch the preferences. IPDOMIndexer oldIndexer= getIndexer(cproject); if (oldIndexer == null) { return; } - + IProject prj= cproject.getProject(); String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); Properties props= IndexerPreferences.getProperties(prj); - + synchronized (fUpdatePolicies) { if (fClosingProjects.contains(prj.getName())) { return; @@ -519,7 +521,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { enqueue(new PDOMRebuildTask(indexer)); } } - + if (oldIndexer != null) { stopIndexer(oldIndexer); } @@ -546,24 +548,24 @@ public class PDOMManager implements IWritableIndexManager, IListener { void createIndexer(ICProject project, IProgressMonitor pm) throws InterruptedException { final IProject prj= project.getProject(); final String name = prj.getName(); - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Creation for project " + name); //$NON-NLS-1$ - + assert !Thread.holdsLock(fProjectToPDOM); try { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup (1) for closing project " + name + " [1]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } - + WritablePDOM pdom= getOrCreatePDOM(project); Properties props= IndexerPreferences.getProperties(prj); IPDOMIndexer indexer= newIndexer(getIndexerId(project), props); IndexUpdatePolicy policy= createPolicy(project); - boolean rebuild= + boolean rebuild= pdom.isClearedBecauseOfVersionMismatch() || pdom.isCreatedFromScratch() || policy.isInitialRebuildRequested(); @@ -591,7 +593,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseReadLock(); } if (resume) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Resuming for project " + name); //$NON-NLS-1$ enqueue(new PDOMUpdateTask(indexer, @@ -608,7 +610,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { synchronized (fUpdatePolicies) { if (fClosingProjects.contains(name)) { - if (fTraceIndexerSetup) + if (fTraceIndexerSetup) System.out.println("Indexer: Aborting setup for closing project " + name + " [2]"); //$NON-NLS-1$ //$NON-NLS-2$ return; } @@ -623,13 +625,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (policy.isAutomatic() || policy.isInitialRebuildRequested()) { policy.clearInitialFlags(); if (operation.wasSuccessful()) { - if (fTraceIndexerSetup) - System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Imported shared index for project " + name); //$NON-NLS-1$ task= new PDOMUpdateTask(indexer, IIndexManager.UPDATE_CHECK_TIMESTAMPS | IIndexManager.UPDATE_CHECK_CONTENTS_HASH); } else { - if (fTraceIndexerSetup) - System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Rebuiding for project " + name); //$NON-NLS-1$ task= new PDOMRebuildTask(indexer); } enqueue(task); @@ -642,7 +644,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + private IPDOMIndexer newIndexer(String indexerId, Properties props) throws CoreException { IPDOMIndexer indexer = null; // Look up in extension point @@ -656,14 +658,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { indexer.setProperties(props); } catch (CoreException e) { CCorePlugin.log(e); - } + } break; } } } // Unknown index, default to the null one - if (indexer == null) + if (indexer == null) indexer = new PDOMNullIndexer(); return indexer; @@ -683,7 +685,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { fIndexerJob.schedule(); } } - + IPDOMIndexerTask getNextTask() { IPDOMIndexerTask result= null; synchronized (fTaskQueue) { @@ -703,7 +705,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } return result; } - + void cancelledIndexerJob(boolean byManager) { synchronized (fTaskQueue) { fCurrentTask= null; @@ -715,7 +717,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + @Override public boolean isIndexerIdle() { return Job.getJobManager().find(this).length == 0; @@ -725,19 +727,19 @@ public class PDOMManager implements IWritableIndexManager, IListener { final String name = cproject.getProject().getName(); if (fTraceIndexerSetup) { System.out.println("Indexer: Adding new project " + name); //$NON-NLS-1$ - } - + } + synchronized (fUpdatePolicies) { fClosingProjects.remove(name); } - + setupProject(cproject); } void setupProject(final ICProject cproject) { if (fInShutDown) return; - + synchronized (fProjectQueue) { fProjectQueue.add(cproject); } @@ -776,7 +778,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (indexer != null && indexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) { return; } - + if (added.length > 0 || changed.length > 0 || removed.length > 0) { synchronized (fUpdatePolicies) { IndexUpdatePolicy policy= createPolicy(project); @@ -807,7 +809,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } public void preDeleteProject(ICProject cproject) { - preRemoveProject(cproject, true); + preRemoveProject(cproject, true); } public void preCloseProject(ICProject cproject) { @@ -820,8 +822,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { final IProject rproject= cproject.getProject(); final String name = rproject.getName(); - if (fTraceIndexerSetup) - System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ + if (fTraceIndexerSetup) + System.out.println("Indexer: Removing project " + name + "; delete=" + delete); //$NON-NLS-1$ //$NON-NLS-2$ IPDOMIndexer indexer; synchronized (fUpdatePolicies) { @@ -868,12 +870,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { job.setSystem(true); job.schedule(); } - + synchronized (fUpdatePolicies) { fUpdatePolicies.remove(cproject); } } - + void removeProject(ICProject cproject, ICElementDelta delta) { synchronized (fProjectToPDOM) { IProject rproject= cproject.getProject(); @@ -893,7 +895,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { policy.clearTUs(); policy.setIndexer(null); } - } + } } cancelIndexerJobs(indexer); } @@ -909,13 +911,13 @@ public class PDOMManager implements IWritableIndexManager, IListener { } jobToCancel= fIndexerJob; } - + if (jobToCancel != null) { assert !Thread.holdsLock(fTaskQueue); jobToCancel.cancelJobs(indexer, true); } - } - + } + private void reindexAll() { ICProject[] cProjects; try { @@ -930,7 +932,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public void reindex(final ICProject project) { - Job job= new Job(Messages.PDOMManager_notifyJob_label) { + Job job= new Job(Messages.PDOMManager_notifyJob_label) { @Override protected IStatus run(IProgressMonitor monitor) { IPDOMIndexer indexer= null; @@ -971,7 +973,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public void removeIndexChangeListener(IIndexChangeListener listener) { fChangeListeners.remove(listener); } - + @Override public void addIndexerStateListener(IIndexerStateListener listener) { fStateListeners.add(listener); @@ -1001,7 +1003,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { notify.setSystem(true); return notify; } - + private void scheduleNotification(Runnable notify) { if (fInShutDown) return; @@ -1052,12 +1054,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fChangeListeners.isEmpty()) { return; } - + ICProject project; synchronized (fProjectToPDOM) { project = fFileToProject.get(pdom.getPath()); - } - + } + if (project != null) { final ICProject finalProject= project; Runnable notify= new Runnable() { @@ -1088,41 +1090,47 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override public boolean joinIndexer(final int waitMaxMillis, final IProgressMonitor monitor) { assert monitor != null; - Thread th= null; - if (waitMaxMillis != FOREVER) { - final Thread callingThread= Thread.currentThread(); - th= new Thread() { - @Override - public void run() { + long deadline = waitMaxMillis == FOREVER ? Long.MAX_VALUE : System.currentTimeMillis() + waitMaxMillis; + + final boolean[] idleCondition = { false }; + JobChangeAdapter listener = new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + synchronized (idleCondition) { + if (Job.getJobManager().find(PDOMManager.this).length == 0) { + idleCondition[0] = true; + idleCondition.notifyAll(); + } + } + } + }; + Job.getJobManager().addJobChangeListener(listener); + try { + if (Job.getJobManager().find(this).length == 0) { + return true; + } + synchronized (idleCondition) { + while (!idleCondition[0]) { try { - Thread.sleep(waitMaxMillis); - monitor.setCanceled(true); - callingThread.interrupt(); + if (monitor.isCanceled()) + return false; + long t = System.currentTimeMillis(); + if (t >= deadline) + return false; + idleCondition.wait(Math.min(100, deadline - t)); } catch (InterruptedException e) { } } - }; - th.setDaemon(true); - th.start(); - } - try { - try { - Job.getJobManager().join(this, monitor); return true; - } catch (OperationCanceledException e) { - } catch (InterruptedException e) { } - return Job.getJobManager().find(this).length == 0; } finally { - if (th != null) { - th.interrupt(); - } + Job.getJobManager().removeJobChangeListener(listener); } } - + int getMonitorMessage(PDOMIndexerJob job, int currentTicks, int base) { assert !Thread.holdsLock(fTaskQueue); - + int sourceCount, sourceEstimate, headerCount, tickCount, tickEstimate; String detail= null; synchronized (fTaskQueue) { @@ -1149,14 +1157,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { detail= PDOMIndexerJob.sMonitorDetail; } } - - String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { - new Integer(sourceCount), new Integer(sourceEstimate), - new Integer(headerCount)}); + + String msg= MessageFormat.format(Messages.PDOMManager_indexMonitorDetail, new Object[] { + new Integer(sourceCount), new Integer(sourceEstimate), + new Integer(headerCount)}); if (detail != null) { msg += ": " + detail; //$NON-NLS-1$ } - + job.subTask(msg); if (tickCount > 0 && tickCount <= tickEstimate) { int newTick= tickCount*base/tickEstimate; @@ -1192,7 +1200,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public IIndex getIndex(ICProject[] projects, int options) throws CoreException { return fIndexFactory.getIndex(projects, options); } - + /** * Exports the project PDOM to the specified location, rewriting locations with * the specified location converter. @@ -1228,7 +1236,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } // Overwrite internal location representations. - final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); + final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); newPDOM.acquireWriteLock(); try { newPDOM.rewriteLocations(newConverter); @@ -1248,7 +1256,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } /** - * Resets the pdom for the project with the provided stream. + * Resets the pdom for the project with the provided stream. * @throws CoreException * @throws OperationCanceledException in case the thread was interrupted * @since 4.0 @@ -1267,11 +1275,11 @@ public class PDOMManager implements IWritableIndexManager, IListener { } if (version > PDOM.getMaxSupportedVersion()) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedHigherVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } if ( !PDOM.isSupportedVersion( version ) ) { final IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, 0, CCorePlugin.getResourceString("PDOMManager.unsupportedVersion"), null); //$NON-NLS-1$ - throw new CoreException(status); + throw new CoreException(status); } byte[] buffer= new byte[2048]; int read; @@ -1281,7 +1289,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } finally { out.close(); } - + WritablePDOM pdom= (WritablePDOM) getPDOM(project); try { pdom.acquireWriteLock(); @@ -1296,7 +1304,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { pdom.releaseWriteLock(); } } - + @Override public void export(ICProject project, String location, int options, IProgressMonitor monitor) throws CoreException { TeamPDOMExportOperation operation= new TeamPDOMExportOperation(project); @@ -1304,7 +1312,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { operation.setOptions(options); operation.run(monitor); } - + /** * Write metadata appropriate for a project pdom * @param pdom the pdom to write to @@ -1335,7 +1343,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { for (Map.Entry> entry : projectsToElements.entrySet()) { ICProject project = entry.getKey(); List filesAndFolders = entry.getValue(); - + update(project, filesAndFolders, options); } } @@ -1362,14 +1370,14 @@ public class PDOMManager implements IWritableIndexManager, IListener { } else if (contains(element, other)) { set.set(j, element); continue allElements; - } + } } set.add(element); } } return result; } - + private boolean contains(final ICElement a, ICElement b) { if (a.equals(b)) { return true; @@ -1467,7 +1475,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (fPostponedProjects.contains(project)) { setupProject(project); } - } + } } @Override @@ -1486,7 +1494,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + /** * @param project * @return whether the specified project has been registered. If a project has @@ -1496,7 +1504,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectRegistered(ICProject project) { return getIndexer(project) != null; } - + /** * @param cproject the project to check * @return whether the content in the project fragment of the specified project's index @@ -1506,7 +1514,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { public boolean isProjectContentSynced(ICProject cproject) throws CoreException { if (!"true".equals(IndexerPreferences.get(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, null))) //$NON-NLS-1$ return true; // no check performed in this case - + Set sources= new HashSet(); cproject.accept(new TranslationUnitCollector(sources, null, new NullProgressMonitor())); @@ -1532,7 +1540,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { return true; } - + private boolean isSubjectToIndexing(ILanguage language) { final int linkageID=language.getLinkageID(); for (int id : IDS_FOR_LINKAGES_TO_INDEX) { @@ -1554,7 +1562,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private static boolean areSynchronized(Set trail, IIndex index, IResource resource, IIndexFileLocation location) throws CoreException { if (!trail.contains(location)) { trail.add(location); - + IIndexFile[] file= index.getFiles(location); // pre-includes may be listed twice (191989) @@ -1580,7 +1588,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } } - + return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java index 7c3f483a70e..b3e7656fca4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/TypeMarshalBuffer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.db; @@ -16,11 +17,15 @@ import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; 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.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.core.runtime.CoreException; @@ -93,7 +98,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { byte firstByte= fBuffer[fPos]; if (firstByte == BINDING_TYPE) { - fPos+= 2; + fPos += 2; long rec= getRecordPointer(); return (IBinding) fLinkage.getNode(rec); } else if (firstByte == NULL_TYPE || firstByte == UNSTORABLE_TYPE) { @@ -182,6 +187,27 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer { return Value.unmarshal(this); } + @Override + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg instanceof CPPTemplateNonTypeArgument) { + putByte(VALUE); + ((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + int firstByte= getByte(); + if (firstByte == VALUE) { + return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation()); + } else { + fPos--; + return new CPPTemplateTypeArgument(unmarshalType()); + } + } + private void request(int i) { if (fBuffer == null) { if (i <= Database.TYPE_SIZE) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java index 604ad31d3cd..0fc6df2b276 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPArgumentList.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -15,7 +15,8 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +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.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -36,17 +37,18 @@ public class PDOMCPPArgumentList { public static long putArguments(PDOMNode parent, ICPPTemplateArgument[] templateArguments) throws CoreException { final PDOMLinkage linkage= parent.getLinkage(); final Database db= linkage.getDB(); - final short len= (short) Math.min(templateArguments.length, (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); - final long block= db.malloc(2+NODE_SIZE*len); + final short len= (short) Math.min(templateArguments.length, (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE); + final long block= db.malloc(2 + NODE_SIZE * len); long p= block; - db.putShort(p, len); p+=2; - for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); - long p= record+2; - for (int i=0; i= 0 && len <= (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE); + long p= record + 2; + for (int i= 0; i < len; i++) { linkage.storeType(p, null); - linkage.storeValue(p+VALUE_OFFSET, null); + linkage.storeValue(p + VALUE_OFFSET, null); p+= NODE_SIZE; } db.free(record); @@ -81,25 +82,25 @@ public class PDOMCPPArgumentList { final Database db= linkage.getDB(); final short len= db.getShort(rec); - Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE-2)/NODE_SIZE); + Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE); if (len == 0) { return ICPPTemplateArgument.EMPTY_ARGUMENTS; } - rec+=2; + rec += 2; ICPPTemplateArgument[] result= new ICPPTemplateArgument[len]; - for (int i=0; i> fInProgress= new ThreadLocal>(); public PDOMCPPClassSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPClassType classType, @@ -76,7 +76,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public PDOMCPPClassSpecialization(PDOMLinkage linkage, long bindingRecord) { super(linkage, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -91,14 +91,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public ICPPClassType getSpecializedBinding() { return (ICPPClassType) super.getSpecializedBinding(); } - + @Override public IBinding specializeMember(IBinding original) { return specializeMember(original, null); } @Override - public IBinding specializeMember(IBinding original, IASTNode point) { + public IBinding specializeMember(IBinding original, IASTNode point) { if (specializationMap == null) { final Long key= record+PDOMCPPLinkage.CACHE_INSTANCE_SCOPE; Object cached= getPDOM().getCachedResult(key); @@ -124,14 +124,14 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements Set set; synchronized (specializationMap) { IBinding result= (IBinding) specializationMap.get(original); - if (result != null) + if (result != null) return result; set= fInProgress.get(); if (set == null) { set= new HashSet(); fInProgress.set(set); - } - if (!set.add(original)) + } + if (!set.add(original)) return new RecursionResolvingBinding(null, null); } IBinding newSpec= CPPTemplates.createSpecialization(this, original, point); @@ -154,7 +154,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements if (hasOwnScope()) { fScope= new PDOMCPPClassScope(this); return fScope; - } + } } catch (CoreException e) { } fScope= new PDOMCPPClassSpecializationScope(this); @@ -167,22 +167,22 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } public PDOMCPPBase getFirstBase() throws CoreException { - long rec = getDB().getRecPtr(record + FIRSTBASE); + long rec = getDB().getRecPtr(record + FIRST_BASE); return rec != 0 ? new PDOMCPPBase(getLinkage(), rec) : null; } private void setFirstBase(PDOMCPPBase base) throws CoreException { long rec = base != null ? base.getRecord() : 0; - getDB().putRecPtr(record + FIRSTBASE, rec); + getDB().putRecPtr(record + FIRST_BASE, rec); } - + public void addBase(PDOMCPPBase base) throws CoreException { getPDOM().removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase firstBase = getFirstBase(); base.setNextBase(firstBase); setFirstBase(base); } - + public void removeBase(PDOMName pdomName) throws CoreException { getPDOM().removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase base= getFirstBase(); @@ -205,25 +205,31 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements base.delete(); } } - - // implementation of class type + @Override public ICPPBase[] getBases() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getBases(null); + } + + @Override + public ICPPBase[] getBases(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getBases(); - } - - // this is an explicit specialization + return ((ICPPClassSpecializationScope) scope).getBases(point); + } + + // This is an explicit specialization Long key= record + PDOMCPPLinkage.CACHE_BASES; ICPPBase[] bases= (ICPPBase[]) getPDOM().getCachedResult(key); - if (bases != null) + if (bases != null) return bases; try { List list = new ArrayList(); - for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) + for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) { list.add(base); + } Collections.reverse(list); bases = list.toArray(new ICPPBase[list.size()]); getPDOM().putCachedResult(key, bases); @@ -233,12 +239,18 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } return ICPPBase.EMPTY_BASE_ARRAY; } - + @Override public ICPPConstructor[] getConstructors() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getConstructors(null); + } + + @Override + public ICPPConstructor[] getConstructors(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getConstructors(); + return ((ICPPClassSpecializationScope) scope).getConstructors(point); } try { PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); @@ -252,9 +264,15 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPMethod[] getDeclaredMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredMethods(null); + } + + @Override + public ICPPMethod[] getDeclaredMethods(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(point); } try { PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); @@ -268,10 +286,16 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public ICPPField[] getDeclaredFields() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getDeclaredFields(null); + } + + @Override + public ICPPField[] getDeclaredFields(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getDeclaredFields(); - } + return ((ICPPClassSpecializationScope) scope).getDeclaredFields(point); + } try { PDOMClassUtil.FieldCollector visitor = new PDOMClassUtil.FieldCollector(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -281,13 +305,19 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return ICPPField.EMPTY_CPPFIELD_ARRAY; } } - + @Override public ICPPClassType[] getNestedClasses() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getNestedClasses(null); + } + + @Override + public ICPPClassType[] getNestedClasses(IASTNode point) { IScope scope= getCompositeScope(); if (scope instanceof ICPPClassSpecializationScope) { - return ((ICPPClassSpecializationScope) scope).getNestedClasses(); - } + return ((ICPPClassSpecializationScope) scope).getNestedClasses(point); + } try { PDOMClassUtil.NestedClassCollector visitor = new PDOMClassUtil.NestedClassCollector(); PDOMCPPClassScope.acceptViaCache(this, visitor, false); @@ -300,25 +330,49 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public IBinding[] getFriends() { - // not yet supported. + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFriends(null); + } + + @Override + public IBinding[] getFriends(IASTNode point) { + // Not yet supported. return IBinding.EMPTY_BINDING_ARRAY; } @Override - public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + public ICPPMethod[] getMethods() { + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getMethods(null); + } + + @Override + public ICPPMethod[] getMethods(IASTNode point) { + return ClassTypeHelper.getMethods(this, point); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getAllDeclaredMethods(null); } - + + @Override + public ICPPMethod[] getAllDeclaredMethods(IASTNode point) { + return ClassTypeHelper.getAllDeclaredMethods(this, point); + } + @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$ + return getFields(null); } - + + @Override + public IField[] getFields(IASTNode point) { + return ClassTypeHelper.getFields(this, point); + } + @Override public IField findField(String name) { return ClassTypeHelper.findField(this, name); @@ -350,7 +404,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return CPPClassSpecialization.isSameClassSpecialization(this, (ICPPClassSpecialization) type); } - + @Override public Object clone() { try { @@ -362,13 +416,13 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements @Override public void addChild(PDOMNode member) throws CoreException { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST); + PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBER_LIST); list.addMember(member); } @Override public void acceptUncached(IPDOMVisitor visitor) throws CoreException { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST); + PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBER_LIST); list.accept(visitor); } @@ -376,7 +430,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public void accept(IPDOMVisitor visitor) throws CoreException { PDOMCPPClassScope.acceptViaCache(this, visitor, false); } - + @Override public boolean isAnonymous() { return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java index ccbdb499f7b..f370b1e8fc3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java @@ -158,7 +158,7 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization @Override public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. ICPPClassTemplate origTemplate= (ICPPClassTemplate) getSpecializedBinding(); ICPPClassTemplatePartialSpecialization[] orig = origTemplate.getPartialSpecializations(); ICPPClassTemplatePartialSpecialization[] spec = new ICPPClassTemplatePartialSpecialization[orig.length]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index f79a0c1f2f1..1ebf474b9ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -351,17 +351,17 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO @Override public ICPPMethod[] getMethods() { - return ClassTypeHelper.getMethods(this); + return ClassTypeHelper.getMethods(this, null); } @Override public ICPPMethod[] getAllDeclaredMethods() { - return ClassTypeHelper.getAllDeclaredMethods(this); + return ClassTypeHelper.getAllDeclaredMethods(this, null); } @Override public IField[] getFields() { - return ClassTypeHelper.getFields(this); + return ClassTypeHelper.getFields(this, null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index decd3d170cb..1e15385117e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; @@ -63,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; @@ -77,6 +82,7 @@ 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.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; @@ -114,11 +120,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - /** * Container for c++-entities. */ @@ -252,7 +253,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { PDOMBinding pdomBinding = addBinding(binding, name); if (pdomBinding instanceof PDOMCPPClassType || pdomBinding instanceof PDOMCPPClassSpecialization) { if (binding instanceof ICPPClassType && name.isDefinition()) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, name); } } @@ -299,7 +300,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (pdomBinding != null) { getPDOM().putCachedResult(inputBinding, pdomBinding); if (inputBinding instanceof CPPClosureType) { - addImplicitMethods(pdomBinding, (ICPPClassType) binding); + addImplicitMethods(pdomBinding, (ICPPClassType) binding, fromName); } } } catch (DOMException e) { @@ -490,17 +491,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return result; } - private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { + private void addImplicitMethods(PDOMBinding type, ICPPClassType binding, IASTNode point) throws CoreException { try { final long fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { List old= new ArrayList(); if (type instanceof ICPPClassType) { - IScope oldScope = ((ICPPClassType)type).getCompositeScope(); - if (oldScope instanceof ICPPClassScope) { - old.addAll(Arrays.asList(((ICPPClassScope) oldScope).getImplicitMethods())); - } + ArrayUtil.addAll(old, ClassTypeHelper.getImplicitMethods((ICPPClassType) type, point)); } ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); for (ICPPMethod method : implicit) { @@ -1109,5 +1107,4 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } throw new CoreException(CCorePlugin.createStatus("Cannot unmarshal an evaluation, first byte=" + firstByte)); //$NON-NLS-1$ } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index df9d4578aa9..7360c7a1ff5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -253,7 +253,7 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod { @Override public IType[] getExceptionSpecification() { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, null); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java index 03dfa708e9d..1de4f84d7e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java @@ -6,16 +6,18 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPMethodSpecialization; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; @@ -30,8 +32,7 @@ import org.eclipse.core.runtime.CoreException; * Specialization of a method */ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization - implements ICPPMethod { - + implements ICPPMethodSpecialization { /** * Offset of remaining annotation information (relative to the beginning of * the record). @@ -67,7 +68,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization public PDOMCPPMethodSpecialization(PDOMLinkage linkage, long bindingRecord) { super(linkage, bindingRecord); } - + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -135,9 +136,9 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization } @Override - public IType[] getExceptionSpecification() { + public IType[] getExceptionSpecification(IASTNode point) { if (isImplicit()) { - return ClassTypeHelper.getInheritedExceptionSpecification(this); + return ClassTypeHelper.getInheritedExceptionSpecification(this, point); } return super.getExceptionSpecification(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java index 836b8a637bd..5b5988ebfad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Sergey Prigogin (Google) - * Andrew Ferguson (Symbian) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; 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.IPDOMMemberOwner; @@ -35,9 +35,8 @@ import org.eclipse.core.runtime.CoreException; /** * Binding for template non-type parameter in the index. */ -class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner, - ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter { - +class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding + implements IPDOMMemberOwner, ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter { private static final int TYPE_OFFSET= PDOMCPPBinding.RECORD_SIZE; private static final int PARAMETERID= TYPE_OFFSET + Database.TYPE_SIZE; private static final int DEFAULTVAL= PARAMETERID + Database.VALUE_SIZE; @@ -74,7 +73,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem IValue val= getLinkage().loadValue(record + DEFAULTVAL); if (val == null) return null; - return new CPPTemplateArgument(val, getType()); + return new CPPTemplateNonTypeArgument(val, getType()); } catch (CoreException e) { CCorePlugin.log(e); return null; @@ -100,8 +99,8 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem @Override public void forceDelete(PDOMLinkage linkage) throws CoreException { getDBName().delete(); - linkage.storeType(record+TYPE_OFFSET, null); - linkage.storeValue(record+DEFAULTVAL, null); + linkage.storeType(record + TYPE_OFFSET, null); + linkage.storeValue(record + DEFAULTVAL, null); } @Override @@ -112,7 +111,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem @Override public short getTemplateNestingLevel() { readParamID(); - return (short)(getParameterID() >> 16); + return (short) (getParameterID() >> 16); } @Override @@ -184,18 +183,22 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public IValue getInitialValue() { return null; } + @Override public boolean isAuto() { return false; } + @Override public boolean isExtern() { return false; } + @Override public boolean isRegister() { return false; } + @Override public boolean isStatic() { return false; @@ -204,6 +207,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public boolean isExternC() { return false; } + @Override public boolean isMutable() { return false; @@ -213,6 +217,7 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public Object clone() { throw new UnsupportedOperationException(); } + /** * @deprecated */ @@ -221,5 +226,4 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding implements IPDOMMem public IASTExpression getDefault() { return null; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java index 32bd0ad3e13..74b2e6ef453 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateParameterMap.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -16,8 +16,9 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -42,32 +43,32 @@ public class PDOMCPPTemplateParameterMap { int keyLen= 0; int dataSize= 2; for (Integer key : keys) { - int delta= 2+4+NODE_SIZE; + int delta= 2 + 4 + NODE_SIZE; ICPPTemplateArgument[] packExpansion= map.getPackExpansion(key); if (packExpansion != null) { - delta+= (packExpansion.length-1) * NODE_SIZE; + delta += (packExpansion.length - 1) * NODE_SIZE; } - if (dataSize+delta > Database.MAX_MALLOC_SIZE) + if (dataSize + delta > Database.MAX_MALLOC_SIZE) break; dataSize += delta; keyLen++; } final long block= db.malloc(dataSize); long p= block; - db.putShort(p, (short)keyLen); p+=2; + db.putShort(p, (short) keyLen); p += 2; for (final Integer paramId : keys) { if (--keyLen < 0) break; - db.putInt(p, paramId); p+=4; + db.putInt(p, paramId); p += 4; final ICPPTemplateArgument arg = map.getArgument(paramId); if (arg != null) { - db.putShort(p, (short) -1); p+=2; - storeArgument(db, linkage, p, arg); p+= NODE_SIZE; + db.putShort(p, (short) -1); p += 2; + storeArgument(db, linkage, p, arg); p += NODE_SIZE; } else { final ICPPTemplateArgument[] args = map.getPackExpansion(paramId); - db.putShort(p, (short) args.length); p+=2; + db.putShort(p, (short) args.length); p += 2; for (ICPPTemplateArgument a : args) { - storeArgument(db, linkage, p, a); p+= NODE_SIZE; + storeArgument(db, linkage, p, a); p += NODE_SIZE; } } } @@ -93,16 +94,16 @@ public class PDOMCPPTemplateParameterMap { final Database db= linkage.getDB(); long p= record; - final short len= db.getShort(p); p+= 2; + final short len= db.getShort(p); p += 2; - for (int i=0; i> resourceMap = getResourcesToExclusionsMap(project,configName); + + //special case for bug 387428 + CProjectDescriptionManager descriptionManager = CProjectDescriptionManager.getInstance(); + ICProjectDescription projectDescription = descriptionManager.getProjectDescription(project, false); + if (projectDescription == null && resourceMap.keySet().isEmpty()) { + //return project itself as the default to refresh + ArrayList resources = new ArrayList(); + resources.add(project); + return resources; + } return new ArrayList(resourceMap.keySet()); } @@ -520,13 +529,16 @@ public class RefreshScopeManager { // for each build configuration CProjectDescriptionManager descriptionManager = CProjectDescriptionManager.getInstance(); ICProjectDescription projectDescription = descriptionManager.getProjectDescription(project, false); - ICConfigurationDescription cfgDescs[] = projectDescription.getConfigurations(); - for (ICConfigurationDescription cfgDesc : cfgDescs) { - String configName = cfgDesc.getName(); - HashMap> resourceMap = new HashMap>(); - if (!fIsLoading || fIsNewProject) //config settings could be loading and detects a new project and if so, add the default refresh setting - resourceMap.put(project, new LinkedList()); - configMap.put(configName, resourceMap); + + if (projectDescription != null) { + ICConfigurationDescription cfgDescs[] = projectDescription.getConfigurations(); + for (ICConfigurationDescription cfgDesc : cfgDescs) { + String configName = cfgDesc.getName(); + HashMap> resourceMap = new HashMap>(); + if (!fIsLoading || fIsNewProject) //config settings could be loading and detects a new project and if so, add the default refresh setting + resourceMap.put(project, new LinkedList()); + configMap.put(configName, resourceMap); + } } // and add this configMap to the project to config map. @@ -609,8 +621,7 @@ public class RefreshScopeManager { addExclusion(project, configName, resource, exclusion); } } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + CCorePlugin.log(e); } } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java index 7b5affd6f35..cb45f1e99c3 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java @@ -61,8 +61,11 @@ public class AutomatedSuite extends TestSuite { // tests for package org.eclipse.cdt.ui.tests.viewsupport addTest(ViewSupportTestSuite.suite()); + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // tests for package org.eclipse.cdt.ui.tests.callhierarchy addTest(CallHierarchyTestSuite.suite()); + } // tests for package org.eclipse.cdt.ui.tests.typehierarchy addTest(TypeHierarchyTestSuite.suite()); @@ -75,9 +78,12 @@ public class AutomatedSuite extends TestSuite { // tests from package org.eclipse.cdt.ui.tests.text.contentAssist2 addTest(ContentAssist2TestSuite.suite()); - + + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // tests from package org.eclipse.cdt.ui.tests.text.selection addTest(SelectionTestSuite.suite()); + } // tests from package org.eclipse.cdt.ui.tests.quickfix addTest(AssistQuickFixTest.suite()); @@ -88,8 +94,11 @@ public class AutomatedSuite extends TestSuite { // tests from package org.eclipse.cdt.ui.tests.search addTest(SearchTestSuite.suite()); + // Has intermittent failures + if (System.getProperty("cdt.skip.known.test.failures") == null) { //$NON-NLS-1$ // tests from package org.eclipse.cdt.ui.tests.refactoring addTest(RefactoringTestSuite.suite()); + } // tests from package org.eclipse.cdt.ui.tests.chelp addTest(CHelpTest.suite()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index c8a9ef8cec8..d8b237b69dc 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -41,6 +41,7 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.internal.WorkbenchPartReference; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -282,12 +283,16 @@ public class BaseUITestCase extends BaseTestCase { } final protected TreeItem checkTreeNode(IViewPart part, int i0, String label) { + assertNotNull(label); // we don't handle testing for a base node to not appear; can be added if/when needed + IViewReference viewRef = part.getViewSite().getPage().findViewReference(part.getViewSite().getId()); + Control viewControl = ((WorkbenchPartReference)viewRef).getPane().getControl(); + Tree tree= null; TreeItem root= null; StringBuilder cands= new StringBuilder(); for (int i= 0; i < 400; i++) { cands.setLength(0); - Control[] trees= findControls(part.getSite().getShell(), Tree.class); + Control[] trees= findControls(viewControl, Tree.class); for (int j = 0; j < trees.length; j++) { try { tree= (Tree) trees[j]; @@ -314,6 +319,7 @@ public class BaseUITestCase extends BaseTestCase { } final protected TreeItem checkTreeNode(Tree tree, int i0, String label) { + assertNotNull(label); // we don't handle testing for a base node to not appear; can be added if/when needed TreeItem root= null; for (int millis= 0; millis < 5000; millis= millis == 0 ? 1 : millis * 2) { runEventQueue(millis); @@ -328,52 +334,50 @@ public class BaseUITestCase extends BaseTestCase { // item does not yet exist. } } - assertNotNull("Tree node " + label + "{" + i0 + "} does not exist!", root); - assertEquals(label, root.getText()); - return root; + fail("Tree node " + label + "{" + i0 + "} does not exist!"); + return null; } + /** + * Pass label=null to test that the {i0,i1} node doesn't exist + */ final protected TreeItem checkTreeNode(Tree tree, int i0, int i1, String label) { - TreeItem item= null; - String itemText= null; - SWTException ex= null; String firstItemText= null; - for (int millis= 0; millis < 5000; millis= millis == 0 ? 1 : millis * 2) { + int timeout = (label == null) ? 1000 : 5000; // see footnote[0] + + // If {i0,i1} exists, whether or not it matches label (when label != null) + boolean nodePresent = false; + + for (int millis= 0; millis < timeout; millis= millis == 0 ? 1 : millis * 2) { + nodePresent = false; runEventQueue(millis); - TreeItem root= tree.getItem(i0); - if (!root.getExpanded()) { - expandTreeItem(root); + TreeItem i0Node= tree.getItem(i0); + if (!i0Node.getExpanded()) { + expandTreeItem(i0Node); } - ex= null; try { - TreeItem firstItem= root.getItem(0); + TreeItem firstItem= i0Node.getItem(0); firstItemText= firstItem.getText(); if (firstItemText.length() > 0 && !firstItemText.equals("...")) { - item= root.getItem(i1); - itemText= item.getText(); - assertNotNull("Unexpected tree node " + itemText, label); - if (label.equals(itemText)) { - return item; - } - if (millis > 2000) { - assertEquals(label, itemText); + TreeItem item = i0Node.getItem(i1); + nodePresent = true; + if (label != null && label.equals(item.getText())) { return item; } } - } catch (IllegalArgumentException e) { - if (label != null) { - fail("Tree node " + label + "{" + i0 + "," + i1 + "} does not exist!"); - } - return null; } catch (SWTException e) { - // widget was disposed, try again. - ex= e; + // in case widget was disposed, item may be replaced + } catch (IllegalArgumentException e) { + // item does not yet exist. } } - if (ex != null) - throw ex; - - assertEquals("Timeout expired waiting for tree node {" + i0 + "," + i1 + "}; firstItem=" + firstItemText, label, itemText); + + if (label == null) { + assertFalse("Tree node {" + i0 + "," + i1 + "} exists but shouldn't!", nodePresent); + } + else { + fail("Tree node " + label + "{" + i0 + "," + i1 + "} does not exist!"); + } return null; } @@ -381,3 +385,17 @@ public class BaseUITestCase extends BaseTestCase { StringAsserts.assertEqualString(actual, expected); } } + +// Footnotes +// [0] Waiting for something to appear is very efficient; waiting for it to not +// appear is very inefficient. In the former case, regardless of how much time +// is alloted, we stop waiting as soon as the item appears, whereas in the +// latter we have to wait the entire timeout. In test suites with thousands of +// tests, efficiency is critical. Thus, in testing that a tree node doesn't have +// an Nth child, we shoot for efficiency and accept the risk of a false +// negative. More specifically, we wait only one second for the item TO NOT +// appear, whereas we give an item up to five seconds TO appear. This compromise +// is better than not having that sort of test at all, which some would argue is +// the better approach. In practice, it takes about 60-150 ms for the item to +// appear (on my machine), but we give it up to five seconds. Waiting one second +// for it to not appear should be more than adequate diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java index 160d01cd05c..f3af0034516 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestBase.java @@ -56,7 +56,7 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContext; * Common base for refactoring tests. */ public abstract class RefactoringTestBase extends BaseTestCase { - private static final int INDEXER_TIMEOUT_SEC = 360; + private static final int INDEXER_TIMEOUT_SEC = 300; protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); /** Allows empty files to be created during test setup. */ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java index a9c17f01e13..4446a6de752 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java @@ -1943,6 +1943,30 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase { assertRefactoringFailure(); } + //main.cpp + //void test() { + // int b[10]; + // /*$*/for (auto a : b) { + // if (a == 5) + // continue; + // }/*$$*/ + //} + //==================== + //void extracted(int b[10]) { + // for (auto a : b) { + // if (a == 5) + // continue; + // } + //} + // + //void test() { + // int b[10]; + // extracted(b); + //} + public void testContinueInsideRangeBasedLoop() throws Exception { + assertRefactoringSuccess(); + } + //Test.cpp //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__) //#define ASSERT(cond) ASSERTM(#cond, cond) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java index 8cfd6feea5c..20ec7501b0c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.utils; @@ -18,7 +18,6 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult; /** * @author Thomas Corbat - * */ public class KeywordCaseTest extends TestCase { @@ -122,6 +121,8 @@ public class KeywordCaseTest extends TestCase { assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); result = IdentifierHelper.checkIdentifierName("typeid"); //$NON-NLS-1$ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); + result = IdentifierHelper.checkIdentifierName("noexcept"); //$NON-NLS-1$ + assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); result = IdentifierHelper.checkIdentifierName("inline"); //$NON-NLS-1$ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); result = IdentifierHelper.checkIdentifierName("compl"); //$NON-NLS-1$ @@ -158,7 +159,5 @@ public class KeywordCaseTest extends TestCase { assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); result = IdentifierHelper.checkIdentifierName("public"); //$NON-NLS-1$ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult()); - } - } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java index 07005b227c0..a61d122a55c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java @@ -47,10 +47,12 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.ui.testplugin.EditorTestHelper; import org.eclipse.cdt.ui.tests.BaseUITestCase; @@ -68,6 +70,7 @@ import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; * @author dsteffle */ public class BaseSelectionTestsIndexer extends BaseUITestCase { + protected static final int INDEXER_TIMEOUT_SEC = 20; protected ICProject fCProject; static FileManager fileManager = new FileManager(); IProgressMonitor monitor = new NullProgressMonitor(); @@ -90,7 +93,11 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase { public void waitForIndex(int maxSec) throws Exception { assertTrue(CCorePlugin.getIndexManager().joinIndexer(maxSec * 1000, new NullProgressMonitor())); } - + + protected void waitUntilFileIsIndexed(IIndex index, IFile file) throws Exception { + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); + } + protected String getMessage(IStatus status) { StringBuffer message = new StringBuffer("["); //$NON-NLS-1$ message.append(status.getMessage()); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 9e307564bd0..436afbe29c1 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -37,8 +37,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * Test Ctrl-F3/F3 with the DOM Indexer for a C++ project. */ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer { - private static final int MAX_WAIT_TIME = 8000; - protected String sourceIndexerID; protected IIndex index; @@ -87,10 +85,6 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde assertEquals(loc.getNodeLength(), name.length()); } - protected void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception { - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); - } - // // header // class Point{ // public: @@ -124,7 +118,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("test93281.h", hcode); IFile file = importFile("test93281.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset = scode.indexOf("p2->operator") + 6; IASTNode node = testF3(file, offset); @@ -166,7 +160,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("test.h", hcode); IFile file = importFile("test.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("testTemplate"); int soffset = scode.indexOf("testTemplate"); @@ -192,7 +186,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("test.h", hcode); IFile file = importFile("test.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("assign"); int soffset = scode.indexOf("assign"); @@ -223,7 +217,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("basicDefinition.h", hcode); IFile file = importFile("testBasicDefinition.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("MyInt"); int soffset = scode.indexOf("MyInt"); @@ -304,7 +298,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBasicTemplateInstance.h", hcode); IFile file = importFile("testBasicTemplateInstance.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("AAA"); int soffset = scode.indexOf("AAA"); @@ -338,7 +332,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug86829A.h", hcode); IFile file = importFile("testBug86829A.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset = scode.indexOf("X(2)"); int doffset= hcode.indexOf("X(int)"); @@ -370,7 +364,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug86829B.h", hcode); IFile file = importFile("testBug86829B.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset = scode.indexOf("X(a)"); int doffset = hcode.indexOf("X()"); @@ -413,7 +407,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode); IFile file = importFile("testCPPSpecDeclsDefs.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset0= hcode.indexOf("a;"); int offset1= scode.indexOf("a;"); @@ -564,7 +558,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug168533.h", hcode); IFile file = importFile("testBug168533.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset0= hcode.indexOf("d;"); int offset1= scode.indexOf("d;"); @@ -600,7 +594,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug95225.h", hcode); IFile file = importFile("testBug95225.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -642,7 +636,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug95202.h", hcode); IFile file = importFile("testBug95202.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -666,7 +660,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug101287.h", hcode); IFile file = importFile("testBug101287.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -692,7 +686,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug102258.h", hcode); IFile file = importFile("testBug102258.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -720,7 +714,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug103323.h", hcode); IFile file = importFile("testBug103323.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -750,7 +744,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug78354.h", hcode); IFile file = importFile("testBug78354.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -781,7 +775,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFileWithLink("testBug103697.h", hcode); IFile file = importFileWithLink("testBug103697.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -808,7 +802,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug108202.h", hcode); IFile file = importFile("testBug108202.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -840,7 +834,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde IFile hcppfile = importFile("cpp.h", hcppcode); IFile cppfile = importFile("cpp.cpp", cppcode); CCorePlugin.getIndexManager().reindex(fCProject); - waitForIndex(MAX_WAIT_TIME); + waitForIndex(INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -875,7 +869,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug190730.h", hcode); IFile file = importFile("testBug190730.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -901,7 +895,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testBug190730_2.h", hcode); IFile file = importFile("testBug190730_2.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -929,7 +923,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("macrodef.h", hcode); IFile file = importFile("macronavi.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -964,7 +958,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("macrodef.h", hcode); IFile file = importFile("macronavi.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -993,7 +987,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testUndef_312399.h", hcode); IFile file = importFile("testUndef_312399.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode target = testF3(file, scode.indexOf("MYMACRO")); assertTrue(target instanceof IASTName); @@ -1011,7 +1005,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("aheader.h", hcode); IFile file = importFile("includenavi.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset0, offset1; @@ -1037,7 +1031,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile cfile = importFile("s.c", ccode); IFile cppfile = importFile("s.cpp", scode); - waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, cppfile); IASTNode decl; int offset1, offset2; @@ -1075,7 +1069,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile cfile = importFile("s.c", ccode); IFile cppfile = importFile("s.cpp", scode); - waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, cppfile); IASTNode decl; int offset1, offset2; @@ -1108,7 +1102,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde StringBuilder[] buffers= getContents(1); String code= buffers[0].toString(); IFile file = importFile("s.cpp", code); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode decl; int offset1, offset2; @@ -1139,7 +1133,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde StringBuilder[] buffers= getContents(1); String code= buffers[0].toString(); IFile file = importFile("in.cpp", code); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset1 = code.indexOf("operator +"); int offset2 = code.indexOf("+ x;"); @@ -1180,7 +1174,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("test.h", hcode); IFile file = importFile("test.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("operator+"); int soffset = scode.indexOf("+"); @@ -1199,7 +1193,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde public void testBug305487() throws Exception { String code = getAboveComment(); IFile file = importFile("testBug305487.cpp", code); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int offset= code.indexOf("test(0)"); IASTNode def = testF3(file, offset + 1); @@ -1226,7 +1220,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("testImplicitConstructorCall_248855.h", hcode); IFile file = importFile("testImplicitConstructorCall_248855.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); IASTNode target = testF3(file, scode.indexOf("a1")); assertTrue(target instanceof IASTName); @@ -1264,7 +1258,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde String scode= buffers[1].toString(); IFile hfile = importFile("test.h", hcode); IFile file = importFile("test.cpp", scode); - waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + waitUntilFileIsIndexed(index, file); int hoffset= hcode.indexOf("func"); int offset = scode.indexOf("func()"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java index 258264e862a..42ebecbc222 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.selection; @@ -33,9 +33,6 @@ import org.eclipse.cdt.ui.testplugin.CTestPlugin; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer { - - private static final int MAX_WAIT_TIME = 8000; - private String sourceIndexerID; private IIndex index; @@ -99,7 +96,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("basicDefinition.h", hcode); IFile file = importFile("testBasicDefinition.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); int hoffset= hcode.indexOf("MyInt"); int soffset = scode.indexOf("MyInt"); @@ -181,7 +178,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode); IFile file = importFile("testCPPSpecDeclsDefs.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); int offset0= hcode.indexOf("a;"); int offset1= scode.indexOf("a;"); @@ -293,7 +290,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("testBug101287.h", hcode); IFile file = importFile("testBug101287.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -317,7 +314,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFileWithLink("testBug103697.h", hcode); IFile file = importFileWithLink("testBug103697.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -345,7 +342,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("testBug78354.h", hcode); IFile file = importFile("testBug78354.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -378,7 +375,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("testBug190730.h", hcode); IFile file = importFile("testBug190730.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -404,7 +401,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("testBug190730_2.h", hcode); IFile file = importFile("testBug190730_2.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -432,7 +429,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("macrodef.h", hcode); IFile file = importFile("macronavi.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -465,7 +462,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("macrodef.h", hcode); IFile file = importFile("macronavi.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -489,7 +486,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("aheader.h", hcode); IFile file = importFile("includenavi.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -509,7 +506,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe String scode= buffers[1].toString(); IFile hfile = importFile("aheader.h", hcode); IFile file = importFile("source.c", scode); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl; int offset0, offset1; @@ -539,7 +536,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe IFile hfile = importFile("aheader.h", hcode); IFile file = importFile("source.c", code); int offset= code.indexOf("myFunc(0)"); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); IASTNode decl= testF3(file, offset); assertTrue(decl instanceof IASTName); @@ -555,8 +552,8 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe IFile file = importFile("source.c", code); int offset= code.indexOf("__LINE__"); - TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME); - // just make sure that no NPE is thrown. + TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000); + // Just make sure that no NPE is thrown. testF3(file, offset); } } diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 5de290067a3..783a6f95038 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2011 IBM Corporation, QNX Software Systems, and others. +# Copyright (c) 2003, 2012 IBM Corporation, QNX Software Systems, 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 @@ -638,3 +638,5 @@ extension-point.name = Refresh Exclusion Contributor # New New Project Wizard newProjectWizard.name = C/C++ Project (prototype) projectTypePages = Project Type Pages + +UserSettingEntries.name = CDT User Setting Entries diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index ec3347b3891..41cc3aa4f15 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4331,7 +4331,7 @@ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java index ecf68a72717..039319a9de5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java @@ -82,7 +82,7 @@ public class CHQueries { if (calleeBinding != null) { findCalledBy1(index, calleeBinding, true, project, result); if (calleeBinding instanceof ICPPMethod) { - IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding); + IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding, null); for (IBinding overriddenBinding : overriddenBindings) { findCalledBy1(index, overriddenBinding, false, project, result); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java index b183769b80a..93f338dbb21 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OverrideIndicatorManager.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2010 Tomasz Wesolowski and others + * Copyright (c) 2010, 2012 Tomasz Wesolowski 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: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -52,13 +53,10 @@ import org.eclipse.cdt.internal.ui.text.ICReconcilingListener; import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; public class OverrideIndicatorManager implements ICReconcilingListener { - static final String ANNOTATION_TYPE = "org.eclipse.cdt.ui.overrideIndicator"; //$NON-NLS-1$ - private static final String MESSAGE_SEPARATOR = ";\n"; //$NON-NLS-1$ public static class OverrideInfo { - public int nodeOffset; public int resultType; public String message; @@ -79,7 +77,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { public static final int RESULT_SHADOWS = 2; public class OverrideIndicator extends Annotation { - public static final String ANNOTATION_TYPE_ID = "org.eclipse.cdt.ui.overrideIndicator"; //$NON-NLS-1$ private int type; private ICElementHandle declaration; @@ -108,9 +105,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { CDTUITools.openInEditor(declaration, true, true); } catch (CoreException e) { } - } - } private IAnnotationModel fAnnotationModel; @@ -123,7 +118,6 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } private void handleResult(OverrideInfo info, IIndex index) { - Position position = new Position(info.nodeOffset, info.nodeLength); OverrideIndicator indicator = new OverrideIndicator(info.resultType, info.message, info.binding, index); @@ -166,7 +160,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } if (binding instanceof ICPPMethod) { method = (ICPPMethod) binding; - OverrideInfo overrideInfo = testForOverride(method, declaration.getFileLocation()); + OverrideInfo overrideInfo = checkForOverride(method, declaration); if (overrideInfo != null) { handleResult(overrideInfo, index); } @@ -209,7 +203,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { return PROCESS_SKIP; } ICPPMethod method = (ICPPMethod) definitionBinding; - OverrideInfo overrideInfo = testForOverride(method, definition.getFileLocation()); + OverrideInfo overrideInfo = checkForOverride(method, definition); if (overrideInfo != null) { handleResult(overrideInfo, index); } @@ -223,9 +217,8 @@ public class OverrideIndicatorManager implements ICReconcilingListener { ast.accept(new MethodDefinitionFinder()); } - public static OverrideInfo testForOverride(ICPPMethod testedOverride, IASTFileLocation location) throws DOMException { - - testedOverride.getClassOwner().getBases(); + private static OverrideInfo checkForOverride(ICPPMethod testedOverride, IASTNode node) throws DOMException { + IASTFileLocation location = node.getFileLocation(); boolean onlyPureVirtual = true; StringBuilder sb = new StringBuilder(); @@ -234,7 +227,7 @@ public class OverrideIndicatorManager implements ICReconcilingListener { Set alreadyTestedBases = new HashSet(); - ICPPBase[] bases = testedOverride.getClassOwner().getBases(); + ICPPBase[] bases = ClassTypeHelper.getBases(testedOverride.getClassOwner(), node); // Don't override 'self' in cyclic inheritance alreadyTestedBases.add(testedOverride.getClassOwner()); @@ -248,10 +241,10 @@ public class OverrideIndicatorManager implements ICReconcilingListener { overridenMethods.clear(); shadowedMethods.clear(); - handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, alreadyTestedBases); + handleBaseClass(testedClass, testedOverride, overridenMethods, shadowedMethods, + alreadyTestedBases, node); for (ICPPMethod overriddenMethod : overridenMethods) { - if (sb.length() > 0) { sb.append(MESSAGE_SEPARATOR); } @@ -296,34 +289,34 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } if (sb.length() > 0) { - OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), markerType, - sb.toString(), bindingToOpen); + OverrideInfo info = new OverrideInfo(location.getNodeOffset(), location.getNodeLength(), + markerType, sb.toString(), bindingToOpen); return info; } return null; - } /** - * If the class directly has a valid override for testedOverride, it is added to foundBindings. Otherwise - * each base class is added to handleBaseClass. + * If the class directly has a valid override for testedOverride, it is added to foundBindings. + * Otherwise each base class is added to handleBaseClass. * * @param shadowedMethods * @param alreadyTestedBases + * @param point * * @throws DOMException */ - private static void handleBaseClass(ICPPClassType aClass, ICPPMethod testedOverride, - Set foundMethods, Set shadowedMethods, Set alreadyTestedBases) throws DOMException { - - if (alreadyTestedBases.contains(aClass)) { + private static void handleBaseClass(ICPPClassType classType, ICPPMethod testedOverride, + Set foundMethods, Set shadowedMethods, + Set alreadyTestedBases, IASTNode point) throws DOMException { + if (alreadyTestedBases.contains(classType)) { return; } else { - alreadyTestedBases.add(aClass); + alreadyTestedBases.add(classType); } Vector validOverrides = new Vector(); - for (ICPPMethod method : aClass.getDeclaredMethods()) { + for (ICPPMethod method : ClassTypeHelper.getDeclaredMethods(classType, point)) { if (testedOverride.getName().equals(method.getName())) { if (ClassTypeHelper.isOverrider(testedOverride, method)) { validOverrides.add(method); @@ -340,12 +333,13 @@ public class OverrideIndicatorManager implements ICReconcilingListener { return; } - for (ICPPBase b : aClass.getBases()) { + for (ICPPBase b : ClassTypeHelper.getBases(classType, point)) { if (!(b.getBaseClass() instanceof ICPPClassType)) { continue; } ICPPClassType baseClass = (ICPPClassType) b.getBaseClass(); - handleBaseClass(baseClass, testedOverride, foundMethods, shadowedMethods, alreadyTestedBases); + handleBaseClass(baseClass, testedOverride, foundMethods, shadowedMethods, + alreadyTestedBases, point); } } @@ -427,5 +421,4 @@ public class OverrideIndicatorManager implements ICReconcilingListener { } return annotationModel; } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 2aba31b03dd..7b1b8a0e8e9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -246,7 +246,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { } private void checkForNonExtractableStatements(NodeContainer container, RefactoringStatus status) { - NonExtractableStmtFinder finder = new NonExtractableStmtFinder(); + NonExtractableStatementFinder finder = new NonExtractableStatementFinder(); for (IASTNode node : container.getNodesToWrite()) { node.accept(finder); if (finder.containsContinue()) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties index 85834ad3ac3..6942af2d249 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties @@ -21,9 +21,9 @@ ExtractFunctionRefactoring_CreateMethodDef=Create Method Definition ExtractFunctionRefactoring_CreateFunctionDef=Create Function Definition ExtractFunctionRefactoring_CreateMethodCall=Create Method Call ExtractFunctionRefactoring_CreateFunctionCall=Create Function Call -ExtractFunctionRefactoring_Error_Return=Extracting return statements is not supported -ExtractFunctionRefactoring_Error_Continue=Extracting continue statements without the surrounding loop is not possible. Please adjust your selection. -ExtractFunctionRefactoring_Error_Break=Extracting break statements without the surrounding loop is not possible. Please adjust your selection. +ExtractFunctionRefactoring_Error_Return=Extracting 'return' statements is not supported +ExtractFunctionRefactoring_Error_Continue=Extracting 'continue' statements without the surrounding loop is not possible. Please adjust your selection. +ExtractFunctionRefactoring_Error_Break=Extracting 'break' statements without the surrounding loop is not possible. Please adjust your selection. ExtractFunctionInputPage_description=Enter new method name and specify the method's visibility ExtractFunctionInputPage_access_modifier=&Access modifier: ExtractFunctionInputPage_public=public diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java similarity index 77% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java index bc4a39c87fa..1d269df71c1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractfunction; @@ -19,11 +20,12 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement; /** * @author Emanuel Graf IFS */ -class NonExtractableStmtFinder extends ASTVisitor{ +class NonExtractableStatementFinder extends ASTVisitor { private boolean containsContinueStmt; private boolean containsBreakStmt; @@ -40,10 +42,11 @@ class NonExtractableStmtFinder extends ASTVisitor{ containsBreakStmt = true; return ASTVisitor.PROCESS_SKIP; } else if (statement instanceof IASTForStatement || + statement instanceof ICPPASTRangeBasedForStatement || statement instanceof IASTWhileStatement || - statement instanceof IASTSwitchStatement || - statement instanceof IASTDoStatement) { - // Extracting a whole loop statement is allowed + statement instanceof IASTDoStatement || + statement instanceof IASTSwitchStatement) { + // Extracting a whole loop or switch statement is allowed. return ASTVisitor.PROCESS_SKIP; } return ASTVisitor.PROCESS_CONTINUE; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java index fa58c0f1e39..2548a03142f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java @@ -31,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; - /** * Rename processor for methods. */ @@ -108,7 +107,7 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; try { - IBinding[] bs= ClassTypeHelper.findOverridden(m); + IBinding[] bs= ClassTypeHelper.findOverridden(m, argument.getTranslationUnit()); bindings.addAll(Arrays.asList(bs)); bs= ClassTypeHelper.findOverriders(getIndex(), m); bindings.addAll(Arrays.asList(bs)); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java index c534bd7ea9d..62296c39645 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchQuery.java @@ -357,7 +357,8 @@ public abstract class CSearchQuery implements ISearchQuery { if (binding instanceof ICPPMethod) { ICPPMethod m= (ICPPMethod) binding; - ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m); + IASTNode point = null; // Instantiation of dependent expressions may not work. + ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m, point); if (msInBases.length > 0) { if (polymorphicNames == null) { polymorphicNames= new ArrayList(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java index 0bbfe23e972..3de9c43fae1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LinkedNamesFinder.java @@ -99,7 +99,7 @@ public class LinkedNamesFinder { } } else if (target instanceof ICPPMethod) { ICPPMethod method= (ICPPMethod) target; - for (ICPPMethod m : ClassTypeHelper.findOverridden(method)) { + for (ICPPMethod m : ClassTypeHelper.findOverridden(method, root)) { findBinding(m); } try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index e225d62efcf..1fdb266723d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -78,6 +79,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; @@ -309,7 +311,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (binding instanceof ICPPClassType) { handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals); } else if (binding instanceof IFunction) { - handleFunction((IFunction)binding, cContext, baseRelevance, proposals); + handleFunction((IFunction) binding, cContext, baseRelevance, proposals); } else if (binding instanceof IVariable) { handleVariable((IVariable) binding, cContext, baseRelevance, proposals); } else if (!cContext.isContextInformationStyle()) { @@ -466,7 +468,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer t= unwindTypedefs(t); if (t instanceof ICPPClassType) { ICPPClassType classType= (ICPPClassType) t; - ICPPConstructor[] constructors = classType.getConstructors(); + IASTTranslationUnit ast = context.getCompletionNode().getTranslationUnit(); + ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, ast); for (ICPPConstructor constructor : constructors) { handleFunction(constructor, context, baseRelevance, proposals); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 528fd655cde..8f8bd310991 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -511,7 +511,7 @@ public class IndexUI { // Check for specializations of the owner IBinding owner = binding.getOwner(); if (owner != null) { - IASTNode point= null; // Instantiation of dependent expression may not work. + IASTNode point= null; // Instantiation of dependent expressions may not work. for (IBinding specOwner : findSpecializations(index, owner)) { if (specOwner instanceof ICPPClassSpecialization) { // Add the specialized member diff --git a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF index 31e74c889b6..b138257a87b 100644 --- a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.debug.core; singleton:=true -Bundle-Version: 7.2.0.qualifier +Bundle-Version: 7.3.0.qualifier Bundle-Activator: org.eclipse.cdt.debug.core.CDebugCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/debug/org.eclipse.cdt.debug.core/pom.xml b/debug/org.eclipse.cdt.debug.core/pom.xml index 3bfb96892a0..c99b93cb60f 100644 --- a/debug/org.eclipse.cdt.debug.core/pom.xml +++ b/debug/org.eclipse.cdt.debug.core/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 7.2.0-SNAPSHOT + 7.3.0-SNAPSHOT org.eclipse.cdt.debug.core eclipse-plugin diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IConnectHandler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IConnectHandler.java new file mode 100644 index 00000000000..3e681e5d09d --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IConnectHandler.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.core.model; + +import org.eclipse.debug.core.commands.IDebugCommandHandler; + +/** + * Handler interface to for the connect command + * + * @since 7.3 + */ +public interface IConnectHandler extends IDebugCommandHandler { +} diff --git a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java index 450ecac149a..0fb1b76ad5c 100644 --- a/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java +++ b/debug/org.eclipse.cdt.debug.ui.tests/core/org/eclipse/cdt/debug/core/tests/AllDebugTests.java @@ -23,14 +23,10 @@ import junit.framework.TestSuite; * @author Judy N. Green * @since Jul 19, 2002 */ -public class AllDebugTests { +public class AllDebugTests extends TestSuite { - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - public static Test suite() { - TestSuite suite = new TestSuite(); + TestSuite suite = new AllDebugTests(); // Just add more test cases here as you create them for // each class being tested @@ -40,8 +36,6 @@ public class AllDebugTests { suite.addTest(LocationTests.suite()); suite.addTest(EventBreakpointTests.suite()); return suite; - - } } // End of AllDebugTests.java diff --git a/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF index e68437be26c..c3c06a0139b 100644 --- a/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true -Bundle-Version: 7.2.0.qualifier +Bundle-Version: 7.3.0.qualifier Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/connect.gif b/debug/org.eclipse.cdt.debug.ui/icons/obj16/connect.gif similarity index 100% rename from dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/icons/full/obj16/connect.gif rename to debug/org.eclipse.cdt.debug.ui/icons/obj16/connect.gif diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index 76acb8514ee..a68c817bb15 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -10,6 +10,7 @@ # IBM Corporation # Patrick Chuong (Texas Instruments) - Pin and Clone Supports (Bug 331781) # Dobrin Alexiev (Texas Instruments) - initial API and implementation (bug 336876) +# Marc Khouzam (Ericsson) - Added support for connect command (Bug 365601) ############################################################################### pluginName=C/C++ Development Tools Debugger UI @@ -200,6 +201,12 @@ Uncall.name = Uncall Uncall.description = Perform Uncall Uncall.label = Uncall +# Connect command +Connect.name = Connect +Connect.description = Connect to a process +Connect.label = Connect... +Connect.tooltip = Connect to a process + # Debug View layout DebugViewLayoutActionSet.label = Debug View Layout DebugViewLayoutCategory.name = Debug View Layout Commands diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index dba67c653a7..d1ae7a9b7c4 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -1990,6 +1990,13 @@ id="org.eclipse.cdt.debug.ui.command.ungroupDebugContexts" name="%UngroupDebugContexts.name"> + + + @@ -2052,6 +2059,10 @@ class="org.eclipse.cdt.debug.internal.ui.commands.UngroupDebugContextsCommandHandler" commandId="org.eclipse.cdt.debug.ui.command.ungroupDebugContexts"> + + @@ -2494,6 +2505,27 @@ + + + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.ui/pom.xml b/debug/org.eclipse.cdt.debug.ui/pom.xml index 64b82cebb62..f23e6501c7d 100644 --- a/debug/org.eclipse.cdt.debug.ui/pom.xml +++ b/debug/org.eclipse.cdt.debug.ui/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 7.2.0-SNAPSHOT + 7.3.0-SNAPSHOT org.eclipse.cdt.debug.ui eclipse-plugin diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ConnectCommandHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ConnectCommandHandler.java new file mode 100644 index 00000000000..7bfbd70b68e --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ConnectCommandHandler.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson 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: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.commands; + +import org.eclipse.cdt.debug.core.model.IConnectHandler; +import org.eclipse.debug.ui.actions.DebugCommandHandler; + +/** + * Command handler to trigger a connect operation + * + * @since 7.3 + */ +public class ConnectCommandHandler extends DebugCommandHandler { + @Override + protected Class getCommandType() { + return IConnectHandler.class; + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java new file mode 100644 index 00000000000..a094d71579e --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view; + +import org.eclipse.osgi.util.NLS; + +/** + * @since 1.0 + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view.messages"; //$NON-NLS-1$ + public static String MulticoreVisualizer_name; + public static String MulticoreVisualizer_tooltip; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java index e2debc25747..f3f7ac3e792 100755 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java @@ -7,6 +7,7 @@ * * Contributors: * William R. Swanson (Tilera Corporation) - initial API and implementation + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view; @@ -187,15 +188,13 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer /** Returns localized name to display for this visualizer. */ @Override public String getDisplayName() { - // TODO: use a string resource here. - return "Multicore Visualizer"; //$NON-NLS-1$ + return Messages.MulticoreVisualizer_name; } /** Returns localized tooltip text to display for this visualizer. */ @Override public String getDescription() { - // TODO: use a string resource here. - return "Displays current state of selected debug target."; //$NON-NLS-1$ + return Messages.MulticoreVisualizer_tooltip; } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/messages.properties new file mode 100644 index 00000000000..80af558c977 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/messages.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 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 +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +MulticoreVisualizer_name=Multicore Visualizer +MulticoreVisualizer_tooltip=Displays current state of selected debug target. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties index 4a343bfaf70..6248385f21a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties @@ -13,9 +13,6 @@ pluginName=GDB DSF Debugger Integration UI providerName=Eclipse CDT -action.connect.label = Connect... -action.connect.tooltip = Connect to a process - gdbPreferencePage.name = GDB launchTab.main.name=Main diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml index 62f27c7673e..b59f15537b5 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml @@ -210,54 +210,6 @@ plugin="org.eclipse.cdt.dsf.gdb.ui"> - - - - - - - - - - - - - - - - - - - - - - - - { +public class ProcessInfo implements IProcessExtendedInfo, Comparable { private final int pid; private final String name; private final String[] cores; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java similarity index 83% rename from dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java rename to dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java index 04ca9d980ee..d90dc5752ac 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/actions/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java @@ -9,16 +9,18 @@ * Ericsson - initial API and implementation * Marc Khouzam (Ericsson) - Add support for multi-attach (Bug 293679) *******************************************************************************/ -package org.eclipse.cdt.dsf.gdb.internal.ui.actions; +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; +import org.eclipse.cdt.debug.core.model.IConnectHandler; import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; @@ -35,8 +37,11 @@ import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.gdb.actions.IConnect; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; +import org.eclipse.cdt.dsf.gdb.internal.ui.actions.ProcessInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.LaunchUIMessages; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter.PrompterInfo; +import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; import org.eclipse.cdt.dsf.gdb.launching.IProcessExtendedInfo; import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages; import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; @@ -45,22 +50,24 @@ import org.eclipse.cdt.dsf.gdb.service.IGDBProcesses.IGdbThreadDMData; import org.eclipse.cdt.dsf.gdb.service.SessionType; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IStatusHandler; +import org.eclipse.debug.core.IRequest; +import org.eclipse.debug.core.commands.AbstractDebugCommand; +import org.eclipse.debug.core.commands.IDebugCommandRequest; +import org.eclipse.debug.core.commands.IEnabledStateRequest; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.progress.UIJob; -public class GdbConnectCommand implements IConnect { +public class GdbConnectCommand extends AbstractDebugCommand implements IConnectHandler, IConnect { private final DsfExecutor fExecutor; private final DsfServicesTracker fTracker; @@ -85,7 +92,19 @@ public class GdbConnectCommand implements IConnect { } @Override - public boolean canConnect() { + protected boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request) + throws CoreException + { + return canConnect(); + } + + /* + * This method should not be called from the UI thread. + * (non-Javadoc) + * @see org.eclipse.cdt.dsf.gdb.actions.IConnect#canConnect() + */ + @Override + public boolean canConnect() { Query canConnectQuery = new Query() { @Override public void execute(DataRequestMonitor rm) { @@ -115,10 +134,10 @@ public class GdbConnectCommand implements IConnect { /** * This job will prompt the user to select a set of processes * to attach too. - * We need a job because prompter.handleStatus will block and + * We need a job because the ProcessPrompter will block and * we don't want to block the executor. */ - protected class PromptForPidJob extends Job { + protected class PromptForPidJob extends UIJob { // The list of processes used in the case of an ATTACH session IProcessExtendedInfo[] fProcessList = null; @@ -133,25 +152,14 @@ public class GdbConnectCommand implements IConnect { } @Override - protected IStatus run(IProgressMonitor monitor) { - IStatus promptStatus = new Status(IStatus.INFO, "org.eclipse.debug.ui", 200/*STATUS_HANDLER_PROMPT*/, "", null); //$NON-NLS-1$//$NON-NLS-2$ - final IStatus processPromptStatus = new Status(IStatus.INFO, "org.eclipse.cdt.dsf.gdb.ui", 100, "", null); //$NON-NLS-1$//$NON-NLS-2$ - - final IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(promptStatus); - + public IStatus runInUIThread(IProgressMonitor monitor) { final Status NO_PID_STATUS = new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, -1, LaunchMessages.getString("LocalAttachLaunchDelegate.No_Process_ID_selected"), //$NON-NLS-1$ null); - if (prompter == null) { - fRequestMonitor.setStatus(NO_PID_STATUS); - fRequestMonitor.done(); - return Status.OK_STATUS; - } - try { PrompterInfo info = new PrompterInfo(fNewProcessSupported, fProcessList); - Object result = prompter.handleStatus(processPromptStatus, info); + Object result = new ProcessPrompter().handleStatus(null, info); if (result == null) { fRequestMonitor.cancel(); } else if (result instanceof IProcessExtendedInfo[] || result instanceof String) { @@ -242,21 +250,34 @@ public class GdbConnectCommand implements IConnect { } @Override - public void connect(RequestMonitor requestMonitor) - { - // Create a fake rm to avoid null pointer exceptions - final RequestMonitor rm; - if (requestMonitor == null) { - rm = new RequestMonitor(fExecutor, null); - } else { - rm = requestMonitor; - } - - // Don't wait for the operation to finish because this - // method can be called from the UI thread, and it will - // block it, which is bad, because we need to use the UI - // thread to prompt the user for the process to choose. - // This is why we simply use a DsfRunnable. + protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException { + Query connectQuery = new Query() { + @Override + public void execute(DataRequestMonitor rm) { + connect(rm); + } + }; + try { + fExecutor.execute(connectQuery); + connectQuery.get(); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } catch (CancellationException e) { + // Nothing to do, just ignore the command since the user + // cancelled it. + } catch (RejectedExecutionException e) { + // Can be thrown if the session is shutdown + } + } + + /* + * This method should not be called from the UI thread. + * (non-Javadoc) + * @see org.eclipse.cdt.dsf.gdb.actions.IConnect#canConnect() + */ + @Override + public void connect(final RequestMonitor rm) + { fExecutor.execute(new DsfRunnable() { @Override public void run() { @@ -265,12 +286,15 @@ public class GdbConnectCommand implements IConnect { if (procService != null && commandControl != null) { final ICommandControlDMContext controlCtx = commandControl.getContext(); - procService.isDebugNewProcessSupported(controlCtx, new DataRequestMonitor(fExecutor, null) { + + // First check if the "New..." button should be enabled. + procService.isDebugNewProcessSupported(controlCtx, new DataRequestMonitor(fExecutor, rm) { @Override protected void handleCompleted() { final boolean newProcessSupported = isSuccess() && getData(); - procService.getRunningProcesses( + // Now get the list of all processes + procService.getRunningProcesses( controlCtx, new DataRequestMonitor(fExecutor, rm) { @Override @@ -282,8 +306,11 @@ public class GdbConnectCommand implements IConnect { new CountingRequestMonitor(fExecutor, rm) { @Override protected void handleSuccess() { + // Prompt the user to choose one or more processes, or to start a new one new PromptForPidJob( - LaunchUIMessages.getString("ProcessPrompter.PromptJob"), newProcessSupported, procInfoList.toArray(new IProcessExtendedInfo[0]), //$NON-NLS-1$ + LaunchUIMessages.getString("ProcessPrompter.PromptJob"), //$NON-NLS-1$ + newProcessSupported, + procInfoList.toArray(new IProcessExtendedInfo[procInfoList.size()]), new DataRequestMonitor(fExecutor, rm) { @Override protected void handleCancel() { @@ -299,8 +326,7 @@ public class GdbConnectCommand implements IConnect { } else if (data instanceof IProcessExtendedInfo[]) { attachToProcesses(controlCtx, (IProcessExtendedInfo[])data, rm); } else { - rm.setStatus(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid return type for process prompter", null)); //$NON-NLS-1$ - rm.done(); + rm.done(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid return type for process prompter", null)); //$NON-NLS-1$ } } }).schedule(); @@ -382,7 +408,7 @@ public class GdbConnectCommand implements IConnect { } private void startNewProcess(ICommandControlDMContext controlDmc, String binaryPath, RequestMonitor rm) { - final IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); + IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); procService.debugNewProcess( controlDmc, binaryPath, new HashMap(), new DataRequestMonitor(fExecutor, rm)); @@ -457,6 +483,8 @@ public class GdbConnectCommand implements IConnect { LaunchUIMessages.getString("ProcessPrompterDialog.TitlePrefix") + process.getName(), //$NON-NLS-1$ processShortName, new AttachToProcessRequestMonitor()).schedule(); } else { + // For a local attach, we can attach directly without looking for the binary + // since GDB will figure it out by itself IProcessDMContext procDmc = procService.createProcessContext(controlDmc, pidStr); procService.attachDebuggerToProcess(procDmc, null, new AttachToProcessRequestMonitor()); } @@ -477,11 +505,24 @@ public class GdbConnectCommand implements IConnect { new AttachToProcessRequestMonitor().done(); } else { - rm.setStatus(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Cannot find service", null)); //$NON-NLS-1$ - rm.done(); + rm.done(new Status(IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Cannot find service", null)); //$NON-NLS-1$ } } + + @Override + protected Object getTarget(Object element) { + if (element instanceof GdbLaunch || + element instanceof IDMVMContext) { + return element; + } + return null; + } + + @Override + protected boolean isRemainEnabled(IDebugCommandRequest request) { + return false; + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java index c356dba0b53..5addf84a8c3 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java @@ -10,6 +10,7 @@ * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Sergey Prigogin (Google) * Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.preferences; @@ -537,17 +538,17 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements final StringFieldEditor stringFieldEditorCommand = new StringFieldEditor( IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND, - "GDB debugger:", //$NON-NLS-1$ + MessagesForPreferences.GdbDebugPreferencePage_GDB_debugger, group1); stringFieldEditorCommand.fillIntoGrid(group1, 2); addField(stringFieldEditorCommand); Button browsebutton = new Button(group1, SWT.PUSH); - browsebutton.setText("&Browse..."); //$NON-NLS-1$ + browsebutton.setText(MessagesForPreferences.GdbDebugPreferencePage_Browse_button); browsebutton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - handleBrowseButtonSelected("GDB Debugger", //$NON-NLS-1$ + handleBrowseButtonSelected(MessagesForPreferences.GdbDebugPreferencePage_GDB_debugger_dialog_title, stringFieldEditorCommand); } }); @@ -555,17 +556,17 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements final StringFieldEditor stringFieldEditorGdbInit = new StringFieldEditor( IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_INIT, - "GDB command file:", //$NON-NLS-1$ + MessagesForPreferences.GdbDebugPreferencePage_GDB_command_file, group1); stringFieldEditorGdbInit.fillIntoGrid(group1, 2); addField(stringFieldEditorGdbInit); browsebutton = new Button(group1, SWT.PUSH); - browsebutton.setText("&Browse..."); //$NON-NLS-1$ + browsebutton.setText(MessagesForPreferences.GdbDebugPreferencePage_Browse_button); browsebutton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - handleBrowseButtonSelected("GDB Command File", //$NON-NLS-1$ + handleBrowseButtonSelected(MessagesForPreferences.GdbDebugPreferencePage_GDB_command_file_dialog_title, stringFieldEditorGdbInit); } }); @@ -574,7 +575,7 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements final StringWithBooleanFieldEditor enableStopAtMain = new StringWithBooleanFieldEditor( IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN, IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN_SYMBOL, - "Stop on startup at:", //$NON-NLS-1$ + MessagesForPreferences.GdbDebugPreferencePage_Stop_on_startup_at, group1); enableStopAtMain.fillIntoGrid(group1, 3); addField(enableStopAtMain); @@ -608,14 +609,14 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements @Override public void widgetSelected(SelectionEvent e) { handleAdvancedButtonSelected( - "GDB Debugger"); //$NON-NLS-1$ + MessagesForPreferences.GdbDebugPreferencePage_GDB_debugger_dialog_title); } }); setButtonLayoutData( fTimeoutAdvancedButton ); final ListenableBooleanFieldEditor enableNonStop= new ListenableBooleanFieldEditor( IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP, - "Non-stop mode (Note: Requires non-stop GDB)", //$NON-NLS-1$ + MessagesForPreferences.GdbDebugPreferencePage_Non_stop_mode, SWT.NONE, group1); enableNonStop.fillIntoGrid(group1, 3); addField(enableNonStop); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java index 8fc656475e9..39f8c012e09 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java @@ -9,6 +9,7 @@ * Ericsson - initial API and implementation * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.preferences; @@ -31,6 +32,7 @@ class MessagesForPreferences extends NLS { /** @since 2.2 */ public static String GdbDebugPreferencePage_maxGdbTraces_label; public static String GdbDebugPreferencePage_autoTerminateGdb_label; + public static String GdbDebugPreferencePage_Browse_button; public static String GdbDebugPreferencePage_Command_column_name; public static String GdbDebugPreferencePage_Command_field_can_not_be_empty; public static String GdbDebugPreferencePage_Command_timeout; @@ -48,11 +50,17 @@ class MessagesForPreferences extends NLS { /** @since 2.2 */ public static String GdbDebugPreferencePage_defaults_label; public static String GdbDebugPreferencePage_Delete_button; + public static String GdbDebugPreferencePage_GDB_command_file; + public static String GdbDebugPreferencePage_GDB_command_file_dialog_title; + public static String GdbDebugPreferencePage_GDB_debugger; + public static String GdbDebugPreferencePage_GDB_debugger_dialog_title; public static String GdbDebugPreferencePage_Invalid_timeout_value; + public static String GdbDebugPreferencePage_Non_stop_mode; public static String GdbDebugPreferencePage_Timeout_column_name; public static String GdbDebugPreferencePage_Timeout_value_can_not_be_negative; /** @since 2.3 */ public static String GdbDebugPreferencePage_rtti_label; + public static String GdbDebugPreferencePage_Stop_on_startup_at; /** @since 2.3 */ public static String GdbDebugPreferencePage_use_rtti_label1; /** @since 2.3 */ diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties index fb85bc6c3bc..b9d448bab57 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties @@ -9,6 +9,7 @@ # Ericsson - initial API and implementation # Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) # Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) +# IBM Corporation ############################################################################### GdbDebugPreferencePage_Add_button=Add @@ -47,3 +48,10 @@ GdbDebugPreferencePage_Advanced_timeout_dialog_title=Add/delete/modify custom ti GdbDebugPreferencePage_Advanced_timeout_settings_dialog_tooltip=Specify commands and corresponding timeout values, use zero for "no timeout".\nMI commands must start with hyphen ('-'). For example, '-target-select'.\nThe default value will be used for all commands that are not mentioned here. GdbDebugPreferencePage_Advanced_Timeout_Settings=Advanced Timeout Settings +GdbDebugPreferencePage_Browse_button=&Browse... +GdbDebugPreferencePage_GDB_command_file=GDB command file: +GdbDebugPreferencePage_GDB_command_file_dialog_title=GDB Command File +GdbDebugPreferencePage_GDB_debugger=GDB debugger: +GdbDebugPreferencePage_GDB_debugger_dialog_title=GDB Debugger +GdbDebugPreferencePage_Non_stop_mode=Non-stop mode (Note: Requires non-stop GDB) +GdbDebugPreferencePage_Stop_on_startup_at=Stop on startup at: diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java index 42b82306dd2..8e897d248f8 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java @@ -22,6 +22,7 @@ import java.util.Map; import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.model.IConnectHandler; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; @@ -520,9 +521,9 @@ public class FinalLaunchSequence extends ReflectionSequence { fProcService.createProcessContext(fCommandControl.getContext(), Integer.toString(pid)), new DataRequestMonitor(getExecutor(), requestMonitor)); } else { - IConnect connectCommand = (IConnect)fSession.getModelAdapter(IConnect.class); - if (connectCommand != null) { - connectCommand.connect(requestMonitor); + IConnectHandler connectCommand = (IConnectHandler)fSession.getModelAdapter(IConnectHandler.class); + if (connectCommand instanceof IConnect) { + ((IConnect)connectCommand).connect(requestMonitor); } else { requestMonitor.done(); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java index 6fa04beb738..87c79a79e94 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java @@ -18,6 +18,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; +import org.eclipse.cdt.debug.core.model.IConnectHandler; import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; @@ -289,7 +290,12 @@ public class GdbLaunch extends DsfLaunch // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=377447. if (adapter.equals(ITerminateHandler.class)) return getSession().getModelAdapter(adapter); - // Must force adapters to be loaded. + + // Allow to call the connect handler when the launch is selected + if (adapter.equals(IConnectHandler.class)) + return getSession().getModelAdapter(adapter); + + // Must force adapters to be loaded. Platform.getAdapterManager().loadAdapter(this, adapter.getName()); return super.getAdapter(adapter); } diff --git a/dsf/org.eclipse.cdt.dsf.ui/plugin.properties b/dsf/org.eclipse.cdt.dsf.ui/plugin.properties index 996feae9d4d..beddd33412d 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/plugin.properties +++ b/dsf/org.eclipse.cdt.dsf.ui/plugin.properties @@ -54,6 +54,8 @@ popup.resumeAtLine.label=Resume At Li&ne popup.moveToLine.label=&Move To Line popup.runToLine.label=Run To &Line +command.refreshAll.name=Refresh Debug Views +command.refreshAll.description=Refresh all data in debug views # Preferences diff --git a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml index c745ce4544d..bfa8abf7798 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml +++ b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml @@ -672,6 +672,14 @@ + + + + diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java index ba3b733c1f1..33ee22a6df5 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionVMProvider.java @@ -430,7 +430,6 @@ public class ExpressionVMProvider extends AbstractDMVMProvider if (input instanceof IExpressionDMContext) { IExpressionDMContext dmc = (IExpressionDMContext) input; SingleExpressionVMNode vmNode = (SingleExpressionVMNode) getChildVMNodes(getRootVMNode())[0]; - vmNode.setExpression(dmc); final IDMVMContext viewerInput= vmNode.createVMContext(dmc); // provide access to viewer (needed by details pane) diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/SingleExpressionVMNode.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/SingleExpressionVMNode.java index a511fbeb7ab..0670698dbe6 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/SingleExpressionVMNode.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/SingleExpressionVMNode.java @@ -15,14 +15,10 @@ import java.util.LinkedList; import java.util.List; import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; -import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; -import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionVMProvider; -import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionsChangedEvent; -import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.InvalidExpressionVMContext; -import org.eclipse.cdt.dsf.ui.concurrent.ViewerCountingRequestMonitor; +import org.eclipse.cdt.dsf.ui.concurrent.ViewerDataRequestMonitor; import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMContext; import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMNode; import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode; @@ -38,6 +34,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProv import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; import org.eclipse.jface.viewers.TreePath; /** @@ -90,6 +87,10 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa return getVMNode().hashCode() + fDmc.hashCode(); } + @Override + public String toString() { + return fDmc.toString(); + } } private static class SimpleExpression implements IExpression { @@ -141,27 +142,8 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa } } - private static class SingleExpressionManager { - private static final IExpression[] NO_EXPRESSIONS = {}; - IExpression fExpression; - public IExpression[] getExpressions() { - if (fExpression != null) { - return new IExpression[] { fExpression }; - } - return NO_EXPRESSIONS; - } - public void setExpression(IExpression expression) { - fExpression = expression; - } - - } - - /** Local reference to the expression manager */ - private final SingleExpressionManager fManager; - public SingleExpressionVMNode(ExpressionVMProvider provider) { super(provider); - fManager = new SingleExpressionManager(); } @Override @@ -173,14 +155,21 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa return (ExpressionVMProvider)getVMProvider(); } + private IExpressionDMContext getUpdateExpressionDMC(IViewerUpdate update) { + if (update.getElement() instanceof IDMVMContext) { + IDMContext dmc = ((IDMVMContext)update.getElement()).getDMContext(); + if (dmc instanceof IExpressionDMContext) { + return (IExpressionDMContext)dmc; + } + } + return null; + } + + @Override public void update(IHasChildrenUpdate[] updates) { - // Test availability of children based on whether there are any expressions - // in the manager. We assume that the getExpressions() will just read - // local state data, so we don't bother using a job to perform this - // operation. for (int i = 0; i < updates.length; i++) { - updates[i].setHasChilren(fManager.getExpressions().length != 0); + updates[i].setHasChilren(getUpdateExpressionDMC(updates[i]) != null); updates[i].done(); } } @@ -192,7 +181,7 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa // We assume that the getExpressions() will just read local state data, // so we don't bother using a job to perform this operation. - update.setChildCount(fManager.getExpressions().length); + update.setChildCount(getUpdateExpressionDMC(update) != null ? 1 : 0); update.done(); } } @@ -200,62 +189,38 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa @Override public void update(final IChildrenUpdate[] updates) { for (IChildrenUpdate update : updates) { - doUpdateChildren(update); + IExpressionDMContext dmc = getUpdateExpressionDMC(update); + if (dmc != null) { + doUpdateChildren(update, new SimpleExpression(dmc.getExpression())); + } + else { + handleFailedUpdate(update); + } } } - public void doUpdateChildren(final IChildrenUpdate update) { - final IExpression[] expressions = fManager.getExpressions(); - - // For each (expression) element in update, find the layout node that can - // parse it. And for each expression that has a corresponding layout node, - // call IExpressionLayoutNode#getElementForExpression to generate a VMC. - // Since the last is an async call, we need to create a multi-RM to wait - // for all the calls to complete. - final CountingRequestMonitor multiRm = new ViewerCountingRequestMonitor(getVMProvider().getExecutor(), update); - int multiRmCount = 0; - - int lowOffset= update.getOffset(); - if (lowOffset < 0) { - lowOffset = 0; - } - int length= update.getLength(); - if (length <= 0) { - length = expressions.length; - } - final int highOffset= lowOffset + length; - for (int i = lowOffset; i < highOffset && i < expressions.length + 1; i++) { - if (i < expressions.length) { - multiRmCount++; - final int childIndex = i; - final IExpression expression = expressions[i]; - // getElementForExpression() accepts a IElementsUpdate as an argument. - // Construct an instance of VMElementsUpdate which will call a - // the request monitor when it is finished. The request monitor - // will in turn set the element in the update argument in this method. - ((ExpressionVMProvider)getVMProvider()).update( - new VMExpressionUpdate( - update, expression, - new DataRequestMonitor(getVMProvider().getExecutor(), multiRm) { - @Override - protected void handleSuccess() { - update.setChild(getData(), childIndex); - multiRm.done(); - } - - @Override - protected void handleError() { - update.setChild(new InvalidExpressionVMContext(SingleExpressionVMNode.this, expression), childIndex); - multiRm.done(); - } - }) - ); - } - } - - // If no expressions were parsed, we're finished. - // Set the count to the counting RM. - multiRm.setDoneCount(multiRmCount); + public void doUpdateChildren(final IChildrenUpdate update, final IExpression expression) { + // getElementForExpression() accepts a IElementsUpdate as an argument. + // Construct an instance of VMElementsUpdate which will call a + // the request monitor when it is finished. The request monitor + // will in turn set the element in the update argument in this method. + ((ExpressionVMProvider)getVMProvider()).update( + new VMExpressionUpdate( + update, expression, + new ViewerDataRequestMonitor(getVMProvider().getExecutor(), update) { + @Override + protected void handleSuccess() { + update.setChild(getData(), 0); + update.done(); + } + + @Override + protected void handleError() { + update.setChild(new InvalidExpressionVMContext(SingleExpressionVMNode.this, expression), 0); + update.done(); + } + }) + ); } @Override @@ -267,7 +232,7 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa update.done(); } } - + @Override public int getDeltaFlags(Object event) { int retVal = 0; @@ -277,40 +242,47 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa retVal |= IModelDelta.ADDED | IModelDelta.REMOVED | IModelDelta.INSERTED | IModelDelta.CONTENT ; } - for (IExpression expression : fManager.getExpressions()) { - retVal |= getExpressionVMProvider().getDeltaFlagsForExpression(expression, event); + // The expression in the hover is not known here, so assume that all + // expression nodes need to provide delta flags for event. Iterate + // through them here and collect the flags. + for (IExpressionVMNode node : getExpressionVMProvider().getExpressionNodes()) { + retVal |= getDeltaFlagsForNode(node, event); } return retVal; } + private int getDeltaFlagsForNode(IVMNode node, Object event) { + int retVal = node.getDeltaFlags(event); + for (IVMNode child : getVMProvider().getChildVMNodes(node)) { + if (!node.equals(child)) { + retVal |= getDeltaFlagsForNode(child, event); + } + } + return retVal; + } + @Override public void buildDelta(final Object event, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) { if (event instanceof ExpressionsChangedEvent) { buildDeltaForExpressionsChangedEvent((ExpressionsChangedEvent)event, parentDelta, nodeOffset, requestMonitor); } else { - - // For each expression, find its corresponding node and ask that - // layout node for its delta flags for given event. If there are delta flags to be - // generated, call the asynchronous method to do so. - CountingRequestMonitor multiRm = new CountingRequestMonitor(getExecutor(), requestMonitor); - - int buildDeltaForExpressionCallCount = 0; - - IExpression[] expressions = fManager.getExpressions(); - for (int i = 0; i < expressions.length; i++ ) { - int flags = getExpressionVMProvider().getDeltaFlagsForExpression(expressions[i], event); - // If the given expression has no delta flags, skip it. - if (flags == IModelDelta.NO_CHANGE) continue; - - int elementOffset = nodeOffset >= 0 ? nodeOffset + i : -1; - getExpressionVMProvider().buildDeltaForExpression( - expressions[i], elementOffset, event, parentDelta, getTreePathFromDelta(parentDelta), - new RequestMonitor(getExecutor(), multiRm)); - buildDeltaForExpressionCallCount++; + Object parent = parentDelta.getElement(); + if (parent instanceof IDMVMContext) { + IDMContext dmc = ((IDMVMContext)parent).getDMContext(); + if (dmc instanceof IExpressionDMContext) { + IExpression expression = new SimpleExpression( ((IExpressionDMContext)dmc).getExpression() ); + int flags = getExpressionVMProvider().getDeltaFlagsForExpression(expression, event); + // If the given expression has no delta flags, skip it. + if (flags != IModelDelta.NO_CHANGE) { + getExpressionVMProvider().buildDeltaForExpression( + expression, nodeOffset, event, parentDelta, getTreePathFromDelta(parentDelta), + requestMonitor); + return; + } + } } - - multiRm.setDoneCount(buildDeltaForExpressionCallCount); + requestMonitor.done(); } } @@ -340,16 +312,8 @@ public class SingleExpressionVMNode extends AbstractVMNode implements IElementLa return new TreePath(elementList.toArray()); } - protected void updateElementsInSessionThread(IChildrenUpdate update) { - doUpdateChildren(update); - } - public IDMVMContext createVMContext(IDMContext dmc) { return new RootDMVMContext(getVMProvider().getRootVMNode(), dmc); } - public void setExpression(IExpressionDMContext dmc) { - String text = dmc.getExpression(); - fManager.setExpression(new SimpleExpression(text)); - } } diff --git a/testsrunner/org.eclipse.cdt.testsrunner.test/META-INF/MANIFEST.MF b/testsrunner/org.eclipse.cdt.testsrunner.test/META-INF/MANIFEST.MF index 8753f5de416..9ec870acded 100644 --- a/testsrunner/org.eclipse.cdt.testsrunner.test/META-INF/MANIFEST.MF +++ b/testsrunner/org.eclipse.cdt.testsrunner.test/META-INF/MANIFEST.MF @@ -14,3 +14,6 @@ Require-Bundle: org.junit, Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: %Bundle-Vendor +Export-Package: org.eclipse.cdt.testsrunner.core, + org.eclipse.cdt.testsrunner.test, + org.eclipse.cdt.testsrunner.testsrunners diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/META-INF/MANIFEST.MF b/upc/org.eclipse.cdt.core.parser.upc.tests/META-INF/MANIFEST.MF index 50fb978bbb2..f7bfba09f93 100644 --- a/upc/org.eclipse.cdt.core.parser.upc.tests/META-INF/MANIFEST.MF +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/META-INF/MANIFEST.MF @@ -14,3 +14,4 @@ Require-Bundle: org.eclipse.core.runtime, Bundle-Vendor: %Bundle-Vendor.0 Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Export-Package: org.eclipse.cdt.core.parser.upc.tests diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/META-INF/MANIFEST.MF b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/META-INF/MANIFEST.MF index 26486547076..0ab0aa05d22 100644 --- a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/META-INF/MANIFEST.MF +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/META-INF/MANIFEST.MF @@ -12,3 +12,6 @@ Require-Bundle: org.junit, org.eclipse.cdt.core.lrparser.tests;bundle-version="5.1.0", org.eclipse.core.runtime;bundle-version="3.5.0", org.eclipse.core.resources;bundle-version="3.5.0" +Export-Package: org.eclipse.cdt.core.parser.xlc.tests, + org.eclipse.cdt.core.parser.xlc.tests.base, + org.eclipse.cdt.core.parser.xlc.tests.suite