mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
[273283] [XLC Parser] support _Complex and restrict keywords in C++
This commit is contained in:
parent
91657617cb
commit
6262b1fe81
18 changed files with 3579 additions and 3341 deletions
|
@ -964,10 +964,14 @@ elaborated_specifier_hook
|
|||
-- ::= identifier_token
|
||||
|
||||
|
||||
comma_opt
|
||||
::= ',' | $empty
|
||||
|
||||
|
||||
enum_specifier
|
||||
::= 'enum' enum_specifier_hook '{' <openscope-ast> enumerator_list_opt '}'
|
||||
::= 'enum' enum_specifier_hook '{' <openscope-ast> enumerator_list_opt comma_opt '}'
|
||||
/. $Build consumeTypeSpecifierEnumeration(false); $EndBuild ./
|
||||
| 'enum' enum_specifier_hook identifier_token '{' <openscope-ast> enumerator_list_opt '}'
|
||||
| 'enum' enum_specifier_hook identifier_token '{' <openscope-ast> enumerator_list_opt comma_opt '}'
|
||||
/. $Build consumeTypeSpecifierEnumeration(true); $EndBuild ./
|
||||
|
||||
enum_specifier_hook
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.xlc.tests;
|
||||
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPref;
|
||||
|
||||
|
||||
public class XLCExtensionsTest extends XLCTestBase {
|
||||
|
||||
|
@ -218,11 +221,18 @@ public class XLCExtensionsTest extends XLCTestBase {
|
|||
|
||||
parse(code, getCLanguage(), true);
|
||||
}
|
||||
public void testRestrictCPP() {
|
||||
|
||||
public void testRestrictCPPOn() {
|
||||
String code =
|
||||
"void foo(int n, int * restrict a, int * __restrict b, int * __restrict__ c) {} ";
|
||||
|
||||
parse(code, getCPPLanguage(), true);
|
||||
}
|
||||
public void testRestrictCPPOff() {
|
||||
XlcLanguagePreferences.setWorkspacePreference(XlcPref.SUPPORT_RESTRICT_IN_CPP, String.valueOf(false));
|
||||
String code =
|
||||
"void restrict(); \n " +
|
||||
"void __restrict(); \n " +
|
||||
"void __restrict__(); \n ";
|
||||
"void foo(int n, int * __restrict b, int * __restrict__ c) {} ";
|
||||
|
||||
parse(code, getCPPLanguage(), true);
|
||||
}
|
||||
|
@ -244,7 +254,7 @@ public class XLCExtensionsTest extends XLCTestBase {
|
|||
}
|
||||
|
||||
|
||||
public void testFloatingPoingTypes() {
|
||||
public void testFloatingPointTypes() {
|
||||
String code =
|
||||
" _Decimal32 x = 22.2df; \n " +
|
||||
" _Decimal64 y = 33.3dd; \n " +
|
||||
|
|
|
@ -38,12 +38,29 @@ $Define
|
|||
|
||||
$End
|
||||
|
||||
|
||||
|
||||
$Terminals
|
||||
|
||||
_Complex
|
||||
restrict
|
||||
|
||||
$End
|
||||
|
||||
|
||||
$Start
|
||||
translation_unit
|
||||
$End
|
||||
|
||||
|
||||
$Rules
|
||||
|
||||
simple_type_specifier_token
|
||||
::= '_Complex'
|
||||
|
||||
cv_qualifier
|
||||
::= 'restrict'
|
||||
|
||||
block_declaration
|
||||
::= vector_declaration
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.lrparser.xlc;
|
||||
|
||||
import static org.eclipse.cdt.core.lrparser.xlc.XlcCPPLanguage.getPref;
|
||||
import static org.eclipse.cdt.core.lrparser.xlc.XlcCPPLanguage.getProject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -17,8 +20,7 @@ import org.eclipse.cdt.core.dom.lrparser.IParser;
|
|||
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPreferenceKeys;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPref;
|
||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParser;
|
||||
|
@ -40,9 +42,9 @@ public class XlcCLanguage extends GCCLanguage {
|
|||
|
||||
@Override
|
||||
protected IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties) {
|
||||
IProject project = XlcCPPLanguage.getProject(properties);
|
||||
boolean supportVectors = Boolean.valueOf(XlcLanguagePreferences.get(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, project));
|
||||
boolean supportDecimals = Boolean.valueOf(XlcLanguagePreferences.get(XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES, project));
|
||||
IProject project = getProject(properties);
|
||||
boolean supportVectors = getPref(XlcPref.SUPPORT_VECTOR_TYPES, project);
|
||||
boolean supportDecimals = getPref(XlcPref.SUPPORT_DECIMAL_FLOATING_POINT_TYPES, project);
|
||||
|
||||
return new XlcCParser(scanner, new XlcCTokenMap(supportVectors, supportDecimals), getBuiltinBindingsProvider(), index, properties);
|
||||
}
|
||||
|
|
|
@ -13,13 +13,14 @@ package org.eclipse.cdt.core.lrparser.xlc;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
|
||||
import org.eclipse.cdt.core.dom.lrparser.IParser;
|
||||
import org.eclipse.cdt.core.dom.lrparser.LRParserProperties;
|
||||
import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPreferenceKeys;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPref;
|
||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParser;
|
||||
|
@ -57,17 +58,25 @@ public class XlcCPPLanguage extends GPPLanguage {
|
|||
}
|
||||
|
||||
|
||||
static boolean getPref(XlcPref key, IProject project) {
|
||||
return Boolean.valueOf(XlcLanguagePreferences.get(key, project));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties) {
|
||||
IProject project = getProject(properties);
|
||||
boolean supportVectors = Boolean.valueOf(XlcLanguagePreferences.get(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, project));
|
||||
boolean supportDecimals = Boolean.valueOf(XlcLanguagePreferences.get(XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES, project));
|
||||
boolean supportVectors = getPref(XlcPref.SUPPORT_VECTOR_TYPES, project);
|
||||
boolean supportDecimals = getPref(XlcPref.SUPPORT_DECIMAL_FLOATING_POINT_TYPES, project);
|
||||
boolean supportComplex = getPref(XlcPref.SUPPORT_COMPLEX_IN_CPP, project);
|
||||
boolean supportRestrict = getPref(XlcPref.SUPPORT_RESTRICT_IN_CPP, project);
|
||||
IDOMTokenMap tokenMap = new XlcCPPTokenMap(supportVectors, supportDecimals, supportComplex, supportRestrict);
|
||||
|
||||
|
||||
XlcCPPParser parser = new XlcCPPParser(scanner, new XlcCPPTokenMap(supportVectors, supportDecimals), getBuiltinBindingsProvider(), index, properties);
|
||||
XlcCPPParser parser = new XlcCPPParser(scanner, tokenMap, getBuiltinBindingsProvider(), index, properties);
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import static org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym.*;
|
|||
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
* Maps tokens types returned by CPreprocessor to token types
|
||||
|
@ -28,8 +27,8 @@ public class XlcCPPTokenMap implements IDOMTokenMap {
|
|||
|
||||
private final XlcKeywords keywordMap;
|
||||
|
||||
public XlcCPPTokenMap(boolean supportVectors, boolean supportDecimalFloatingPoint) {
|
||||
keywordMap = new XlcKeywords(ParserLanguage.CPP, supportVectors, supportDecimalFloatingPoint);
|
||||
public XlcCPPTokenMap(boolean supportVectors, boolean supportDecimalFloatingPoint, boolean supportComplex, boolean supportRestrict) {
|
||||
keywordMap = XlcKeywords.createCPP(supportVectors, supportDecimalFloatingPoint, supportComplex, supportRestrict);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import static org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParsersym.*;
|
|||
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
* Maps tokens types returned by CPreprocessor to token types
|
||||
|
@ -29,7 +28,7 @@ public final class XlcCTokenMap implements IDOMTokenMap {
|
|||
private final XlcKeywords keywordMap;
|
||||
|
||||
public XlcCTokenMap(boolean supportVectors, boolean supportDecimalFloatingPoint) {
|
||||
keywordMap = new XlcKeywords(ParserLanguage.C, supportVectors, supportDecimalFloatingPoint);
|
||||
keywordMap = XlcKeywords.createC(supportVectors, supportDecimalFloatingPoint);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,46 +23,63 @@ import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym;
|
|||
|
||||
public class XlcKeywords extends CLanguageKeywords {
|
||||
|
||||
public static final XlcKeywords ALL_C_KEYWORDS = new XlcKeywords(ParserLanguage.C, true, true);
|
||||
public static final XlcKeywords ALL_CPP_KEYWORDS = new XlcKeywords(ParserLanguage.CPP, true, true);
|
||||
public static final XlcKeywords ALL_C_KEYWORDS = createC(true, true);
|
||||
public static final XlcKeywords ALL_CPP_KEYWORDS = createCPP(true, true, true, true);
|
||||
|
||||
|
||||
private final CharArrayMap<Integer> map = new CharArrayMap<Integer>();
|
||||
private final ParserLanguage language;
|
||||
private String[] allKeywords = null;
|
||||
|
||||
public XlcKeywords(ParserLanguage language, boolean supportVectors, boolean supportDeclimalFloatingPoint) {
|
||||
|
||||
public static XlcKeywords createC(boolean supportVectors, boolean supportDecimalFloatingPoint) {
|
||||
XlcKeywords keywords = new XlcKeywords(ParserLanguage.C);
|
||||
CharArrayMap<Integer> map = keywords.map;
|
||||
if(supportVectors) {
|
||||
map.put("vector".toCharArray(), XlcCParsersym.TK_vector);
|
||||
map.put("__vector".toCharArray(), XlcCParsersym.TK_vector);
|
||||
map.put("pixel".toCharArray(), XlcCParsersym.TK_pixel);
|
||||
map.put("__pixel".toCharArray(), XlcCParsersym.TK_pixel);
|
||||
map.put("bool".toCharArray(), XlcCParsersym.TK_bool);
|
||||
}
|
||||
if(supportDecimalFloatingPoint) {
|
||||
map.put("_Decimal32".toCharArray(), XlcCParsersym.TK__Decimal32);
|
||||
map.put("_Decimal64".toCharArray(), XlcCParsersym.TK__Decimal64);
|
||||
map.put("_Decimal128".toCharArray(), XlcCParsersym.TK__Decimal128);
|
||||
}
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public static XlcKeywords createCPP(boolean supportVectors, boolean supportDecimalFloatingPoint, boolean supportComplex, boolean supportRestrict) {
|
||||
XlcKeywords keywords = new XlcKeywords(ParserLanguage.CPP);
|
||||
CharArrayMap<Integer> map = keywords.map;
|
||||
if(supportVectors) {
|
||||
map.put("vector".toCharArray(), XlcCPPParsersym.TK_vector);
|
||||
map.put("__vector".toCharArray(), XlcCPPParsersym.TK_vector);
|
||||
map.put("pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
|
||||
map.put("__pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
|
||||
}
|
||||
if(supportDecimalFloatingPoint) {
|
||||
map.put("_Decimal32".toCharArray(), XlcCPPParsersym.TK__Decimal32);
|
||||
map.put("_Decimal64".toCharArray(), XlcCPPParsersym.TK__Decimal64);
|
||||
map.put("_Decimal128".toCharArray(), XlcCPPParsersym.TK__Decimal128);
|
||||
}
|
||||
if(supportComplex) {
|
||||
map.put("_Complex".toCharArray(), XlcCPPParsersym.TK__Complex);
|
||||
}
|
||||
if(supportRestrict) {
|
||||
map.put("restrict".toCharArray(), XlcCPPParsersym.TK_restrict);
|
||||
map.put("__restrict".toCharArray(), XlcCPPParsersym.TK_restrict);
|
||||
map.put("__restrict__".toCharArray(), XlcCPPParsersym.TK_restrict);
|
||||
}
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
|
||||
private XlcKeywords(ParserLanguage language) {
|
||||
super(language, XlcScannerExtensionConfiguration.getInstance());
|
||||
this.language = language;
|
||||
|
||||
if(language.isCPP()) {
|
||||
if(supportVectors) {
|
||||
map.put("vector".toCharArray(), XlcCPPParsersym.TK_vector);
|
||||
map.put("__vector".toCharArray(), XlcCPPParsersym.TK_vector);
|
||||
map.put("pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
|
||||
map.put("__pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
|
||||
}
|
||||
if(supportDeclimalFloatingPoint) {
|
||||
map.put("_Decimal32".toCharArray(), XlcCPPParsersym.TK__Decimal32);
|
||||
map.put("_Decimal64".toCharArray(), XlcCPPParsersym.TK__Decimal64);
|
||||
map.put("_Decimal128".toCharArray(), XlcCPPParsersym.TK__Decimal128);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(supportVectors) {
|
||||
map.put("vector".toCharArray(), XlcCParsersym.TK_vector);
|
||||
map.put("__vector".toCharArray(), XlcCParsersym.TK_vector);
|
||||
map.put("pixel".toCharArray(), XlcCParsersym.TK_pixel);
|
||||
map.put("__pixel".toCharArray(), XlcCParsersym.TK_pixel);
|
||||
map.put("bool".toCharArray(), XlcCParsersym.TK_bool);
|
||||
}
|
||||
if(supportDeclimalFloatingPoint) {
|
||||
map.put("_Decimal32".toCharArray(), XlcCParsersym.TK__Decimal32);
|
||||
map.put("_Decimal64".toCharArray(), XlcCParsersym.TK__Decimal64);
|
||||
map.put("_Decimal128".toCharArray(), XlcCParsersym.TK__Decimal128);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,4 +30,8 @@ public class XlcScannerExtensionConfiguration extends GCCScannerExtensionConfigu
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] supportAdditionalNumericLiteralSuffixes() {
|
||||
return "dfl".toCharArray(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,47 +31,48 @@ public class XlcLanguagePreferences {
|
|||
|
||||
|
||||
static void initializeDefaultPreferences() {
|
||||
Preferences prefs = getDefaultPreferences();
|
||||
prefs.putBoolean(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, true);
|
||||
prefs.putBoolean(XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES, true);
|
||||
}
|
||||
|
||||
public static void setProjectPreference(String key, String value, IProject project) {
|
||||
getProjectPreferences(project).put(key, value);
|
||||
Preferences defaultNode = getDefaultPreferences();
|
||||
|
||||
for(XlcPref p : XlcPref.values()) {
|
||||
defaultNode.put(p.toString(), p.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setWorkspacePreference(String key, String value) {
|
||||
getWorkspacePreferences().put(key, value);
|
||||
|
||||
public static void setProjectPreference(XlcPref key, String value, IProject project) {
|
||||
getProjectPreferences(project).put(key.toString(), value);
|
||||
}
|
||||
|
||||
public static void setWorkspacePreference(XlcPref key, String value) {
|
||||
getWorkspacePreferences().put(key.toString(), value);
|
||||
}
|
||||
|
||||
|
||||
public static String getProjectPreference(String key, IProject project) {
|
||||
return getProjectPreferences(project).get(key, null);
|
||||
}
|
||||
|
||||
public static String getProjectPreference(XlcPref key, IProject project) {
|
||||
return getProjectPreferences(project).get(key.toString(), null);
|
||||
}
|
||||
|
||||
public static String getWorkspacePreference(String key) {
|
||||
return getWorkspacePreferences().get(key, null);
|
||||
public static String getWorkspacePreference(XlcPref key) {
|
||||
return getWorkspacePreferences().get(key.toString(), null);
|
||||
}
|
||||
|
||||
public static String getDefaultPreference(String key) {
|
||||
return getDefaultPreferences().get(key, null);
|
||||
public static String getDefaultPreference(XlcPref key) {
|
||||
return getDefaultPreferences().get(key.toString(), null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the preference for the given key.
|
||||
*
|
||||
* @param project If null then just the workspace and default preferences will be checked.
|
||||
*/
|
||||
public static String get(String key, IProject project) {
|
||||
return Platform.getPreferencesService().get(key, null, getPreferences(key, project));
|
||||
public static String get(XlcPref key, IProject project) {
|
||||
return Platform.getPreferencesService().get(key.toString(), null, getPreferences(project));
|
||||
}
|
||||
|
||||
private static Preferences[] getPreferences(String key, IProject project) {
|
||||
private static Preferences[] getPreferences(IProject project) {
|
||||
if(project == null) {
|
||||
return new Preferences[] {
|
||||
getWorkspacePreferences(),
|
||||
|
|
|
@ -11,12 +11,25 @@
|
|||
package org.eclipse.cdt.core.lrparser.xlc.preferences;
|
||||
|
||||
|
||||
public final class XlcPreferenceKeys {
|
||||
public enum XlcPref {
|
||||
|
||||
private XlcPreferenceKeys() {}
|
||||
|
||||
public static final String KEY_SUPPORT_VECTOR_TYPES = "vectorTypes";
|
||||
SUPPORT_VECTOR_TYPES("true"),
|
||||
SUPPORT_DECIMAL_FLOATING_POINT_TYPES("true"),
|
||||
SUPPORT_COMPLEX_IN_CPP("true"),
|
||||
SUPPORT_RESTRICT_IN_CPP("true");
|
||||
|
||||
public static final String KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES = "floatingPointTypes";
|
||||
|
||||
private final String defaultVal;
|
||||
|
||||
private XlcPref(String defaultVal) {
|
||||
this.defaultVal = defaultVal;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -23,23 +23,23 @@ public interface XlcCPPParsersym {
|
|||
TK_bool = 15,
|
||||
TK_break = 88,
|
||||
TK_case = 89,
|
||||
TK_catch = 132,
|
||||
TK_catch = 133,
|
||||
TK_char = 16,
|
||||
TK_class = 53,
|
||||
TK_const = 33,
|
||||
TK_class = 52,
|
||||
TK_const = 32,
|
||||
TK_const_cast = 55,
|
||||
TK_continue = 90,
|
||||
TK_default = 91,
|
||||
TK_delete = 81,
|
||||
TK_delete = 82,
|
||||
TK_do = 92,
|
||||
TK_double = 26,
|
||||
TK_dynamic_cast = 56,
|
||||
TK_else = 135,
|
||||
TK_enum = 68,
|
||||
TK_enum = 57,
|
||||
TK_explicit = 38,
|
||||
TK_export = 93,
|
||||
TK_extern = 39,
|
||||
TK_false = 57,
|
||||
TK_false = 58,
|
||||
TK_float = 17,
|
||||
TK_for = 94,
|
||||
TK_friend = 40,
|
||||
|
@ -49,66 +49,66 @@ public interface XlcCPPParsersym {
|
|||
TK_int = 18,
|
||||
TK_long = 19,
|
||||
TK_mutable = 42,
|
||||
TK_namespace = 71,
|
||||
TK_new = 82,
|
||||
TK_namespace = 73,
|
||||
TK_new = 83,
|
||||
TK_operator = 12,
|
||||
TK_private = 116,
|
||||
TK_protected = 117,
|
||||
TK_public = 118,
|
||||
TK_private = 130,
|
||||
TK_protected = 131,
|
||||
TK_public = 132,
|
||||
TK_register = 43,
|
||||
TK_reinterpret_cast = 58,
|
||||
TK_reinterpret_cast = 59,
|
||||
TK_return = 97,
|
||||
TK_short = 20,
|
||||
TK_signed = 21,
|
||||
TK_sizeof = 59,
|
||||
TK_sizeof = 60,
|
||||
TK_static = 44,
|
||||
TK_static_cast = 60,
|
||||
TK_struct = 69,
|
||||
TK_static_cast = 61,
|
||||
TK_struct = 62,
|
||||
TK_switch = 98,
|
||||
TK_template = 52,
|
||||
TK_this = 61,
|
||||
TK_throw = 76,
|
||||
TK_template = 53,
|
||||
TK_this = 63,
|
||||
TK_throw = 78,
|
||||
TK_try = 84,
|
||||
TK_true = 62,
|
||||
TK_true = 64,
|
||||
TK_typedef = 45,
|
||||
TK_typeid = 63,
|
||||
TK_typename = 22,
|
||||
TK_union = 70,
|
||||
TK_unsigned = 23,
|
||||
TK_typeid = 65,
|
||||
TK_typename = 23,
|
||||
TK_union = 66,
|
||||
TK_unsigned = 22,
|
||||
TK_using = 74,
|
||||
TK_virtual = 36,
|
||||
TK_void = 27,
|
||||
TK_volatile = 34,
|
||||
TK_volatile = 33,
|
||||
TK_wchar_t = 28,
|
||||
TK_while = 87,
|
||||
TK_integer = 64,
|
||||
TK_floating = 65,
|
||||
TK_charconst = 66,
|
||||
TK_stringlit = 47,
|
||||
TK_integer = 67,
|
||||
TK_floating = 68,
|
||||
TK_charconst = 69,
|
||||
TK_stringlit = 49,
|
||||
TK_identifier = 1,
|
||||
TK_Completion = 4,
|
||||
TK_EndOfCompletion = 11,
|
||||
TK_Invalid = 136,
|
||||
TK_LeftBracket = 77,
|
||||
TK_LeftBracket = 75,
|
||||
TK_LeftParen = 5,
|
||||
TK_Dot = 133,
|
||||
TK_Dot = 129,
|
||||
TK_DotStar = 103,
|
||||
TK_Arrow = 119,
|
||||
TK_Arrow = 116,
|
||||
TK_ArrowStar = 102,
|
||||
TK_PlusPlus = 50,
|
||||
TK_MinusMinus = 51,
|
||||
TK_And = 14,
|
||||
TK_Star = 13,
|
||||
TK_Plus = 48,
|
||||
TK_Minus = 49,
|
||||
TK_Plus = 47,
|
||||
TK_Minus = 48,
|
||||
TK_Tilde = 10,
|
||||
TK_Bang = 54,
|
||||
TK_Slash = 104,
|
||||
TK_Percent = 105,
|
||||
TK_RightShift = 99,
|
||||
TK_LeftShift = 100,
|
||||
TK_LT = 72,
|
||||
TK_GT = 83,
|
||||
TK_LT = 71,
|
||||
TK_GT = 81,
|
||||
TK_LE = 106,
|
||||
TK_GE = 107,
|
||||
TK_EQ = 108,
|
||||
|
@ -117,29 +117,29 @@ public interface XlcCPPParsersym {
|
|||
TK_Or = 111,
|
||||
TK_AndAnd = 112,
|
||||
TK_OrOr = 113,
|
||||
TK_Question = 120,
|
||||
TK_Question = 117,
|
||||
TK_Colon = 80,
|
||||
TK_ColonColon = 6,
|
||||
TK_DotDotDot = 101,
|
||||
TK_Assign = 85,
|
||||
TK_StarAssign = 121,
|
||||
TK_SlashAssign = 122,
|
||||
TK_PercentAssign = 123,
|
||||
TK_PlusAssign = 124,
|
||||
TK_MinusAssign = 125,
|
||||
TK_RightShiftAssign = 126,
|
||||
TK_LeftShiftAssign = 127,
|
||||
TK_AndAssign = 128,
|
||||
TK_CaretAssign = 129,
|
||||
TK_OrAssign = 130,
|
||||
TK_StarAssign = 118,
|
||||
TK_SlashAssign = 119,
|
||||
TK_PercentAssign = 120,
|
||||
TK_PlusAssign = 121,
|
||||
TK_MinusAssign = 122,
|
||||
TK_RightShiftAssign = 123,
|
||||
TK_LeftShiftAssign = 124,
|
||||
TK_AndAssign = 125,
|
||||
TK_CaretAssign = 126,
|
||||
TK_OrAssign = 127,
|
||||
TK_Comma = 79,
|
||||
TK_RightBracket = 131,
|
||||
TK_RightParen = 78,
|
||||
TK_RightBracket = 128,
|
||||
TK_RightParen = 76,
|
||||
TK_RightBrace = 86,
|
||||
TK_SemiColon = 46,
|
||||
TK_LeftBrace = 73,
|
||||
TK_typeof = 32,
|
||||
TK___alignof__ = 67,
|
||||
TK_LeftBrace = 72,
|
||||
TK_typeof = 34,
|
||||
TK___alignof__ = 70,
|
||||
TK___attribute__ = 8,
|
||||
TK___declspec = 9,
|
||||
TK_MAX = 114,
|
||||
|
@ -149,7 +149,7 @@ public interface XlcCPPParsersym {
|
|||
TK__Decimal32 = 29,
|
||||
TK__Decimal64 = 30,
|
||||
TK__Decimal128 = 31,
|
||||
TK_ERROR_TOKEN = 75,
|
||||
TK_ERROR_TOKEN = 77,
|
||||
TK_EOF_TOKEN = 134;
|
||||
|
||||
public final static String orderedTerminalSymbols[] = {
|
||||
|
@ -175,8 +175,8 @@ public interface XlcCPPParsersym {
|
|||
"long",
|
||||
"short",
|
||||
"signed",
|
||||
"typename",
|
||||
"unsigned",
|
||||
"typename",
|
||||
"_Complex",
|
||||
"_Imaginary",
|
||||
"double",
|
||||
|
@ -185,9 +185,9 @@ public interface XlcCPPParsersym {
|
|||
"_Decimal32",
|
||||
"_Decimal64",
|
||||
"_Decimal128",
|
||||
"typeof",
|
||||
"const",
|
||||
"volatile",
|
||||
"typeof",
|
||||
"restrict",
|
||||
"virtual",
|
||||
"auto",
|
||||
|
@ -200,43 +200,43 @@ public interface XlcCPPParsersym {
|
|||
"static",
|
||||
"typedef",
|
||||
"SemiColon",
|
||||
"stringlit",
|
||||
"Plus",
|
||||
"Minus",
|
||||
"stringlit",
|
||||
"PlusPlus",
|
||||
"MinusMinus",
|
||||
"template",
|
||||
"class",
|
||||
"template",
|
||||
"Bang",
|
||||
"const_cast",
|
||||
"dynamic_cast",
|
||||
"enum",
|
||||
"false",
|
||||
"reinterpret_cast",
|
||||
"sizeof",
|
||||
"static_cast",
|
||||
"struct",
|
||||
"this",
|
||||
"true",
|
||||
"typeid",
|
||||
"union",
|
||||
"integer",
|
||||
"floating",
|
||||
"charconst",
|
||||
"__alignof__",
|
||||
"enum",
|
||||
"struct",
|
||||
"union",
|
||||
"namespace",
|
||||
"LT",
|
||||
"LeftBrace",
|
||||
"namespace",
|
||||
"using",
|
||||
"ERROR_TOKEN",
|
||||
"throw",
|
||||
"LeftBracket",
|
||||
"RightParen",
|
||||
"ERROR_TOKEN",
|
||||
"throw",
|
||||
"Comma",
|
||||
"Colon",
|
||||
"GT",
|
||||
"delete",
|
||||
"new",
|
||||
"GT",
|
||||
"try",
|
||||
"Assign",
|
||||
"RightBrace",
|
||||
|
@ -269,9 +269,6 @@ public interface XlcCPPParsersym {
|
|||
"OrOr",
|
||||
"MAX",
|
||||
"MIN",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"Arrow",
|
||||
"Question",
|
||||
"StarAssign",
|
||||
|
@ -285,8 +282,11 @@ public interface XlcCPPParsersym {
|
|||
"CaretAssign",
|
||||
"OrAssign",
|
||||
"RightBracket",
|
||||
"catch",
|
||||
"Dot",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"catch",
|
||||
"EOF_TOKEN",
|
||||
"else",
|
||||
"Invalid"
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPref;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
|
||||
/**
|
||||
* A simple wrapper for a checkbox.
|
||||
*
|
||||
*/
|
||||
class PrefCheckbox {
|
||||
|
||||
private final XlcPref key;
|
||||
private final Button button;
|
||||
|
||||
PrefCheckbox(Composite parent, XlcPref prefKey, String label) {
|
||||
button = ControlFactory.createCheckBox(parent, label);
|
||||
key = prefKey;
|
||||
}
|
||||
|
||||
public XlcPref getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setSelection(boolean selection) {
|
||||
button.setSelection(selection);
|
||||
}
|
||||
|
||||
public boolean getSelection() {
|
||||
return button.getSelection();
|
||||
}
|
||||
|
||||
public void setDefault() {
|
||||
setSelection(Boolean.valueOf(XlcLanguagePreferences.getDefaultPreference(key)));
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class PreferenceMessages extends NLS {
|
||||
|
@ -19,15 +21,33 @@ public class PreferenceMessages extends NLS {
|
|||
private PreferenceMessages() {}
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(BUNDLE_NAME, PreferenceMessages.class);
|
||||
initializeMessages(BUNDLE_NAME, PreferenceMessages.class);
|
||||
}
|
||||
|
||||
public static final String PREFIX = "XlcLanguageOptionsPreferencePage_";
|
||||
|
||||
|
||||
public static String getMessage(String suffix) {
|
||||
try {
|
||||
Field field = PreferenceMessages.class.getDeclaredField(PREFIX + suffix);
|
||||
return (String)field.get(null);
|
||||
|
||||
} catch (NoSuchFieldException e) {
|
||||
return null;
|
||||
} catch (IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String
|
||||
XlcLanguageOptionsPreferencePage_link,
|
||||
XlcLanguageOptionsPreferencePage_group,
|
||||
XlcLanguageOptionsPreferencePage_preference_vectors,
|
||||
XlcLanguageOptionsPreferencePage_preference_decimals;
|
||||
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_VECTOR_TYPES,
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_DECIMAL_FLOATING_POINT_TYPES,
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_COMPLEX_IN_CPP,
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_RESTRICT_IN_CPP;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
XlcLanguageOptionsPreferencePage_link=These settings are project-specific. The settings listed here override <a href="org.eclipse.cdt.core.lrparser.xlc.ui.XlcLanguagePreferencePage">workspace-wide</a> language settings.
|
||||
XlcLanguageOptionsPreferencePage_group=Support For XL C/C++ Language Extensions
|
||||
|
||||
XlcLanguageOptionsPreferencePage_preference_vectors=Allow vector type declarations
|
||||
XlcLanguageOptionsPreferencePage_preference_decimals=Allow decimal floating-point types (_Decimal32, _Decimal64, _Decimal128)
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_VECTOR_TYPES=Allow vector type declarations
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_DECIMAL_FLOATING_POINT_TYPES=Allow decimal floating-point types (_Decimal32, _Decimal64, _Decimal128)
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_COMPLEX_IN_CPP=Allow complex type in C++ (_Complex)
|
||||
XlcLanguageOptionsPreferencePage_SUPPORT_RESTRICT_IN_CPP=Allow 'restrict' keyword in C++ (restrict, __restrict, __restrict__)
|
||||
|
||||
|
|
|
@ -13,13 +13,12 @@ package org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences;
|
|||
|
||||
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPreferenceKeys;
|
||||
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPref;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
|
@ -38,11 +37,24 @@ import org.eclipse.ui.dialogs.PreferencesUtil;
|
|||
public class XlcLanguageOptionsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage {
|
||||
|
||||
private IAdaptable element;
|
||||
private PrefCheckbox[] checkboxes;
|
||||
|
||||
|
||||
private void initializeCheckboxes(Composite group) {
|
||||
XlcPref[] prefs = XlcPref.values();
|
||||
int n = prefs.length;
|
||||
PrefCheckbox[] checkboxes = new PrefCheckbox[n];
|
||||
IProject project = getProject(); // null for preference page
|
||||
|
||||
for(int i = 0; i < n; i++) {
|
||||
String message = PreferenceMessages.getMessage(prefs[i].toString());
|
||||
checkboxes[i] = new PrefCheckbox(group, prefs[i], message);
|
||||
String preference = XlcLanguagePreferences.get(prefs[i], project);
|
||||
checkboxes[i].setSelection(Boolean.valueOf(preference));
|
||||
}
|
||||
}
|
||||
|
||||
private Button buttonVectors;
|
||||
private Button buttonDecimals;
|
||||
|
||||
|
||||
@Override
|
||||
protected Control createContents(Composite parent) {
|
||||
Composite page = ControlFactory.createComposite(parent, 1);
|
||||
|
@ -58,11 +70,7 @@ public class XlcLanguageOptionsPreferencePage extends PreferencePage implements
|
|||
}
|
||||
|
||||
Composite group = ControlFactory.createGroup(page, PreferenceMessages.XlcLanguageOptionsPreferencePage_group, 1);
|
||||
|
||||
buttonVectors = ControlFactory.createCheckBox(group, PreferenceMessages.XlcLanguageOptionsPreferencePage_preference_vectors);
|
||||
initCheckbox(buttonVectors, XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES);
|
||||
buttonDecimals = ControlFactory.createCheckBox(group, PreferenceMessages.XlcLanguageOptionsPreferencePage_preference_decimals);
|
||||
initCheckbox(buttonDecimals, XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES);
|
||||
initializeCheckboxes(group);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
@ -70,53 +78,36 @@ public class XlcLanguageOptionsPreferencePage extends PreferencePage implements
|
|||
|
||||
@Override
|
||||
protected void performDefaults() {
|
||||
buttonVectors.setSelection(Boolean.valueOf(XlcLanguagePreferences.getDefaultPreference(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES)));
|
||||
buttonDecimals.setSelection(Boolean.valueOf(XlcLanguagePreferences.getDefaultPreference(XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES)));
|
||||
|
||||
for(PrefCheckbox button : checkboxes) {
|
||||
button.setDefault();
|
||||
}
|
||||
super.performDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
setPreference(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, buttonVectors.getSelection(), getProject());
|
||||
setPreference(XlcPreferenceKeys.KEY_SUPPORT_DECIMAL_FLOATING_POINT_TYPES, buttonDecimals.getSelection(), getProject());
|
||||
IProject project = getProject();
|
||||
for(PrefCheckbox button : checkboxes) {
|
||||
setPreference(button.getKey(), button.getSelection(), project);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initCheckbox(Button checkbox, String prefKey) {
|
||||
String preference = null;
|
||||
|
||||
if(isPropertyPage()) {
|
||||
IProject project = getProject();
|
||||
preference = XlcLanguagePreferences.getProjectPreference(prefKey, project);
|
||||
}
|
||||
else {
|
||||
preference = XlcLanguagePreferences.getWorkspacePreference(prefKey);
|
||||
}
|
||||
|
||||
if(preference == null) {
|
||||
preference = XlcLanguagePreferences.getDefaultPreference(prefKey);
|
||||
}
|
||||
|
||||
checkbox.setSelection(Boolean.valueOf(preference));
|
||||
private static void setPreference(XlcPref key, boolean val, IProject project) {
|
||||
String s = String.valueOf(val);
|
||||
if(project != null)
|
||||
XlcLanguagePreferences.setProjectPreference(key, s, project);
|
||||
else
|
||||
XlcLanguagePreferences.setWorkspacePreference(key, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private IProject getProject() {
|
||||
return isPropertyPage() ? (IProject)element.getAdapter(IProject.class) : null;
|
||||
}
|
||||
|
||||
private static void setPreference(String key, boolean val, IProject project) {
|
||||
if(project != null)
|
||||
XlcLanguagePreferences.setProjectPreference(key, String.valueOf(val), project);
|
||||
else
|
||||
XlcLanguagePreferences.setWorkspacePreference(key, String.valueOf(val));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public IAdaptable getElement() {
|
||||
return element;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue