Skip to main content
summaryrefslogtreecommitdiffstats
path: root/upc
diff options
context:
space:
mode:
authorMike Kucera2008-12-19 12:00:20 -0500
committerMike Kucera2008-12-19 12:00:20 -0500
commite3a1eeca7a07a737cdf647c972234c038283052a (patch)
tree5b68e6462a96965938cfddaf7d471950805f6c73 /upc
parent602ce8c5f684b97e1105a8902db6120aa9751426 (diff)
downloadorg.eclipse.cdt-e3a1eeca7a07a737cdf647c972234c038283052a.tar.gz
org.eclipse.cdt-e3a1eeca7a07a737cdf647c972234c038283052a.tar.xz
org.eclipse.cdt-e3a1eeca7a07a737cdf647c972234c038283052a.zip
bug 259318, provide reusable implementation of ICLanguageKeywords
Diffstat (limited to 'upc')
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCKeyword.java47
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCLanguageKeywords.java19
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java23
3 files changed, 70 insertions, 19 deletions
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCKeyword.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCKeyword.java
index 30cd0d1d91..64b3be282a 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCKeyword.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCKeyword.java
@@ -1,12 +1,22 @@
package org.eclipse.cdt.core.dom.parser.upc;
-import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_MYTHREAD;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_THREADS;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_UPC_MAX_BLOCKSIZE;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_relaxed;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_shared;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_strict;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_barrier;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_blocksizeof;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_elemsizeof;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_fence;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_forall;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_localsizeof;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_notify;
+import static org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym.TK_upc_wait;
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.parser.util.CharArrayMap;
/**
@@ -34,19 +44,30 @@ public enum UPCKeyword {
private final int tokenKind;
- private static List<String> names = new ArrayList<String>();
+
private static final CharArrayMap<Integer> tokenMap = new CharArrayMap<Integer>();
+ private static final String[] upcKeywords;
+ private static final String[] allKeywords;
UPCKeyword(int tokenKind) {
this.tokenKind = tokenKind;
}
- static { // cannot refer to static fields from constructor
- for(UPCKeyword keyword : values()) {
+ static {
+ UPCKeyword[] keywords = values();
+ upcKeywords = new String[keywords.length];
+ for(int i = 0; i < keywords.length; i++) {
+ UPCKeyword keyword = keywords[i];
String name = keyword.name();
- names.add(name);
+ upcKeywords[i] = name;
tokenMap.put(name.toCharArray(), keyword.tokenKind);
}
+
+ ICLanguageKeywords c99Keywords = (ICLanguageKeywords) C99Language.getDefault().getAdapter(ICLanguageKeywords.class);
+ String[] c99ks = c99Keywords.getKeywords();
+ allKeywords = new String[upcKeywords.length + c99ks.length];
+ System.arraycopy(c99ks, 0, allKeywords, 0, c99ks.length);
+ System.arraycopy(upcKeywords, 0, allKeywords, c99ks.length, upcKeywords.length);
}
public int getTokenKind() {
@@ -54,16 +75,16 @@ public enum UPCKeyword {
}
public static String[] getUPCOnlyKeywords() {
- return names.toArray(new String[names.size()]);
+ return upcKeywords;
}
public static String[] getAllKeywords() {
- List<String> allKeywords = new ArrayList<String>(names);
- allKeywords.addAll(Arrays.asList(C99Language.getDefault().getKeywords()));
- return allKeywords.toArray(new String[allKeywords.size()]);
+ return allKeywords;
}
public static Integer getTokenKind(char[] image) {
+ if(image == null)
+ return null;
return tokenMap.get(image);
}
}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCLanguageKeywords.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCLanguageKeywords.java
new file mode 100644
index 0000000000..90acf2bcad
--- /dev/null
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/parser/upc/UPCLanguageKeywords.java
@@ -0,0 +1,19 @@
+package org.eclipse.cdt.core.dom.parser.upc;
+
+import org.eclipse.cdt.core.dom.parser.CLanguageKeywords;
+import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+
+public class UPCLanguageKeywords extends CLanguageKeywords {
+
+ public UPCLanguageKeywords(IScannerExtensionConfiguration config) {
+ super(ParserLanguage.C, config);
+ }
+
+ private static String[] upcKeywords = UPCKeyword.getAllKeywords();
+
+ @Override
+ public String[] getKeywords() {
+ return upcKeywords;
+ }
+}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
index 01ce11c287..c2b879a92d 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
@@ -18,15 +18,18 @@ import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.upc.DOMToUPCTokenMap;
-import org.eclipse.cdt.core.dom.parser.upc.UPCKeyword;
+import org.eclipse.cdt.core.dom.parser.upc.UPCLanguageKeywords;
import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ParserLanguage;
-import org.eclipse.cdt.internal.core.dom.parser.c.CNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
+import org.eclipse.cdt.internal.core.dom.parser.c.CNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.upc.UPCParser;
+import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
+import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
/**
@@ -43,7 +46,6 @@ public class UPCLanguage extends BaseExtensibleLanguage {
private static final IDOMTokenMap TOKEN_MAP = new DOMToUPCTokenMap();
private static final UPCLanguage myDefault = new UPCLanguage();
- private static final String[] upcKeywords = UPCKeyword.getAllKeywords();
private static final IScannerExtensionConfiguration SCANNER_CONFIGURATION = new ScannerExtensionConfiguration();
@@ -77,11 +79,20 @@ public class UPCLanguage extends BaseExtensibleLanguage {
return ILinkage.C_LINKAGE_ID;
}
+
+ private static final ICLanguageKeywords upcKeywords = new UPCLanguageKeywords(SCANNER_CONFIGURATION);
+
+ @SuppressWarnings("unchecked")
@Override
- public String[] getKeywords() {
- return upcKeywords;
+ public Object getAdapter(Class adapter) {
+ if(IPDOMLinkageFactory.class.equals(adapter))
+ return new PDOMCLinkageFactory();
+ if(ICLanguageKeywords.class.equals(adapter))
+ return upcKeywords;
+
+ return super.getAdapter(adapter);
}
-
+
@Override
protected ParserLanguage getParserLanguage() {
return ParserLanguage.C;

Back to the top