Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mbien/netbeans-opencl-pack
base: 54f4721eb6
...
head fork: mbien/netbeans-opencl-pack
compare: 04c6249879
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 29, 2011
@mbien editor annotations are now updated if the CLPlatform changes (propert…
…y changed event).

CLPlatform chooser action uses now a shared model to display the same value on all opened editors.
Added F9 shortcut for the compile program action.
8650640
@mbien added auto completion for built-in functions including rudimentary do…
…c download.
04c6249
View
18 opencl-editor/nbproject/project.xml
@@ -24,6 +24,15 @@
</run-dependency>
</dependency>
<dependency>
+ <code-name-base>org.netbeans.modules.editor.completion</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.26.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
<code-name-base>org.netbeans.modules.editor.lib</code-name-base>
<build-prerequisite/>
<compile-dependency/>
@@ -42,6 +51,15 @@
</run-dependency>
</dependency>
<dependency>
+ <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.22.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
<code-name-base>org.netbeans.modules.editor.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
View
29 opencl-editor/src/com/mbien/opencl/editor/compiler/CLCompilerMessageAnnotationTask.java
@@ -15,6 +15,8 @@
import com.mbien.opencl.editor.compiler.CompilerMessage.KIND;
import com.mbien.opencl.editor.file.CLDataObject;
import com.mbien.opencl.service.CLService;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +37,17 @@
private int compileDelay = 500;
private CLDataObject dao;
+ public CLCompilerMessageAnnotationTask() {
+ getCLService().addPropertyChangeListener(new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if(CLService.PLATFORM.equals(event.getPropertyName())) {
+ update();
+ }
+ }
+ });
+ }
+
private static class TaskImpl implements Runnable {
private final CLDataObject dao;
@@ -115,13 +128,13 @@ private AnnotationType getType(CompilerMessage msg) {
return AnnotationType.WARNING;
}
}
+ }
- private static CLService getCLService() {
- return Lookup.getDefault().lookup(CLService.class);
- }
+ private static CLService getCLService() {
+ return Lookup.getDefault().lookup(CLService.class);
}
- private void needUpdate() {
+ private void update() {
CLDataObject obj = dao;
if (obj != null) {
RequestProcessor.Task task = pool.create(new TaskImpl(obj));
@@ -131,23 +144,23 @@ private void needUpdate() {
@Override
public void insertUpdate(DocumentEvent e) {
- needUpdate();
+ update();
}
@Override
public void removeUpdate(DocumentEvent e) {
- needUpdate();
+ update();
}
@Override
public void changedUpdate(DocumentEvent e) {
- needUpdate();
+ update();
}
@Override
public void opened(CLDataObject dao) {
this.dao = dao;
- needUpdate();
+ update();
}
@Override
View
13 opencl-editor/src/com/mbien/opencl/editor/compiler/CompilerActions.java
@@ -41,6 +41,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
+import javax.swing.DefaultComboBoxModel;
import org.openide.util.Lookup;
import static java.awt.Color.*;
@@ -58,7 +59,8 @@ private CompilerActions() { }
@ActionRegistration(displayName = "Compile Kernel", iconBase = "com/mbien/opencl/editor/compiler/clbuild.png")
@ActionReferences({
@ActionReference(path = "Editors/text/x-opencl/Toolbars/Default", position = 20400),
- @ActionReference(path = "Loaders/text/x-opencl/Actions", position = 810)
+ @ActionReference(path = "Loaders/text/x-opencl/Actions", position = 810),
+ @ActionReference(path = "Shortcuts", name="F9")
})
public static class CompileAction implements ActionListener {
@@ -213,6 +215,7 @@ public void outputLineSelected(OutputEvent arg0) { }
public static class CLPlatformAction extends AbstractAction implements Presenter.Toolbar {
private JComboBox<CLPlatform> box;
+ private DefaultComboBoxModel<CLPlatform> model;
@Override
public void actionPerformed(ActionEvent e) {
@@ -224,9 +227,13 @@ public Component getToolbarPresenter() {
CLService service = getCLService();
- CLPlatform[] platforms = service.listCLPlatforms();
+ // one model instance shared between n components
+ if(model == null) {
+ CLPlatform[] platforms = service.listCLPlatforms();
+ model = new DefaultComboBoxModel<>(platforms);
+ }
- box = new JComboBox<>(platforms);
+ box = new JComboBox<>(model);
box.setRenderer(new DefaultListCellRenderer() {
@Override
View
139 opencl-editor/src/com/mbien/opencl/editor/completion/CLCompletionItem.java
@@ -0,0 +1,139 @@
+/*
+ * Created on Monday, August 29 2011 05:33
+ */
+package com.mbien.opencl.editor.completion;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.event.KeyEvent;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.spi.editor.completion.CompletionItem;
+import org.netbeans.spi.editor.completion.CompletionResultSet;
+import org.netbeans.spi.editor.completion.CompletionTask;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
+import org.netbeans.spi.editor.completion.support.CompletionUtilities;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author mbien
+ */
+class CLCompletionItem implements CompletionItem {
+
+ private final CLCompletionProvider.CLElementDescriptor content;
+ private int carretPosition = 0;
+ private String prefix;
+ private String leftText;
+ private String rightText;
+ private String ARGUMENTS_COLOR = "<font color=#b28b00>";
+ private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>";
+ private String KEYWORD_COLOR = "<font color=#000099>";
+ private int priority;
+
+ public CLCompletionItem(CLCompletionProvider.CLElementDescriptor content, String prefix, int carretPosition) {
+ this.content = content;
+ this.prefix = prefix;
+ this.carretPosition = carretPosition;
+ leftText = createLeftText();
+ rightText = content.type;
+ // low prority is first in completion list
+ priority = 10;
+ }
+
+ private String createLeftText() {
+ StringBuilder text = new StringBuilder();
+// switch (content.category) {
+// case TYPE:
+// case KEYWORD:
+// case QUALIFIER:
+// text.append(KEYWORD_COLOR);
+// break;
+// case BUILD_IN_VAR:
+ text.append(BUILD_IN_VAR_COLOR);
+// break;
+// }
+ text.append("<b>");
+ text.append(content.token);
+ text.append("</b></font>");
+// if (content.arguments != null) {
+// text.append(ARGUMENTS_COLOR);
+// text.append(content.arguments);
+// text.append("</font>");
+// }
+ return text.toString();
+ }
+
+ public void defaultAction(JTextComponent component) {
+ Completion.get().hideAll();
+ // replace prefix with content.token
+ try {
+ component.getDocument().remove(carretPosition - prefix.length(), prefix.length());
+ component.getDocument().insertString(carretPosition - prefix.length(), content.token, null);
+ } catch (BadLocationException e) {
+ Exceptions.printStackTrace(e);
+ }
+ }
+
+ public void processKeyEvent(KeyEvent evt) {
+
+ // hide
+ switch(evt.getKeyCode()) {
+ case KeyEvent.VK_SPACE:
+ if(evt.isControlDown()) {break;}
+ case KeyEvent.VK_TAB:
+ case KeyEvent.VK_BACK_SPACE:
+ if(prefix.isEmpty()) {
+ Completion.get().hideAll();
+ }
+ }
+
+ // TODO: if "." then Completion.get().showCompletion()... but this does not make much sense without AST
+ }
+
+ public int getPreferredWidth(Graphics g, Font defaultFont) {
+ return CompletionUtilities.getPreferredWidth(leftText, rightText, g, defaultFont);
+ }
+
+ public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
+ CompletionUtilities.renderHtml(null, leftText, rightText, g, defaultFont, defaultColor, width, height, selected);
+ }
+
+ public CompletionTask createDocumentationTask() {
+ if (content.doc == null) {
+ return null;
+ }
+ return new AsyncCompletionTask(new AsyncCompletionQuery() {
+ protected void query(CompletionResultSet resultSet, Document document, int i) {
+ resultSet.setDocumentation(new CLDocItem(content.token, content));
+ resultSet.finish();
+ }
+ });
+ }
+
+ public CompletionTask createToolTipTask() {
+ return null;
+ }
+
+ public boolean instantSubstitution(JTextComponent component) {
+ defaultAction(component);
+ return true;
+ }
+
+ public int getSortPriority() {
+ return priority;
+ }
+
+ public CharSequence getSortText() {
+ return content.token;
+ }
+
+ public CharSequence getInsertPrefix() {
+ return prefix;
+ }
+
+}
View
115 opencl-editor/src/com/mbien/opencl/editor/completion/CLCompletionProvider.java
@@ -0,0 +1,115 @@
+/*
+ * Created on Sunday, August 28 2011 21:52
+ */
+package com.mbien.opencl.editor.completion;
+
+import com.mbien.opencl.editor.file.CLDataObject;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.spi.editor.completion.CompletionProvider;
+import org.netbeans.spi.editor.completion.CompletionResultSet;
+import org.netbeans.spi.editor.completion.CompletionTask;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author mbien
+ */
+@MimeRegistration(mimeType = CLDataObject.MIME_TYPE, service = CompletionProvider.class)
+public class CLCompletionProvider implements CompletionProvider {
+
+
+ @Override
+ public CompletionTask createTask(int queryType, JTextComponent component) {
+ return new AsyncCompletionTask(new CLCompletionQuery(), component);
+ }
+
+ @Override
+ public int getAutoQueryTypes(JTextComponent component, String typedText) {
+ return 0;
+ }
+
+ private static class CLCompletionQuery extends AsyncCompletionQuery {
+
+ private static final List<CLElementDescriptor> items = new ArrayList<>(1024);
+
+ @Override
+ protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
+ fillResultset(resultSet, doc, caretOffset);
+ resultSet.finish();
+ }
+
+ private void fillResultset(CompletionResultSet resultSet, Document doc, int caretOffset) {
+
+ Element paragraph = ((BaseDocument) doc).getParagraphElement(caretOffset);
+ String prefix;
+ try {
+ prefix = doc.getText(paragraph.getStartOffset(), caretOffset - paragraph.getStartOffset());
+ prefix = prefix.replaceAll(".*?([\\w-\"]*)$", "$1");
+ } catch (BadLocationException ex) {
+ Exceptions.printStackTrace(ex);
+ prefix = "";
+ }
+
+ synchronized(items) {
+ if(items.isEmpty()) {
+ try {
+ loadItems();
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
+
+ for (CLElementDescriptor item : items) {
+ if (item.token.regionMatches(true, 0, prefix, 0, prefix.length())) {
+ resultSet.addItem(new CLCompletionItem(item, prefix, caretOffset));
+ }
+ }
+ }
+
+ }
+
+ private void loadItems() throws IOException {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(getClass().getResourceAsStream("builtin-functions")))) {
+ for (;;) {
+ String line = reader.readLine();
+ if (line == null)
+ return;
+ String[] split = line.split("=");
+ items.add(new CLElementDescriptor(split[0], "built-in function", split[1]));
+ }
+ }
+ }
+
+ }
+
+ static class CLElementDescriptor {
+
+ public final String token;
+ public final String type;
+ public final String doc;
+
+ public final int category;
+
+ public CLElementDescriptor(String token, String type, String doc) {
+ this.token = token;
+ this.doc = doc;
+ this.type = type;
+ this.category = 0;
+ }
+
+
+ }
+}
View
96 opencl-editor/src/com/mbien/opencl/editor/completion/CLDocItem.java
@@ -0,0 +1,96 @@
+/*
+ * Created on Monday, August 29 2011 05:33
+ */
+package com.mbien.opencl.editor.completion;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.swing.Action;
+import org.netbeans.spi.editor.completion.CompletionDocumentation;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author mbien
+ */
+class CLDocItem implements CompletionDocumentation {
+
+ private String doc;
+ private String text;
+
+ public CLDocItem(String item, CLCompletionProvider.CLElementDescriptor content) {
+ doc = content.doc;
+ StringBuilder sb = new StringBuilder();
+ sb.append("<code>");
+ if (content.type != null) {
+ sb.append(content.type);
+ sb.append(" ");
+ }
+ sb.append("<b>");
+ sb.append(item);
+ sb.append("</b>");
+// if(content.arguments != null) {
+// sb.append(content.arguments);
+// }
+ sb.append("</code><p>");
+ try{
+ downloadDoc(sb);
+ }catch(IOException ex) {
+// sb.append("<a href='"+getURL()+"'>"+getURL()+"</a>");
+ Exceptions.printStackTrace(ex);
+ }
+ sb.append("</p>");
+ text = sb.toString();
+ }
+
+ //FIXME this is a hack, but we can't parse the doc since it contains invalid xhtml
+ private void downloadDoc(StringBuilder sb) throws IOException {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(getURL().openStream()))) {
+ boolean skip = false;
+ for (;;) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ if(line.contains("<style") || line.contains("<head")) {
+ skip = true;
+ continue;
+ }else if(line.contains("</style>") || line.contains("</head>")) {
+ skip = false;
+ continue;
+ }
+
+ if(!skip && !line.startsWith("<?xml")
+ && !line.startsWith("<!DOCTYPE")
+ && !line.contains("<h1>")
+ && !line.contains("<meta")
+ && !line.contains("<title")) {
+ sb.append(line);
+ }
+ }
+ }
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public URL getURL() {
+ try {
+ return new URL("http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/"+doc+".html");
+ } catch (MalformedURLException ex) {
+ return null;
+ }
+ }
+
+ public CompletionDocumentation resolveLink(String link) {
+ return null;
+ }
+
+ public Action getGotoSourceAction() {
+ return null;
+ }
+
+}
View
203 opencl-editor/src/com/mbien/opencl/editor/completion/builtin-functions
@@ -0,0 +1,203 @@
+abs=abs
+abs-diff=abs
+acos=acos
+acosh=acos
+acospi=acos
+add_sat=add_sat
+all=any
+any=any
+asin=asin
+asinh=asin
+asinpi=asin
+async_work_group_copy=async_work_group_copy
+async_work_group_strided_copy=async_work_group_strided_copy
+atan=atan
+atan2=atan
+atan2pi=atan
+atanh=atan
+atanpi=atan
+atomic_add=atomic_add
+atomic_and=atomic_and
+atomic_cmpxchg=atomic_cmpxchg
+atomic_dec=atomic_dec
+atomic_inc=atomic_inc
+atomic_max=atomic_max
+atomic_min=atomic_min
+atomic_or=atomic_or
+atomic_sub=atomic_sub
+atomic_xchg=atomic_xchg
+atomic_xor=atomic_xor
+barrier=barrier
+bitselect=bitselect
+cbrt=cbrt
+ceil=ceil
+clamp=clamp
+clamp=integerClamp
+clz=clz
+copysign=copysign
+cos=cos
+cosh=cos
+cospi=cos
+cross=cross
+degrees=degrees
+distance=distance
+dot=dot
+erf=erf
+erfc=erf
+exp=exp
+exp10=exp
+exp2=exp
+expm1=exp
+fabs=fabs
+fast_distance=fast_distance
+fast_length=fast_length
+fast_normalize=fast_normalize
+fdim=fdim
+floor=floor
+fma=fma
+fmax=fmax
+fmin=fmin
+fmod=fmod
+fract=fract
+frexp=frexp
+get_global_id=get_global_id
+get_global_offset=get_global_offset
+get_global_size=get_global_size
+get_group_id=get_group_id
+get_image_channel_data_type=get_image_channel_data_type
+get_image_channel_order=get_image_channel_order
+get_image_depth=get_image_depth
+get_image_dim=get_image_dim
+get_image_height=get_image_height
+get_image_width=get_image_width
+get_local_id=get_local_id
+get_local_size=get_local_size
+get_num_groups=get_num_groups
+get_work_dim=get_work_dim
+hadd=hadd
+half_cos=cos
+half_divide=divide
+half_exp=exp
+half_exp10=exp
+half_exp2=exp
+half_log=log
+half_log10=log
+half_log2=log
+half_powr=pow
+half_recip=recip
+half_rsqrt=sqrt
+half_sin=sin
+half_sqrt=sqrt
+half_tan=tan
+hypot=hypot
+ilogb=ilogb
+isequal=isequal
+isfinite=isfinite
+isgreater=isgreater
+isgreaterequal=isgreaterequal
+isinf=isinf
+isless=isless
+islessequal=islessequal
+islessgreater=islessgreater
+isnan=isnan
+isnormal=isnormal
+isnotequal=isnotequal
+isordered=isordered
+isunordered=isunordered
+ldexp=ldexp
+length=length
+lgamma=lgamma
+lgamma_r=lgamma
+log=log
+log10=log
+log1p=log
+log2=log
+logb=log
+mad=mad
+mad24=mad24
+mad_hi=mad_hi
+mad_sat=mad_sat
+max=commonMax
+max=integerMax
+maxmag=mag
+mem_fence=mem_fence
+min=commonMin
+min=integerMax
+minmag=mag
+mix=mix
+modf=modf
+mul24=mul24
+mul_hi=mul_hi
+nan=nan
+nativ_cos=cos
+nativ_divide=divide
+nativ_exp=exp
+nativ_exp10=exp
+nativ_exp2=exp
+nativ_log=log
+nativ_log10=log
+nativ_log2=log
+nativ_powr=pow
+nativ_recip=recip
+nativ_rsqrt=sqrt
+nativ_sin=sin
+nativ_sqrt=sqrt
+nativ_tan=tan
+nextafter=nextafter
+normalize=normalize
+pow=pow
+pown=pow
+powr=pow
+prefetch=prefetch
+radians=radians
+read_imagef=read_imagef2d
+read_imagef=read_imagef3d
+read_imageh=read_imageh2d
+read_imageh=read_imageh3d
+read_imagei=read_imagei2d
+read_imagei=read_imagei3d
+read_imageui=read_imagei2d
+read_mem_fence=read_mem_fence
+remainder=remainder
+remquo=remquo
+rhadd=hadd
+rint=rint
+rootn=rootn
+rotate=rotate
+round=round
+rsqrt=sqrt
+select=select
+shuffle=shuffle
+shuffle2=shuffle
+sign=sign
+signbit=signbit
+sin=sin
+sincos=sin
+sinh=sin
+sinpi=sin
+smoothstep=smoothstep
+sqrt=sqrt
+step=step
+sub_sat=sub_sat
+tan=tan
+tanh=tan
+tanpi=tan
+tgamma=tgamma
+trunc=trunc
+upsample=upsample
+vec_step=vec_step
+vload_half=vload_half
+vload_halfn=vload_halfn
+vloada_halfn=vloada_halfn
+vloadn=vloadn
+vstore_half=vstore_half
+vstore_halfn=vstore_halfn
+vstorea_halfn=vstorea_halfn
+vstoren=vstoren
+wait_group_events=wait_group_events
+write_imagef=write_image
+write_imageh=write_imageh2d
+write_imageh=write_imageh3d
+write_imagei=write_image
+write_imageui=write_image
+write_mem_fence=write_mem_fence
View
6 opencl-editor/src/com/mbien/opencl/service/CLService.java
@@ -4,6 +4,7 @@
package com.mbien.opencl.service;
import com.jogamp.opencl.CLPlatform;
+import java.beans.PropertyChangeListener;
/**
*
@@ -11,6 +12,8 @@
*/
public interface CLService {
+ public static final String PLATFORM = "platform";
+
CLPlatform getDefaultPlatform();
void setDefaultPlatform(CLPlatform platform);
@@ -18,4 +21,7 @@
boolean available();
+ void addPropertyChangeListener(PropertyChangeListener listener);
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
}
View
17 opencl-editor/src/com/mbien/opencl/service/CLServiceImpl.java
@@ -4,6 +4,8 @@
package com.mbien.opencl.service;
import com.jogamp.opencl.CLPlatform;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import org.openide.util.Exceptions;
import org.openide.util.lookup.ServiceProvider;
@@ -16,6 +18,8 @@
private static CLPlatform platform;
+ private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+
public CLServiceImpl() {
try{
@@ -34,7 +38,9 @@ public synchronized CLPlatform getDefaultPlatform() {
@Override
public synchronized void setDefaultPlatform(CLPlatform platform) {
+ CLPlatform old = CLServiceImpl.platform;
CLServiceImpl.platform = platform;
+ propertyChangeSupport.firePropertyChange(PLATFORM, old, platform);
}
@Override
@@ -46,8 +52,19 @@ public synchronized void setDefaultPlatform(CLPlatform platform) {
}
}
+ @Override
public synchronized boolean available() {
return platform != null;
}
+ @Override
+ public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
+ propertyChangeSupport.addPropertyChangeListener(listener);
+ }
+
+ @Override
+ public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
+ propertyChangeSupport.removePropertyChangeListener(listener);
+ }
+
}

No commit comments for this range

Something went wrong with that request. Please try again.