You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ni...@us...> - 2007-12-06 23:20:51
|
Revision: 61 http://mspsim.svn.sourceforge.net/mspsim/?rev=61&view=rev Author: nifi Date: 2007-12-06 15:20:49 -0800 (Thu, 06 Dec 2007) Log Message: ----------- update source viewer if open when single stepping Modified Paths: -------------- mspsim/se/sics/mspsim/util/ControlUI.java Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 22:57:46 UTC (rev 60) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 23:20:49 UTC (rev 61) @@ -98,9 +98,22 @@ stepAction = new AbstractAction("Single Step") { public void actionPerformed(ActionEvent e) { - System.out.println("step"); ControlUI.this.cpu.step(); dui.repaint(); + if (elfData != null && sourceViewer != null + && sourceViewer.isVisible()) { + int pc = ControlUI.this.cpu.readRegister(MSP430Constants.PC); + DebugInfo dbg = elfData.getDebugInfo(pc); + if (dbg != null) { + if (ControlUI.this.cpu.getDebug()) { + System.out.println("looking up $" + Integer.toString(pc, 16) + + " => " + dbg.getFile() + ':' + + dbg.getLine()); + } + sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); + sourceViewer.viewLine(dbg.getLine()); + } + } } }; stepAction.putValue(Action.MNEMONIC_KEY, @@ -181,6 +194,10 @@ if (elfData != null) { DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { + if (cpu.getDebug()) { + System.out.println("looking up $" + Integer.toString(pc, 16) + + " => " + dbg.getFile() + ':' + dbg.getLine()); + } if (sourceViewer != null) { sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); sourceViewer.viewLine(dbg.getLine()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 22:57:48
|
Revision: 60 http://mspsim.svn.sourceforge.net/mspsim/?rev=60&view=rev Author: nifi Date: 2007-12-06 14:57:46 -0800 (Thu, 06 Dec 2007) Log Message: ----------- show file name in window title Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 21:37:25 UTC (rev 59) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 22:57:46 UTC (rev 60) @@ -129,7 +129,7 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { try { - String file = findSourceFile(path, filename); + File file = findSourceFile(path, filename); if (file != null) { FileReader reader = new FileReader(file); try { @@ -137,6 +137,8 @@ // Workaround for bug 4782232 in Java 1.4 highlighter.setCaretPosition(1); highlighter.setCaretPosition(0); + window.setTitle("Source Viewer (" + file.getAbsolutePath() + + ')'); if (!window.isVisible()) { window.setVisible(true); } @@ -156,7 +158,7 @@ if (highlighter != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { - highlighter.viewLine(line); + highlighter.viewLine(line - 1); if (!window.isVisible()) { window.setVisible(true); } @@ -178,21 +180,21 @@ } } - private String findSourceFile(String fPath, String filename) { + private File findSourceFile(String fPath, String filename) { File fp = new File(fPath, filename); if (fp.exists()) { - return fp.getAbsolutePath(); + return fp; } fp = new File(filename); if (fp.exists()) { - return filename; + return fp; } if (path != null) { for(File p : path) { File nfp = new File(p, filename); if (nfp.exists()) { - return nfp.getAbsolutePath(); + return nfp; } } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 21:37:27
|
Revision: 59 http://mspsim.svn.sourceforge.net/mspsim/?rev=59&view=rev Author: joxe Date: 2007-12-06 13:37:25 -0800 (Thu, 06 Dec 2007) Log Message: ----------- fixed selection of line in highligter to be behind text Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:37:11 UTC (rev 58) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 21:37:25 UTC (rev 59) @@ -65,6 +65,9 @@ } }); + + setOpaque(false); + } public int getColumns() { @@ -227,20 +230,21 @@ private int smallAmount = 100; - private Color highlightColor = new Color(0, 240, 0, 127); + private Color highlightColor = new Color(0, 240, 0, 255); /** * <font style='color:gray;'>Ignore this method. Carries out a small amount of * re-highlighting for each call to <code>repaint</code>.</font> */ protected void paintComponent(Graphics g) { - super.paintComponent(g); - if (currentHeight > 0) { g.setColor(highlightColor); g.fillRect(0, currentY, getWidth(), currentHeight); } + super.paintComponent(g); + + int offset = scanner.position(); if (offset < 0) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:37:14
|
Revision: 58 http://mspsim.svn.sourceforge.net/mspsim/?rev=58&view=rev Author: nifi Date: 2007-12-06 12:37:11 -0800 (Thu, 06 Dec 2007) Log Message: ----------- only show window if not already visible Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:32:10 UTC (rev 57) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:37:11 UTC (rev 58) @@ -137,7 +137,9 @@ // Workaround for bug 4782232 in Java 1.4 highlighter.setCaretPosition(1); highlighter.setCaretPosition(0); - window.setVisible(true); + if (!window.isVisible()) { + window.setVisible(true); + } } finally { reader.close(); } @@ -155,7 +157,9 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { highlighter.viewLine(line); - window.setVisible(true); + if (!window.isVisible()) { + window.setVisible(true); + } } }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 20:32:18
|
Revision: 57 http://mspsim.svn.sourceforge.net/mspsim/?rev=57&view=rev Author: joxe Date: 2007-12-06 12:32:10 -0800 (Thu, 06 Dec 2007) Log Message: ----------- fixed colors Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:29:59 UTC (rev 56) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:32:10 UTC (rev 57) @@ -227,7 +227,7 @@ private int smallAmount = 100; - private Color highlightColor = new Color(220, 220, 255, 155); + private Color highlightColor = new Color(0, 240, 0, 127); /** * <font style='color:gray;'>Ignore this method. Carries out a small amount of This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:30:01
|
Revision: 56 http://mspsim.svn.sourceforge.net/mspsim/?rev=56&view=rev Author: nifi Date: 2007-12-06 12:29:59 -0800 (Thu, 06 Dec 2007) Log Message: ----------- restored Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:17:21 UTC (rev 55) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:29:59 UTC (rev 56) @@ -154,7 +154,7 @@ if (highlighter != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { - highlighter.viewLine(line + 1); + highlighter.viewLine(line); window.setVisible(true); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:17:25
|
Revision: 55 http://mspsim.svn.sourceforge.net/mspsim/?rev=55&view=rev Author: nifi Date: 2007-12-06 12:17:21 -0800 (Thu, 06 Dec 2007) Log Message: ----------- minor optimization Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:17:05 UTC (rev 54) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:17:21 UTC (rev 55) @@ -284,14 +284,12 @@ // Quick fix to position the line somewhere in the center Rectangle r = getUI().modelToView(this, pos); if (r != null && r.height > 0) { - int y = r.y; - r = getVisibleRect(); - y -= r.height / 2; - if (y < 0) { - y = 0; + Rectangle vr = getVisibleRect(); + vr.y = r.y - vr.height / 2; + if (vr.y < 0) { + vr.y = 0; } - scrollRectToVisible(new Rectangle(0, y + r.height, 1, 1)); - scrollRectToVisible(new Rectangle(0, y, 1, 1)); + scrollRectToVisible(vr); } setCaretPosition(pos); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:17:12
|
Revision: 54 http://mspsim.svn.sourceforge.net/mspsim/?rev=54&view=rev Author: nifi Date: 2007-12-06 12:17:05 -0800 (Thu, 06 Dec 2007) Log Message: ----------- off by one Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:15:36 UTC (rev 53) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:17:05 UTC (rev 54) @@ -154,7 +154,7 @@ if (highlighter != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { - highlighter.viewLine(line); + highlighter.viewLine(line + 1); window.setVisible(true); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:15:41
|
Revision: 53 http://mspsim.svn.sourceforge.net/mspsim/?rev=53&view=rev Author: nifi Date: 2007-12-06 12:15:36 -0800 (Thu, 06 Dec 2007) Log Message: ----------- keywords Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java Modified: mspsim/se/sics/mspsim/extutil/highlight/CScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 20:05:17 UTC (rev 52) +++ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 20:15:36 UTC (rev 53) @@ -643,14 +643,10 @@ // Override initSymbolTable protected void initSymbolTable() { - lookup(KEYWORD, "abstract"); - lookup(KEYWORD, "assert"); - lookup(KEYWORD, "boolean"); + lookup(KEYWORD, "auto"); + lookup(KEYWORD, "asm"); lookup(KEYWORD, "break"); - lookup(KEYWORD, "byte"); lookup(KEYWORD, "case"); - lookup(KEYWORD, "catch"); - lookup(KEYWORD, "class"); lookup(KEYWORD, "const"); lookup(KEYWORD, "continue"); lookup(KEYWORD, "default"); @@ -660,30 +656,26 @@ lookup(KEYWORD, "else"); lookup(KEYWORD, "endif"); lookup(KEYWORD, "enum"); - lookup(KEYWORD, "extends"); lookup(KEYWORD, "extern"); lookup(KEYWORD, "for"); lookup(KEYWORD, "goto"); lookup(KEYWORD, "if"); lookup(KEYWORD, "ifdef"); lookup(KEYWORD, "ifndef"); + lookup(KEYWORD, "inline"); lookup(KEYWORD, "include"); - lookup(KEYWORD, "new"); lookup(KEYWORD, "private"); lookup(KEYWORD, "protected"); lookup(KEYWORD, "public"); + lookup(KEYWORD, "register"); lookup(KEYWORD, "return"); - lookup(KEYWORD, "short"); + lookup(KEYWORD, "sizeof"); lookup(KEYWORD, "static"); lookup(KEYWORD, "struct"); lookup(KEYWORD, "super"); lookup(KEYWORD, "switch"); - lookup(KEYWORD, "synchronized"); - lookup(KEYWORD, "this"); - lookup(KEYWORD, "throw"); - lookup(KEYWORD, "throws"); - lookup(KEYWORD, "transient"); - lookup(KEYWORD, "try"); + lookup(KEYWORD, "typedef"); + lookup(KEYWORD, "union"); lookup(KEYWORD, "volatile"); lookup(KEYWORD, "while"); @@ -705,9 +697,9 @@ lookup(LITERAL, "double"); lookup(LITERAL, "void"); lookup(LITERAL, "unsigned"); + lookup(LITERAL, "signed"); lookup(LITERAL, "char"); lookup(LITERAL, "short"); - } // *** Override lookup, but what about unicode escape translation? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 20:05:25
|
Revision: 52 http://mspsim.svn.sourceforge.net/mspsim/?rev=52&view=rev Author: joxe Date: 2007-12-06 12:05:17 -0800 (Thu, 06 Dec 2007) Log Message: ----------- updated highlight Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java Modified: mspsim/se/sics/mspsim/extutil/highlight/CScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 19:59:47 UTC (rev 51) +++ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 20:05:17 UTC (rev 52) @@ -650,22 +650,24 @@ lookup(KEYWORD, "byte"); lookup(KEYWORD, "case"); lookup(KEYWORD, "catch"); - lookup(KEYWORD, "char"); lookup(KEYWORD, "class"); lookup(KEYWORD, "const"); lookup(KEYWORD, "continue"); lookup(KEYWORD, "default"); + lookup(KEYWORD, "define"); lookup(KEYWORD, "do"); lookup(KEYWORD, "double"); lookup(KEYWORD, "else"); + lookup(KEYWORD, "endif"); lookup(KEYWORD, "enum"); lookup(KEYWORD, "extends"); - lookup(KEYWORD, "float"); + lookup(KEYWORD, "extern"); lookup(KEYWORD, "for"); lookup(KEYWORD, "goto"); lookup(KEYWORD, "if"); - lookup(KEYWORD, "int"); - lookup(KEYWORD, "long"); + lookup(KEYWORD, "ifdef"); + lookup(KEYWORD, "ifndef"); + lookup(KEYWORD, "include"); lookup(KEYWORD, "new"); lookup(KEYWORD, "private"); lookup(KEYWORD, "protected"); @@ -673,6 +675,7 @@ lookup(KEYWORD, "return"); lookup(KEYWORD, "short"); lookup(KEYWORD, "static"); + lookup(KEYWORD, "struct"); lookup(KEYWORD, "super"); lookup(KEYWORD, "switch"); lookup(KEYWORD, "synchronized"); @@ -681,7 +684,6 @@ lookup(KEYWORD, "throws"); lookup(KEYWORD, "transient"); lookup(KEYWORD, "try"); - lookup(KEYWORD, "void"); lookup(KEYWORD, "volatile"); lookup(KEYWORD, "while"); @@ -697,6 +699,15 @@ lookup(LITERAL, "u8_t"); lookup(LITERAL, "u16_t"); lookup(LITERAL, "u32_t"); + lookup(LITERAL, "int"); + lookup(LITERAL, "long"); + lookup(LITERAL, "float"); + lookup(LITERAL, "double"); + lookup(LITERAL, "void"); + lookup(LITERAL, "unsigned"); + lookup(LITERAL, "char"); + lookup(LITERAL, "short"); + } // *** Override lookup, but what about unicode escape translation? Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 19:59:47 UTC (rev 51) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 20:05:17 UTC (rev 52) @@ -129,7 +129,7 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { try { - String file = findSourceFile(filename); + String file = findSourceFile(path, filename); if (file != null) { FileReader reader = new FileReader(file); try { @@ -174,11 +174,16 @@ } } - private String findSourceFile(String filename) { - File fp = new File(filename); + private String findSourceFile(String fPath, String filename) { + File fp = new File(fPath, filename); if (fp.exists()) { + return fp.getAbsolutePath(); + } + fp = new File(filename); + if (fp.exists()) { return filename; } + if (path != null) { for(File p : path) { File nfp = new File(p, filename); @@ -199,7 +204,7 @@ File d = fileChooser.getSelectedFile(); if (d != null) { path.add(d); - return findSourceFile(filename); + return findSourceFile(fPath, filename); } return null; } Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 19:59:47 UTC (rev 51) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 20:05:17 UTC (rev 52) @@ -15,7 +15,7 @@ */ public class SyntaxHighlighter extends JTextPane implements DocumentListener, TokenTypes { - + private static final long serialVersionUID = -1801145479677890566L; private StyledDocument doc; @@ -57,13 +57,13 @@ } else { currentHeight = -1; } - + } catch (BadLocationException e1) { // Ignore } - } + } } - + }); } @@ -113,26 +113,26 @@ private void initStyles() { styles = new Style[typeNames.length]; - changeStyle(UNRECOGNIZED, Color.red); + changeStyle(UNRECOGNIZED, Color.black); changeStyle(WHITESPACE, Color.black); changeStyle(WORD, Color.black); - changeStyle(NUMBER, Color.orange.darker()); - changeStyle(PUNCTUATION, Color.orange.darker()); - changeStyle(COMMENT, Color.green.darker(), Font.ITALIC); - changeStyle(START_COMMENT, Color.green.darker(), Font.ITALIC); - changeStyle(MID_COMMENT, Color.green.darker(), Font.ITALIC); - changeStyle(END_COMMENT, Color.green.darker(), Font.ITALIC); + changeStyle(NUMBER, Color.black); + changeStyle(PUNCTUATION, Color.blue); + changeStyle(COMMENT, Color.red, Font.ITALIC); + changeStyle(START_COMMENT, new Color(178,34,34), Font.ITALIC); + changeStyle(MID_COMMENT, new Color(178,34,34), Font.ITALIC); + changeStyle(END_COMMENT, new Color(178,34,34), Font.ITALIC); changeStyle(TAG, Color.blue, Font.BOLD); changeStyle(END_TAG, Color.blue, Font.BOLD); - changeStyle(KEYWORD, Color.blue); - changeStyle(KEYWORD2, Color.blue); + changeStyle(KEYWORD, new Color(160,32,240)); + changeStyle(KEYWORD2, new Color(160,32,240)); changeStyle(IDENTIFIER, Color.black); - changeStyle(LITERAL, Color.magenta); - changeStyle(STRING, Color.magenta); - changeStyle(CHARACTER, Color.magenta); + changeStyle(LITERAL, Color.green.darker()); + changeStyle(STRING, new Color(188,143,143)); + changeStyle(CHARACTER, new Color(188,143,143)); changeStyle(OPERATOR, Color.black, Font.BOLD); - changeStyle(BRACKET, Color.orange.darker()); - changeStyle(SEPARATOR, Color.orange.darker()); + changeStyle(BRACKET, Color.black); + changeStyle(SEPARATOR, Color.black); changeStyle(URL, Color.blue.darker()); for (int i = 0; i < styles.length; i++) { Modified: mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java 2007-12-06 19:59:47 UTC (rev 51) +++ mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java 2007-12-06 20:05:17 UTC (rev 52) @@ -8,14 +8,14 @@ * states, and in highlighters to determine the colour or style of tokens. There * is also an array typeNames of textual names, indexed by type, for descriptive * purposes. - * + * * <p> * The UNRECOGNIZED constant (zero) is for tokens which are completely * unrecognized, usually consisting of a single illegal character. Other error * tokens are represented by negative types, where -t represents an incomplete * or malformed token of type t. An error token usually consists of the maximal * legal substring of the source text. - * + * * <p> * The WHITESPACE constant is used to classify tokens which are to be discarded, * it acts as a suitable scanner state at the beginning of a document, and it is @@ -23,12 +23,12 @@ * document. Comments can optionally be classified as WHITESPACE and discarded, * if they are not needed for highlighting. No other types besides UNRECOGNIZED * and WHITESPACE are treated specially. - * + * * <p> * The constants are presented as an interface so that any class can implement * the interface and use the names of the constants directly, without prefixing * them with a class name. - * + * */ public interface TokenTypes { public static final int UNRECOGNIZED = 0, WHITESPACE = 1, WORD = 2, @@ -37,6 +37,7 @@ KEYWORD2 = 12, IDENTIFIER = 13, LITERAL = 14, STRING = 15, CHARACTER = 16, OPERATOR = 17, BRACKET = 18, SEPARATOR = 19, URL = 20, DEFINE = 21; + /** * The names of the token types, indexed by type, are provided for descriptive * purposes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 20:00:00
|
Revision: 51 http://mspsim.svn.sourceforge.net/mspsim/?rev=51&view=rev Author: nifi Date: 2007-12-06 11:59:47 -0800 (Thu, 06 Dec 2007) Log Message: ----------- search path via Java system property and OS env variables Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 19:58:32 UTC (rev 50) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 19:59:47 UTC (rev 51) @@ -39,6 +39,7 @@ */ package se.sics.mspsim.extutil.highlight; +import java.awt.Color; import java.awt.Container; import java.io.File; import java.io.FileReader; @@ -61,6 +62,7 @@ private JFrame window; private SyntaxHighlighter highlighter; + private String currentFile; private ArrayList<File> path = null; private JFileChooser fileChooser; @@ -73,17 +75,39 @@ window = new JFrame("Source Viewer"); window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + LineNumberedBorder border = new LineNumberedBorder(LineNumberedBorder.LEFT_SIDE, LineNumberedBorder.RIGHT_JUSTIFY); + border.setSeparatorColor(Color.lightGray); + Scanner scanner = new CScanner(); highlighter = new SyntaxHighlighter(24, 120, scanner); - highlighter.setBorder(new LineNumberedBorder(LineNumberedBorder.LEFT_SIDE, LineNumberedBorder.RIGHT_JUSTIFY)); + highlighter.setEditable(false); + highlighter.setBorder(border); JScrollPane scroller = new JScrollPane(highlighter); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); Container pane = window.getContentPane(); pane.add(scroller); WindowUtils.restoreWindowBounds("SourceViewer", window); WindowUtils.addSaveOnShutdown("SourceViewer", window); + + String searchPath = System.getProperty("CONTIKI_PATH"); + if (searchPath != null) { + addEnvPath(searchPath); + } + searchPath = System.getenv("CONTIKI_PATH"); + if (searchPath != null) { + addEnvPath(searchPath); + } } } + + private void addEnvPath(String searchPath) { + String[] p = searchPath.split(File.pathSeparator); + if (p != null) { + for (int i = 0, n = p.length; i < n; i++) { + addSearchPath(new File(p[i])); + } + } + } public boolean isVisible() { return window != null && window.isVisible(); @@ -95,6 +119,12 @@ } public void viewFile(final String path, final String filename) { + if (filename.equals(currentFile)) { + // Already showing this file + return; + } + currentFile = filename; + setup(); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -107,6 +137,7 @@ // Workaround for bug 4782232 in Java 1.4 highlighter.setCaretPosition(1); highlighter.setCaretPosition(0); + window.setVisible(true); } finally { reader.close(); } @@ -123,20 +154,14 @@ if (highlighter != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { - if (line >= 0 && line < highlighter.getLineCount()) { - highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); - window.setVisible(true); - window.toFront(); - } + highlighter.viewLine(line); + window.setVisible(true); } }); } } public void addSearchPath(File directory) { - if (!directory.exists() || !directory.isDirectory()) { - throw new IllegalArgumentException(directory + " is not a directory"); - } if (path == null) { path = new ArrayList<File>(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 19:58:35
|
Revision: 50 http://mspsim.svn.sourceforge.net/mspsim/?rev=50&view=rev Author: nifi Date: 2007-12-06 11:58:32 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added simple highlight of active line + scroll to specific line Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 19:56:59 UTC (rev 49) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 19:58:32 UTC (rev 50) @@ -3,6 +3,7 @@ import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; + import java.io.*; // Public domain, no restrictions, Ian Holyer, University of Bristol. @@ -21,6 +22,8 @@ private Scanner scanner; private int rows, columns; + private int currentY, currentHeight = -1; + /** * Create a graphics component which displays text with syntax highlighting. * Provide a rows and columns, in characters, and a language scanner. @@ -35,6 +38,33 @@ Font font = new Font("Monospaced", Font.PLAIN, getFont().getSize()); changeFont(font); initStyles(); + + // Quick fix to highlight selected line + addCaretListener(new CaretListener() { + + public void caretUpdate(CaretEvent e) { + int caret = getCaretPosition(); + if (caret >= 0) { + try { + Rectangle r = getUI().modelToView(SyntaxHighlighter.this, caret); + if (currentHeight > 0) { + repaint(0, currentY, getWidth(), currentHeight); + } + if (r != null && r.height > 0) { + currentY = r.y; + currentHeight = r.height; + repaint(0, r.y, getWidth(), r.height); + } else { + currentHeight = -1; + } + + } catch (BadLocationException e1) { + // Ignore + } + } + } + + }); } public int getColumns() { @@ -88,10 +118,10 @@ changeStyle(WORD, Color.black); changeStyle(NUMBER, Color.orange.darker()); changeStyle(PUNCTUATION, Color.orange.darker()); - changeStyle(COMMENT, Color.green.darker()); - changeStyle(START_COMMENT, Color.green.darker()); - changeStyle(MID_COMMENT, Color.green.darker()); - changeStyle(END_COMMENT, Color.green.darker()); + changeStyle(COMMENT, Color.green.darker(), Font.ITALIC); + changeStyle(START_COMMENT, Color.green.darker(), Font.ITALIC); + changeStyle(MID_COMMENT, Color.green.darker(), Font.ITALIC); + changeStyle(END_COMMENT, Color.green.darker(), Font.ITALIC); changeStyle(TAG, Color.blue, Font.BOLD); changeStyle(END_TAG, Color.blue, Font.BOLD); changeStyle(KEYWORD, Color.blue); @@ -157,6 +187,7 @@ return root.getElement(line).getEndOffset(); } + /** * <font style='color:gray;'>Ignore this method. Responds to the underlying * document changes by re-highlighting.</font> @@ -196,12 +227,20 @@ private int smallAmount = 100; + private Color highlightColor = new Color(220, 220, 255, 155); + /** * <font style='color:gray;'>Ignore this method. Carries out a small amount of * re-highlighting for each call to <code>repaint</code>.</font> */ protected void paintComponent(Graphics g) { super.paintComponent(g); + + if (currentHeight > 0) { + g.setColor(highlightColor); + g.fillRect(0, currentY, getWidth(), currentHeight); + } + int offset = scanner.position(); if (offset < 0) return; @@ -236,4 +275,29 @@ repaint(2); } } + + public void viewLine(int line) { + if (line >= 0 && line < getLineCount()) { + try { + int pos = getLineStartOffset(line); + + // Quick fix to position the line somewhere in the center + Rectangle r = getUI().modelToView(this, pos); + if (r != null && r.height > 0) { + int y = r.y; + r = getVisibleRect(); + y -= r.height / 2; + if (y < 0) { + y = 0; + } + scrollRectToVisible(new Rectangle(0, y + r.height, 1, 1)); + scrollRectToVisible(new Rectangle(0, y, 1, 1)); + } + + setCaretPosition(pos); + } catch (BadLocationException e1) { + // Ignore + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 19:57:05
|
Revision: 49 http://mspsim.svn.sourceforge.net/mspsim/?rev=49&view=rev Author: nifi Date: 2007-12-06 11:56:59 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added define for c-style Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java Modified: mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java 2007-12-06 19:53:46 UTC (rev 48) +++ mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java 2007-12-06 19:56:59 UTC (rev 49) @@ -35,7 +35,7 @@ NUMBER = 3, PUNCTUATION = 4, COMMENT = 5, START_COMMENT = 6, MID_COMMENT = 7, END_COMMENT = 8, TAG = 9, END_TAG = 10, KEYWORD = 11, KEYWORD2 = 12, IDENTIFIER = 13, LITERAL = 14, STRING = 15, - CHARACTER = 16, OPERATOR = 17, BRACKET = 18, SEPARATOR = 19, URL = 20; + CHARACTER = 16, OPERATOR = 17, BRACKET = 18, SEPARATOR = 19, URL = 20, DEFINE = 21; /** * The names of the token types, indexed by type, are provided for descriptive @@ -45,6 +45,6 @@ "bad token", "whitespace", "word", "number", "punctuation", "comment", "start of comment", "middle of comment", "end of comment", "tag", "end tag", "keyword", "keyword 2", "identifier", "literal", "string", - "character", "operator", "bracket", "separator", "url" + "character", "operator", "bracket", "separator", "url", "define" }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 19:53:47
|
Revision: 48 http://mspsim.svn.sourceforge.net/mspsim/?rev=48&view=rev Author: nifi Date: 2007-12-06 11:53:46 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added optional separator Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java Modified: mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java 2007-12-06 18:18:23 UTC (rev 47) +++ mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java 2007-12-06 19:53:46 UTC (rev 48) @@ -1,4 +1,5 @@ package se.sics.mspsim.extutil.highlight; +import java.awt.Color; import java.awt.Component; import java.awt.FontMetrics; import java.awt.Graphics; @@ -49,6 +50,8 @@ */ private int location = LEFT_SIDE; + private Color separatorColor = null; + public LineNumberedBorder(int location, int justify) { setLocation(location); setLineNumberJustification(justify); @@ -101,6 +104,14 @@ } } + public Color getSeparatorColor() { + return separatorColor; + } + + public void setSeparatorColor(Color c) { + this.separatorColor = c; + } + /** * Returns the width, in pixels, of the maximum line number, plus a trailing * space. @@ -227,6 +238,15 @@ ybaseline += fontHeight; startingLineNumber++; } + if (separatorColor != null) { + g.setColor(separatorColor); + if (location == LEFT_SIDE) { + lnxstart = x + lineWidth - 1; + } else { + lnxstart = width - lineWidth; + } + g.drawLine(lnxstart, 0, lnxstart, height); + } } // paintComponent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 18:18:24
|
Revision: 47 http://mspsim.svn.sourceforge.net/mspsim/?rev=47&view=rev Author: joxe Date: 2007-12-06 10:18:23 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added path argument to SourceViewer Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/SourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 18:18:23 UTC (rev 47) @@ -63,7 +63,7 @@ private SyntaxHighlighter highlighter; private ArrayList<File> path = null; private JFileChooser fileChooser; - + public HighlightSourceViewer() { // } @@ -94,7 +94,7 @@ window.setVisible(isVisible); } - public void viewFile(final String filename) { + public void viewFile(final String path, final String filename) { setup(); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -182,6 +182,6 @@ public static void main(String[] args) { HighlightSourceViewer sv = new HighlightSourceViewer(); sv.setVisible(true); - sv.viewFile(args[0]); + sv.viewFile(".", args[0]); } } Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 18:18:23 UTC (rev 47) @@ -182,7 +182,7 @@ DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { if (sourceViewer != null) { - sourceViewer.viewFile(dbg.getFile()); + sourceViewer.viewFile(dbg.getPath(), dbg.getFile()); sourceViewer.viewLine(dbg.getLine()); } else { System.out.println("File: " + dbg.getFile()); Modified: mspsim/se/sics/mspsim/util/SourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/util/SourceViewer.java 2007-12-06 17:44:44 UTC (rev 46) +++ mspsim/se/sics/mspsim/util/SourceViewer.java 2007-12-06 18:18:23 UTC (rev 47) @@ -43,7 +43,7 @@ public interface SourceViewer { - public void viewFile(String file); + public void viewFile(String path, String file); public void viewLine(int line); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:44:46
|
Revision: 46 http://mspsim.svn.sourceforge.net/mspsim/?rev=46&view=rev Author: nifi Date: 2007-12-06 09:44:44 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added possibility to set a search path Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:32:27 UTC (rev 45) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:44:44 UTC (rev 46) @@ -119,6 +119,36 @@ }); } + public void viewLine(final int line) { + if (highlighter != null) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (line >= 0 && line < highlighter.getLineCount()) { + highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); + window.setVisible(true); + window.toFront(); + } + } + }); + } + } + + public void addSearchPath(File directory) { + if (!directory.exists() || !directory.isDirectory()) { + throw new IllegalArgumentException(directory + " is not a directory"); + } + if (path == null) { + path = new ArrayList<File>(); + } + path.add(directory); + } + + public void removeSearchPath(File directory) { + if (path != null) { + path.remove(directory); + } + } + private String findSourceFile(String filename) { File fp = new File(filename); if (fp.exists()) { @@ -149,20 +179,6 @@ return null; } - public void viewLine(final int line) { - if (highlighter != null) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (line >= 0 && line < highlighter.getLineCount()) { - highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); - window.setVisible(true); - window.toFront(); - } - } - }); - } - } - public static void main(String[] args) { HighlightSourceViewer sv = new HighlightSourceViewer(); sv.setVisible(true); Modified: mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 17:32:27 UTC (rev 45) +++ mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java 2007-12-06 17:44:44 UTC (rev 46) @@ -23,7 +23,7 @@ /** * Create a graphics component which displays text with syntax highlighting. - * Provide a width and height, in characters, and a language scanner. + * Provide a rows and columns, in characters, and a language scanner. */ public SyntaxHighlighter(int rows, int columns, Scanner scanner) { super(new DefaultStyledDocument()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:32:29
|
Revision: 45 http://mspsim.svn.sourceforge.net/mspsim/?rev=45&view=rev Author: nifi Date: 2007-12-06 09:32:27 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added highlight package Modified Paths: -------------- mspsim/Makefile Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2007-12-06 17:31:58 UTC (rev 44) +++ mspsim/Makefile 2007-12-06 17:32:27 UTC (rev 45) @@ -64,7 +64,7 @@ BINARY := README.txt license.txt images/*.jpg firmware/*/*.firmware -PACKAGES := ${addprefix se/sics/mspsim/,core platform/esb platform/sky util chip} +PACKAGES := ${addprefix se/sics/mspsim/,core platform/esb platform/sky util chip extutil/highlight} SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:32:00
|
Revision: 44 http://mspsim.svn.sourceforge.net/mspsim/?rev=44&view=rev Author: nifi Date: 2007-12-06 09:31:58 -0800 (Thu, 06 Dec 2007) Log Message: ----------- ask user for compilation directory Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:10:41 UTC (rev 43) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:31:58 UTC (rev 44) @@ -39,11 +39,13 @@ */ package se.sics.mspsim.extutil.highlight; - import java.awt.Container; +import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; +import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JScrollPane; @@ -59,6 +61,8 @@ private JFrame window; private SyntaxHighlighter highlighter; + private ArrayList<File> path = null; + private JFileChooser fileChooser; public HighlightSourceViewer() { // @@ -90,28 +94,61 @@ window.setVisible(isVisible); } - public void viewFile(final String file) { + public void viewFile(final String filename) { setup(); SwingUtilities.invokeLater(new Runnable() { public void run() { try { - FileReader reader = new FileReader(file); - try { - highlighter.read(reader, null); - // Workaround for bug 4782232 in Java 1.4 - highlighter.setCaretPosition(1); - highlighter.setCaretPosition(0); - } finally { - reader.close(); + String file = findSourceFile(filename); + if (file != null) { + FileReader reader = new FileReader(file); + try { + highlighter.read(reader, null); + // Workaround for bug 4782232 in Java 1.4 + highlighter.setCaretPosition(1); + highlighter.setCaretPosition(0); + } finally { + reader.close(); + } } } catch (IOException err) { err.printStackTrace(); - JOptionPane.showMessageDialog(window, "Failed to read the file '" + file + '\'', "Could not read file", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(window, "Failed to read the file '" + filename + '\'', "Could not read file", JOptionPane.ERROR_MESSAGE); } } }); } + private String findSourceFile(String filename) { + File fp = new File(filename); + if (fp.exists()) { + return filename; + } + if (path != null) { + for(File p : path) { + File nfp = new File(p, filename); + if (nfp.exists()) { + return nfp.getAbsolutePath(); + } + } + } else { + path = new ArrayList<File>(); + } + // Find new path to search from + if (fileChooser == null) { + fileChooser = new JFileChooser("./"); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.setDialogTitle("Select compilation directory"); + } + fileChooser.showOpenDialog(window); + File d = fileChooser.getSelectedFile(); + if (d != null) { + path.add(d); + return findSourceFile(filename); + } + return null; + } + public void viewLine(final int line) { if (highlighter != null) { SwingUtilities.invokeLater(new Runnable() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:10:44
|
Revision: 43 http://mspsim.svn.sourceforge.net/mspsim/?rev=43&view=rev Author: nifi Date: 2007-12-06 09:10:41 -0800 (Thu, 06 Dec 2007) Log Message: ----------- setup higlight source viewer Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyNode.java Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 17:10:11 UTC (rev 42) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 17:10:41 UTC (rev 43) @@ -44,6 +44,7 @@ import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.core.*; +import se.sics.mspsim.extutil.highlight.HighlightSourceViewer; import se.sics.mspsim.util.*; /** @@ -188,6 +189,8 @@ SkyNode node = new SkyNode(cpu); node.gui = new SkyGui(node); ControlUI control = new ControlUI(cpu, elf); + HighlightSourceViewer sourceViewer = new HighlightSourceViewer(); + control.setSourceViewer(sourceViewer); if (args.length > 1) { MapTable map = new MapTable(args[1]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:10:14
|
Revision: 42 http://mspsim.svn.sourceforge.net/mspsim/?rev=42&view=rev Author: nifi Date: 2007-12-06 09:10:11 -0800 (Thu, 06 Dec 2007) Log Message: ----------- make sure window is visible when ordered to display a specific line Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:07:51 UTC (rev 41) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 17:10:11 UTC (rev 42) @@ -70,7 +70,7 @@ window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Scanner scanner = new CScanner(); - highlighter = new SyntaxHighlighter(24, 80, scanner); + highlighter = new SyntaxHighlighter(24, 120, scanner); highlighter.setBorder(new LineNumberedBorder(LineNumberedBorder.LEFT_SIDE, LineNumberedBorder.RIGHT_JUSTIFY)); JScrollPane scroller = new JScrollPane(highlighter); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); @@ -118,6 +118,8 @@ public void run() { if (line >= 0 && line < highlighter.getLineCount()) { highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); + window.setVisible(true); + window.toFront(); } } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 17:07:53
|
Revision: 41 http://mspsim.svn.sourceforge.net/mspsim/?rev=41&view=rev Author: nifi Date: 2007-12-06 09:07:51 -0800 (Thu, 06 Dec 2007) Log Message: ----------- Changed setSourceViewer to be public Modified Paths: -------------- mspsim/se/sics/mspsim/util/ControlUI.java Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 16:48:22 UTC (rev 40) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 17:07:51 UTC (rev 41) @@ -127,7 +127,7 @@ elfData = elf; } - private void setSourceViewer(SourceViewer viewer) { + public void setSourceViewer(SourceViewer viewer) { sourceViewer = viewer; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 16:48:24
|
Revision: 40 http://mspsim.svn.sourceforge.net/mspsim/?rev=40&view=rev Author: nifi Date: 2007-12-06 08:48:22 -0800 (Thu, 06 Dec 2007) Log Message: ----------- Save and restore window position between restarts Modified Paths: -------------- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java Modified: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 16:40:33 UTC (rev 39) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 16:48:22 UTC (rev 40) @@ -50,6 +50,7 @@ import javax.swing.SwingUtilities; import se.sics.mspsim.util.SourceViewer; +import se.sics.mspsim.util.WindowUtils; /** * @@ -75,7 +76,8 @@ scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); Container pane = window.getContentPane(); pane.add(scroller); - window.pack(); + WindowUtils.restoreWindowBounds("SourceViewer", window); + WindowUtils.addSaveOnShutdown("SourceViewer", window); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2007-12-06 16:40:36
|
Revision: 39 http://mspsim.svn.sourceforge.net/mspsim/?rev=39&view=rev Author: nifi Date: 2007-12-06 08:40:33 -0800 (Thu, 06 Dec 2007) Log Message: ----------- highlighting c source viewer Added Paths: ----------- mspsim/se/sics/mspsim/extutil/ mspsim/se/sics/mspsim/extutil/highlight/ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java mspsim/se/sics/mspsim/extutil/highlight/Scan.java mspsim/se/sics/mspsim/extutil/highlight/Scanner.java mspsim/se/sics/mspsim/extutil/highlight/Symbol.java mspsim/se/sics/mspsim/extutil/highlight/SyntaxHighlighter.java mspsim/se/sics/mspsim/extutil/highlight/TextScanner.java mspsim/se/sics/mspsim/extutil/highlight/Token.java mspsim/se/sics/mspsim/extutil/highlight/TokenTypes.java Added: mspsim/se/sics/mspsim/extutil/highlight/CScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/CScanner.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/CScanner.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,944 @@ +package se.sics.mspsim.extutil.highlight; +// Public domain, no restrictions, Ian Holyer, University of Bristol. + +/** + * <p> + * Provide a hand-written scanner for the Java language. + */ + +public class CScanner extends Scanner { + + private boolean debug = false; + + /** Create a Java scanner, for Java version 1.5 by default. */ + public CScanner() { + super(); + initKind(); + initUniKind(); + } + + /** Create a Java scanner, for a given version between "1.1" and "1.5". */ + public CScanner(String version) { + super(); + initKind(); + initUniKind(); + } + + /** Override the read method from the Scanner class. */ + protected int read() { + int type, saveStart = 0; + if (debug) + saveStart = start; + + if (start >= end) + return WHITESPACE; + + switch (state) { + case MID_COMMENT: + case END_COMMENT: + type = readComment(MID_COMMENT); + if (type == END_COMMENT) + state = WHITESPACE; + else + state = MID_COMMENT; + return type; + default: + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c < 128) + type = kind[c]; + else + type = unikind[Character.getType(c)]; + switch (type) { + case WHITESPACE: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != WHITESPACE) + break; + start = start + charlength; + charlength = 1; + } + break; + case UNRECOGNIZED: + case BRACKET: + case SEPARATOR: + start = start + charlength; + charlength = 1; + break; + case OPERATOR: + start = start + charlength; + charlength = 1; + type = readOperator(c); + break; + case CHARACTER: + start = start + charlength; + charlength = 1; + type = readCharLiteral(); + break; + case STRING: + start = start + charlength; + charlength = 1; + type = readStringLiteral(); + break; + case IDENTIFIER: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != IDENTIFIER && k != NUMBER) + break; + start = start + charlength; + charlength = 1; + } + break; + case NUMBER: + start = start + charlength; + charlength = 1; + type = readNumber(c); + break; + case PUNCTUATION: + start = start + charlength; + charlength = 1; + type = readDot(); + break; + case COMMENT: + start = start + charlength; + charlength = 1; + type = readSlash(); + if (type == START_COMMENT) + state = MID_COMMENT; + break; + } + } + if (debug) { + System.out.print(TokenTypes.typeNames[type]); + System.out.println(" " + saveStart + "," + end + "(" + + (start - saveStart) + ")"); + } + return type; + } + + private int readOperator(char c) { + if (start >= end) + return OPERATOR; + char c2; + + switch (c) { + case '~': + case '?': + case ':': + break; + case '+': + case '-': + case '&': + case '|': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != c && c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '=': + case '*': + case '!': + case '^': + case '%': + case '/': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '<': + case '>': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 == '=') { + start = start + charlength; + charlength = 1; + } else if (c2 == c) { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 == '=') { + start = start + charlength; + charlength = 1; + } else if (c == '>' && c3 == '>') // >>> + { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c4 = buffer[start]; + if (c4 == '\\') + c4 = next(); + if (c4 != '=') + break; + start = start + charlength; + charlength = 1; + } + } + break; + } + return OPERATOR; + } + + private int readCharLiteral() { + if (start >= end) + return bad(CHARACTER); + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(CHARACTER); + break; + case '\'': + case '\n': + return bad(CHARACTER); + default: + start = start + charlength; + charlength = 1; + break; + } + if (start >= end) + return bad(CHARACTER); + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 != '\'') + return bad(CHARACTER); + start = start + charlength; + charlength = 1; + return CHARACTER; + } + + private int readStringLiteral() { + if (start >= end) + return bad(STRING); + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (c != '"') { + switch (c) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(STRING); + break; + case '\n': + return bad(STRING); + default: + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(STRING); + break; + } + c = buffer[start]; + if (c == '\\') + c = next(); + } + if (c != '"') + return bad(STRING); + start = start + charlength; + charlength = 1; + return STRING; + } + + private int readSlash() { + if (start >= end) + return OPERATOR; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + while (c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return COMMENT; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + return COMMENT; + } else if (c == '*') { + start = start + charlength; + charlength = 1; + return readComment(START_COMMENT); + } + return readOperator('/'); + } + + // Read one line of a /*...*/ comment, given the expected type + int readComment(int type) { + if (start >= end) + return type; + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (true) { + while (c != '*' && c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + if (c == '\n') + return type; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + start = start + charlength; + charlength = 1; + if (type == START_COMMENT) { + return COMMENT; + } + return END_COMMENT; + } + } + } + + // Read a number, without checking whether it is out of range + // Doesn't deal with e.g. 0777.9 or 07779f + private int readNumber(char c) { + if (c == '0') { + int saveStart = start, saveLength = charlength; + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + switch (c2) { + case 'x': + case 'X': + start = start + charlength; + charlength = 1; + boolean ok = readDigits(16); + if (!ok) + return bad(NUMBER); + readSuffix(); + return NUMBER; + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + readDigits(8); + readSuffix(); + return NUMBER; + case '.': + case 'e': + case 'E': + start = saveStart; + charlength = saveLength; + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + boolean hasDigits = false; + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == 'l' || c == 'L') { + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + if (c == '.') { + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + } + } + if (!hasDigits) + return bad(NUMBER); + switch (c) { + case 'e': + case 'E': + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '+' || c == '-') { + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + } + readDigits(10); + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + } + return NUMBER; + } + + boolean readDigits(int radix) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (Character.digit(c, radix) == -1) + return false; + while (Character.digit(c, radix) != -1) { + start = start + charlength; + charlength = 1; + if (start >= end) + return true; + c = buffer[start]; + if (c == '\\') + c = next(); + } + return true; + } + + void readSuffix() { + if (start >= end) + return; + char c = buffer[start]; + if (c == '\\') + c = next(); + switch (c) { + case 'f': + case 'F': + case 'd': + case 'D': + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + } + } + + private int readDot() { + if (start >= end) + return SEPARATOR; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (Character.isDigit(c2)) { + return readNumber('.'); + } + if (start + 1 >= end) // || version < 15) + return SEPARATOR; + if (c2 != '.' || buffer[start + 1] != '.') + return SEPARATOR; + start = start + 2; + return SEPARATOR; + } + + private boolean readEscapeSequence() { + if (start >= end) + return false; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case 'b': + case 't': + case 'n': + case 'f': + case 'r': + case '\"': + case '\'': + case '\\': + start = start + charlength; + charlength = 1; + return true; + case '0': + case '1': + case '2': + case '3': + return readOctal(3); + case '4': + case '5': + case '6': + case '7': + return readOctal(2); + default: + return false; + } + } + + boolean readOctal(int maxlength) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + + int i, val = 0; + for (i = 0; i < maxlength; i++) { + if (Character.digit(c, 8) != -1) { + val = 8 * val + Character.digit(c, 8); + start = start + charlength; + charlength = 1; + if (start >= end) + break; + c = buffer[start]; + if (c == '\\') + c = next(); + } else + break; + } + if ((i == 0) || (val > 0xFF)) + return false; + return true; + } + + // A malformed or incomplete token has a negative type + private int bad(int type) { + return -type; + } + + // Look ahead at the next character or unicode escape. + // For efficiency, replace c = next(); with + // c = buffer[start]; if (c == '\\') c = next(); + // To accept the character after looking at it, use: + // start = start + charlength; charlength = 1; + + // Record the number of source code characters used up. To deal with an odd + // or even number of backslashes preceding a unicode escape, whenever a + // second backslash is coming up, mark its position as a pair. + + private int charlength = 1; + + private int pair = 0; + + private char next() { + if (start >= end) + return 26; // EOF + char c = buffer[start]; + if (c != '\\') + return c; + if (start == pair) { + pair = 0; + return '\\'; + } + if (start + 1 >= end) + return '\\'; + + c = buffer[start + 1]; + if (c == '\\') + pair = start + 1; + if (c != 'u') + return '\\'; + + int pos = start + 2; + while (pos < end && buffer[pos] == 'u') + pos++; + if (pos + 4 > end) { + charlength = end - start; + return '\0'; + } + + c = 0; + for (int j = 0; j < 4; j++) { + int d = Character.digit(buffer[pos + j], 16); + if (d < 0) { + charlength = pos + j - start; + return '\0'; + } + c = (char) (c * 16 + d); + } + charlength = pos + 4 - start; + return c; + } + + // Override initSymbolTable + + protected void initSymbolTable() { + lookup(KEYWORD, "abstract"); + lookup(KEYWORD, "assert"); + lookup(KEYWORD, "boolean"); + lookup(KEYWORD, "break"); + lookup(KEYWORD, "byte"); + lookup(KEYWORD, "case"); + lookup(KEYWORD, "catch"); + lookup(KEYWORD, "char"); + lookup(KEYWORD, "class"); + lookup(KEYWORD, "const"); + lookup(KEYWORD, "continue"); + lookup(KEYWORD, "default"); + lookup(KEYWORD, "do"); + lookup(KEYWORD, "double"); + lookup(KEYWORD, "else"); + lookup(KEYWORD, "enum"); + lookup(KEYWORD, "extends"); + lookup(KEYWORD, "float"); + lookup(KEYWORD, "for"); + lookup(KEYWORD, "goto"); + lookup(KEYWORD, "if"); + lookup(KEYWORD, "int"); + lookup(KEYWORD, "long"); + lookup(KEYWORD, "new"); + lookup(KEYWORD, "private"); + lookup(KEYWORD, "protected"); + lookup(KEYWORD, "public"); + lookup(KEYWORD, "return"); + lookup(KEYWORD, "short"); + lookup(KEYWORD, "static"); + lookup(KEYWORD, "super"); + lookup(KEYWORD, "switch"); + lookup(KEYWORD, "synchronized"); + lookup(KEYWORD, "this"); + lookup(KEYWORD, "throw"); + lookup(KEYWORD, "throws"); + lookup(KEYWORD, "transient"); + lookup(KEYWORD, "try"); + lookup(KEYWORD, "void"); + lookup(KEYWORD, "volatile"); + lookup(KEYWORD, "while"); + + lookup(LITERAL, "TRUE"); + lookup(LITERAL, "FALSE"); + lookup(LITERAL, "NULL"); + lookup(LITERAL, "int8_t"); + lookup(LITERAL, "int16_t"); + lookup(LITERAL, "int32_t"); + lookup(LITERAL, "uint8_t"); + lookup(LITERAL, "uint16_t"); + lookup(LITERAL, "uint32_t"); + lookup(LITERAL, "u8_t"); + lookup(LITERAL, "u16_t"); + lookup(LITERAL, "u32_t"); + } + + // *** Override lookup, but what about unicode escape translation? + + private Symbol temp = new Symbol(0, null); + + protected Symbol lookup(int type, String name) { + if (type != IDENTIFIER) + return super.lookup(type, name); + temp.type = KEYWORD; + temp.name = name; + Symbol sym = symbolTable.get(temp); + if (sym != null) + return sym; + temp.type = LITERAL; + sym = symbolTable.get(temp); + if (sym != null) + return sym; + return super.lookup(type, name); + } + + // Classify the ascii characters using an array of kinds, and classify all + // other unicode characters using an array indexed by unicode category. + // See the source file java/lang/Character.java for the categories. + // To find the classification of a character, use: + // if (c < 128) k = kind[c]; else k = unikind[Character.getType(c)]; + + private static final byte[] kind = new byte[128]; + + private static final byte[] unikind = new byte[31]; + + // Initialise the two classification arrays using static initializer code. + // Token types from the TokenTypes class are used to classify characters. + + private void initKind() { + for (char c = 0; c < 128; c++) + kind[c] = -1; + for (char c = 0; c < 128; c++) + switch (c) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 11: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 27: + case 28: + case 29: + case 30: + case 31: + case 127: + case '#': + case '@': + case '`': + case '\\': + kind[c] = UNRECOGNIZED; + break; + case '\t': + case '\n': + case ' ': + case '\f': + case 26: + kind[c] = WHITESPACE; + break; + case '!': + case '%': + case '&': + case '*': + case '+': + case '-': + case ':': + case '<': + case '=': + case '>': + case '?': + case '^': + case '|': + case '~': + kind[c] = OPERATOR; + break; + case '"': + kind[c] = STRING; + break; + case '\'': + kind[c] = CHARACTER; + break; + case '.': + kind[c] = PUNCTUATION; + break; + case '/': + kind[c] = COMMENT; + break; + case '$': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + kind[c] = IDENTIFIER; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + kind[c] = NUMBER; + break; + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + kind[c] = BRACKET; + break; + case ',': + case ';': + kind[c] = SEPARATOR; + break; + } + for (char c = 0; c < 128; c++) + if (kind[c] == -1) + System.out.println("Char " + ((int) c) + " hasn't been classified"); + } + + private void initUniKind() { + for (byte b = 0; b < 31; b++) + unikind[b] = -1; + for (byte b = 0; b < 31; b++) + switch (b) { + case Character.UNASSIGNED: + case Character.ENCLOSING_MARK: + case Character.OTHER_NUMBER: + case Character.SPACE_SEPARATOR: + case Character.LINE_SEPARATOR: + case Character.PARAGRAPH_SEPARATOR: + case Character.CONTROL: + case 17: // category 17 is unused + case Character.PRIVATE_USE: + case Character.SURROGATE: + case Character.DASH_PUNCTUATION: + case Character.START_PUNCTUATION: + case Character.END_PUNCTUATION: + case Character.OTHER_PUNCTUATION: + case Character.MATH_SYMBOL: + case Character.MODIFIER_SYMBOL: + case Character.OTHER_SYMBOL: + case Character.INITIAL_QUOTE_PUNCTUATION: + case Character.FINAL_QUOTE_PUNCTUATION: + unikind[b] = UNRECOGNIZED; + break; + case Character.UPPERCASE_LETTER: + case Character.LOWERCASE_LETTER: + case Character.TITLECASE_LETTER: + case Character.MODIFIER_LETTER: + case Character.OTHER_LETTER: + case Character.LETTER_NUMBER: + case Character.CONNECTOR_PUNCTUATION: // maybe NUMBER + case Character.CURRENCY_SYMBOL: + // Characters where Other_ID_Start is true + unikind[b] = IDENTIFIER; + break; + case Character.NON_SPACING_MARK: + case Character.COMBINING_SPACING_MARK: + case Character.DECIMAL_DIGIT_NUMBER: + case Character.FORMAT: + unikind[b] = NUMBER; + break; + } + for (byte b = 0; b < 31; b++) + if (unikind[b] == -1) + System.out.println("Unicode cat " + b + " hasn't been classified"); + } + +} Added: mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/HighlightSourceViewer.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * HighlightSourceViewer + * + * Authors : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 6 dec 2007 + * Updated : $Date: 6 dec 2007 $ + * $Revision: 1.0 $ + */ + +package se.sics.mspsim.extutil.highlight; + +import java.awt.Container; +import java.io.FileReader; +import java.io.IOException; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +import se.sics.mspsim.util.SourceViewer; + +/** + * + */ +public class HighlightSourceViewer implements SourceViewer { + + private JFrame window; + private SyntaxHighlighter highlighter; + + public HighlightSourceViewer() { + // + } + + private void setup() { + if (window == null) { + window = new JFrame("Source Viewer"); + window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + Scanner scanner = new CScanner(); + highlighter = new SyntaxHighlighter(24, 80, scanner); + highlighter.setBorder(new LineNumberedBorder(LineNumberedBorder.LEFT_SIDE, LineNumberedBorder.RIGHT_JUSTIFY)); + JScrollPane scroller = new JScrollPane(highlighter); + scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + Container pane = window.getContentPane(); + pane.add(scroller); + window.pack(); + } + } + + public boolean isVisible() { + return window != null && window.isVisible(); + } + + public void setVisible(boolean isVisible) { + setup(); + window.setVisible(isVisible); + } + + public void viewFile(final String file) { + setup(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + FileReader reader = new FileReader(file); + try { + highlighter.read(reader, null); + // Workaround for bug 4782232 in Java 1.4 + highlighter.setCaretPosition(1); + highlighter.setCaretPosition(0); + } finally { + reader.close(); + } + } catch (IOException err) { + err.printStackTrace(); + JOptionPane.showMessageDialog(window, "Failed to read the file '" + file + '\'', "Could not read file", JOptionPane.ERROR_MESSAGE); + } + } + }); + } + + public void viewLine(final int line) { + if (highlighter != null) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (line >= 0 && line < highlighter.getLineCount()) { + highlighter.setCaretPosition(highlighter.getLineStartOffset(line)); + } + } + }); + } + } + + public static void main(String[] args) { + HighlightSourceViewer sv = new HighlightSourceViewer(); + sv.setVisible(true); + sv.viewFile(args[0]); + } +} Added: mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/JavaScanner.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,962 @@ +package se.sics.mspsim.extutil.highlight; +// Public domain, no restrictions, Ian Holyer, University of Bristol. + +/** + * <p> + * Provide a hand-written scanner for the Java language. + */ + +public class JavaScanner extends Scanner { + + // The version of Java supported. + private int version = 15; + + private boolean debug = false; + + /** Create a Java scanner, for Java version 1.5 by default. */ + public JavaScanner() { + super(); + initKind(); + initUniKind(); + } + + /** Create a Java scanner, for a given version between "1.1" and "1.5". */ + public JavaScanner(String version) { + super(); + initKind(); + initUniKind(); + if (version.equals("1.1")) + this.version = 11; + else if (version.equals("1.2")) + this.version = 12; + else if (version.equals("1.3")) + this.version = 13; + else if (version.equals("1.4")) + this.version = 14; + else if (version.equals("1.5")) + this.version = 15; + else + throw new Error("Unknown version of Java: " + version); + } + + /** Override the read method from the Scanner class. */ + protected int read() { + int type, saveStart = 0; + if (debug) + saveStart = start; + + if (start >= end) + return WHITESPACE; + + switch (state) { + case MID_COMMENT: + case END_COMMENT: + type = readComment(MID_COMMENT); + if (type == END_COMMENT) + state = WHITESPACE; + else + state = MID_COMMENT; + return type; + default: + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c < 128) + type = kind[c]; + else + type = unikind[Character.getType(c)]; + switch (type) { + case WHITESPACE: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != WHITESPACE) + break; + start = start + charlength; + charlength = 1; + } + break; + case UNRECOGNIZED: + case BRACKET: + case SEPARATOR: + start = start + charlength; + charlength = 1; + break; + case OPERATOR: + start = start + charlength; + charlength = 1; + type = readOperator(c); + break; + case CHARACTER: + start = start + charlength; + charlength = 1; + type = readCharLiteral(); + break; + case STRING: + start = start + charlength; + charlength = 1; + type = readStringLiteral(); + break; + case IDENTIFIER: + start = start + charlength; + charlength = 1; + while (start < end) { + c = buffer[start]; + if (c == '\\') + c = next(); + int k; + if (c < 128) + k = kind[c]; + else + k = unikind[Character.getType(c)]; + if (k != IDENTIFIER && k != NUMBER) + break; + start = start + charlength; + charlength = 1; + } + break; + case NUMBER: + start = start + charlength; + charlength = 1; + type = readNumber(c); + break; + case PUNCTUATION: + start = start + charlength; + charlength = 1; + type = readDot(); + break; + case COMMENT: + start = start + charlength; + charlength = 1; + type = readSlash(); + if (type == START_COMMENT) + state = MID_COMMENT; + break; + } + } + if (debug) { + System.out.print(TokenTypes.typeNames[type]); + System.out.println(" " + saveStart + "," + end + "(" + + (start - saveStart) + ")"); + } + return type; + } + + private int readOperator(char c) { + if (start >= end) + return OPERATOR; + char c2; + + switch (c) { + case '~': + case '?': + case ':': + break; + case '+': + case '-': + case '&': + case '|': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != c && c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '=': + case '*': + case '!': + case '^': + case '%': + case '/': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 != '=') + break; + start = start + charlength; + charlength = 1; + break; + case '<': + case '>': + c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (c2 == '=') { + start = start + charlength; + charlength = 1; + } else if (c2 == c) { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 == '=') { + start = start + charlength; + charlength = 1; + } else if (c == '>' && c3 == '>') // >>> + { + start = start + charlength; + charlength = 1; + if (start >= end) + break; + char c4 = buffer[start]; + if (c4 == '\\') + c4 = next(); + if (c4 != '=') + break; + start = start + charlength; + charlength = 1; + } + } + break; + } + return OPERATOR; + } + + private int readCharLiteral() { + if (start >= end) + return bad(CHARACTER); + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(CHARACTER); + break; + case '\'': + case '\n': + return bad(CHARACTER); + default: + start = start + charlength; + charlength = 1; + break; + } + if (start >= end) + return bad(CHARACTER); + char c3 = buffer[start]; + if (c3 == '\\') + c3 = next(); + if (c3 != '\'') + return bad(CHARACTER); + start = start + charlength; + charlength = 1; + return CHARACTER; + } + + private int readStringLiteral() { + if (start >= end) + return bad(STRING); + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (c != '"') { + switch (c) { + case '\\': + start = start + charlength; + charlength = 1; + boolean ok = readEscapeSequence(); + if (!ok) + return bad(STRING); + break; + case '\n': + return bad(STRING); + default: + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(STRING); + break; + } + c = buffer[start]; + if (c == '\\') + c = next(); + } + if (c != '"') + return bad(STRING); + start = start + charlength; + charlength = 1; + return STRING; + } + + private int readSlash() { + if (start >= end) + return OPERATOR; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + while (c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return COMMENT; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + return COMMENT; + } else if (c == '*') { + start = start + charlength; + charlength = 1; + return readComment(START_COMMENT); + } + return readOperator('/'); + } + + // Read one line of a /*...*/ comment, given the expected type + int readComment(int type) { + if (start >= end) + return type; + char c = buffer[start]; + if (c == '\\') + c = next(); + + while (true) { + while (c != '*' && c != '\n') { + start = start + charlength; + charlength = 1; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + } + start = start + charlength; + charlength = 1; + if (c == '\n') + return type; + if (start >= end) + return type; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '/') { + start = start + charlength; + charlength = 1; + if (type == START_COMMENT) { + return COMMENT; + } + return END_COMMENT; + } + } + } + + // Read a number, without checking whether it is out of range + // Doesn't deal with e.g. 0777.9 or 07779f + private int readNumber(char c) { + if (c == '0') { + int saveStart = start, saveLength = charlength; + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + switch (c2) { + case 'x': + case 'X': + start = start + charlength; + charlength = 1; + boolean ok = readDigits(16); + if (!ok) + return bad(NUMBER); + readSuffix(); + return NUMBER; + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + readDigits(8); + readSuffix(); + return NUMBER; + case '.': + case 'e': + case 'E': + start = saveStart; + charlength = saveLength; + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + boolean hasDigits = false; + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == 'l' || c == 'L') { + start = start + charlength; + charlength = 1; + return NUMBER; + } + } + if (c == '.') { + start = start + charlength; + charlength = 1; + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + if ('0' <= c && c <= '9') { + hasDigits = true; + readDigits(10); + if (start >= end) + return NUMBER; + c = buffer[start]; + if (c == '\\') + c = next(); + } + } + if (!hasDigits) + return bad(NUMBER); + switch (c) { + case 'e': + case 'E': + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + if (c == '+' || c == '-') { + start = start + charlength; + charlength = 1; + if (start >= end) + return bad(NUMBER); + c = buffer[start]; + if (c == '\\') + c = next(); + } + readDigits(10); + break; + case 'f': + case 'F': + case 'd': + case 'D': + start = start + charlength; + charlength = 1; + return NUMBER; + } + return NUMBER; + } + + boolean readDigits(int radix) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + if (Character.digit(c, radix) == -1) + return false; + while (Character.digit(c, radix) != -1) { + start = start + charlength; + charlength = 1; + if (start >= end) + return true; + c = buffer[start]; + if (c == '\\') + c = next(); + } + return true; + } + + void readSuffix() { + if (start >= end) + return; + char c = buffer[start]; + if (c == '\\') + c = next(); + switch (c) { + case 'f': + case 'F': + case 'd': + case 'D': + case 'l': + case 'L': + start = start + charlength; + charlength = 1; + } + } + + private int readDot() { + if (start >= end) + return SEPARATOR; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + if (Character.isDigit(c2)) { + return readNumber('.'); + } + if (start + 1 >= end || version < 15) + return SEPARATOR; + if (c2 != '.' || buffer[start + 1] != '.') + return SEPARATOR; + start = start + 2; + return SEPARATOR; + } + + private boolean readEscapeSequence() { + if (start >= end) + return false; + char c2 = buffer[start]; + if (c2 == '\\') + c2 = next(); + + switch (c2) { + case 'b': + case 't': + case 'n': + case 'f': + case 'r': + case '\"': + case '\'': + case '\\': + start = start + charlength; + charlength = 1; + return true; + case '0': + case '1': + case '2': + case '3': + return readOctal(3); + case '4': + case '5': + case '6': + case '7': + return readOctal(2); + default: + return false; + } + } + + boolean readOctal(int maxlength) { + if (start >= end) + return false; + char c = buffer[start]; + if (c == '\\') + c = next(); + + int i, val = 0; + for (i = 0; i < maxlength; i++) { + if (Character.digit(c, 8) != -1) { + val = 8 * val + Character.digit(c, 8); + start = start + charlength; + charlength = 1; + if (start >= end) + break; + c = buffer[start]; + if (c == '\\') + c = next(); + } else + break; + } + if ((i == 0) || (val > 0xFF)) + return false; + return true; + } + + // A malformed or incomplete token has a negative type + private int bad(int type) { + return -type; + } + + // Look ahead at the next character or unicode escape. + // For efficiency, replace c = next(); with + // c = buffer[start]; if (c == '\\') c = next(); + // To accept the character after looking at it, use: + // start = start + charlength; charlength = 1; + + // Record the number of source code characters used up. To deal with an odd + // or even number of backslashes preceding a unicode escape, whenever a + // second backslash is coming up, mark its position as a pair. + + private int charlength = 1; + + private int pair = 0; + + private char next() { + if (start >= end) + return 26; // EOF + char c = buffer[start]; + if (c != '\\') + return c; + if (start == pair) { + pair = 0; + return '\\'; + } + if (start + 1 >= end) + return '\\'; + + c = buffer[start + 1]; + if (c == '\\') + pair = start + 1; + if (c != 'u') + return '\\'; + + int pos = start + 2; + while (pos < end && buffer[pos] == 'u') + pos++; + if (pos + 4 > end) { + charlength = end - start; + return '\0'; + } + + c = 0; + for (int j = 0; j < 4; j++) { + int d = Character.digit(buffer[pos + j], 16); + if (d < 0) { + charlength = pos + j - start; + return '\0'; + } + c = (char) (c * 16 + d); + } + charlength = pos + 4 - start; + return c; + } + + // Override initSymbolTable + + protected void initSymbolTable() { + lookup(KEYWORD, "abstract"); + if (version >= 14) + lookup(KEYWORD, "assert"); + lookup(KEYWORD, "boolean"); + lookup(KEYWORD, "break"); + lookup(KEYWORD, "byte"); + lookup(KEYWORD, "case"); + lookup(KEYWORD, "catch"); + lookup(KEYWORD, "char"); + lookup(KEYWORD, "class"); + lookup(KEYWORD, "const"); + lookup(KEYWORD, "continue"); + lookup(KEYWORD, "default"); + lookup(KEYWORD, "do"); + lookup(KEYWORD, "double"); + lookup(KEYWORD, "else"); + if (version >= 15) + lookup(KEYWORD, "enum"); + lookup(KEYWORD, "extends"); + lookup(KEYWORD, "final"); + lookup(KEYWORD, "finally"); + lookup(KEYWORD, "float"); + lookup(KEYWORD, "for"); + lookup(KEYWORD, "goto"); + lookup(KEYWORD, "if"); + lookup(KEYWORD, "implements"); + lookup(KEYWORD, "import"); + lookup(KEYWORD, "instanceof"); + lookup(KEYWORD, "int"); + lookup(KEYWORD, "interface"); + lookup(KEYWORD, "long"); + lookup(KEYWORD, "native"); + lookup(KEYWORD, "new"); + lookup(KEYWORD, "package"); + lookup(KEYWORD, "private"); + lookup(KEYWORD, "protected"); + lookup(KEYWORD, "public"); + lookup(KEYWORD, "return"); + lookup(KEYWORD, "short"); + lookup(KEYWORD, "static"); + if (version >= 12) + lookup(KEYWORD, "strictfp"); + lookup(KEYWORD, "super"); + lookup(KEYWORD, "switch"); + lookup(KEYWORD, "synchronized"); + lookup(KEYWORD, "this"); + lookup(KEYWORD, "throw"); + lookup(KEYWORD, "throws"); + lookup(KEYWORD, "transient"); + lookup(KEYWORD, "try"); + lookup(KEYWORD, "void"); + lookup(KEYWORD, "volatile"); + lookup(KEYWORD, "while"); + + lookup(LITERAL, "true"); + lookup(LITERAL, "false"); + lookup(LITERAL, "null"); + } + + // *** Override lookup, but what about unicode escape translation? + + private Symbol temp = new Symbol(0, null); + + protected Symbol lookup(int type, String name) { + if (type != IDENTIFIER) + return super.lookup(type, name); + temp.type = KEYWORD; + temp.name = name; + Symbol sym = symbolTable.get(temp); + if (sym != null) + return sym; + temp.type = LITERAL; + sym = symbolTable.get(temp); + if (sym != null) + return sym; + return super.lookup(type, name); + } + + // Classify the ascii characters using an array of kinds, and classify all + // other unicode characters using an array indexed by unicode category. + // See the source file java/lang/Character.java for the categories. + // To find the classification of a character, use: + // if (c < 128) k = kind[c]; else k = unikind[Character.getType(c)]; + + private static final byte[] kind = new byte[128]; + + private static final byte[] unikind = new byte[31]; + + // Initialise the two classification arrays using static initializer code. + // Token types from the TokenTypes class are used to classify characters. + + private void initKind() { + for (char c = 0; c < 128; c++) + kind[c] = -1; + for (char c = 0; c < 128; c++) + switch (c) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 11: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 27: + case 28: + case 29: + case 30: + case 31: + case 127: + case '#': + case '@': + case '`': + case '\\': + kind[c] = UNRECOGNIZED; + break; + case '\t': + case '\n': + case ' ': + case '\f': + case 26: + kind[c] = WHITESPACE; + break; + case '!': + case '%': + case '&': + case '*': + case '+': + case '-': + case ':': + case '<': + case '=': + case '>': + case '?': + case '^': + case '|': + case '~': + kind[c] = OPERATOR; + break; + case '"': + kind[c] = STRING; + break; + case '\'': + kind[c] = CHARACTER; + break; + case '.': + kind[c] = PUNCTUATION; + break; + case '/': + kind[c] = COMMENT; + break; + case '$': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + kind[c] = IDENTIFIER; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + kind[c] = NUMBER; + break; + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + kind[c] = BRACKET; + break; + case ',': + case ';': + kind[c] = SEPARATOR; + break; + } + for (char c = 0; c < 128; c++) + if (kind[c] == -1) + System.out.println("Char " + ((int) c) + " hasn't been classified"); + } + + private void initUniKind() { + for (byte b = 0; b < 31; b++) + unikind[b] = -1; + for (byte b = 0; b < 31; b++) + switch (b) { + case Character.UNASSIGNED: + case Character.ENCLOSING_MARK: + case Character.OTHER_NUMBER: + case Character.SPACE_SEPARATOR: + case Character.LINE_SEPARATOR: + case Character.PARAGRAPH_SEPARATOR: + case Character.CONTROL: + case 17: // category 17 is unused + case Character.PRIVATE_USE: + case Character.SURROGATE: + case Character.DASH_PUNCTUATION: + case Character.START_PUNCTUATION: + case Character.END_PUNCTUATION: + case Character.OTHER_PUNCTUATION: + case Character.MATH_SYMBOL: + case Character.MODIFIER_SYMBOL: + case Character.OTHER_SYMBOL: + case Character.INITIAL_QUOTE_PUNCTUATION: + case Character.FINAL_QUOTE_PUNCTUATION: + unikind[b] = UNRECOGNIZED; + break; + case Character.UPPERCASE_LETTER: + case Character.LOWERCASE_LETTER: + case Character.TITLECASE_LETTER: + case Character.MODIFIER_LETTER: + case Character.OTHER_LETTER: + case Character.LETTER_NUMBER: + case Character.CONNECTOR_PUNCTUATION: // maybe NUMBER + case Character.CURRENCY_SYMBOL: + // Characters where Other_ID_Start is true + unikind[b] = IDENTIFIER; + break; + case Character.NON_SPACING_MARK: + case Character.COMBINING_SPACING_MARK: + case Character.DECIMAL_DIGIT_NUMBER: + case Character.FORMAT: + unikind[b] = NUMBER; + break; + } + for (byte b = 0; b < 31; b++) + if (unikind[b] == -1) + System.out.println("Unicode cat " + b + " hasn't been classified"); + } + +} Added: mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/LineNumberedBorder.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,258 @@ +package se.sics.mspsim.extutil.highlight; +import java.awt.Component; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; + +import javax.swing.border.AbstractBorder; + +/** + * Draws line numbers next to each line, in the same font as the text. + * Currently, this can only be used with a <tt>SyntaxHighlighter</tt> , since it + * relies on the <tt>getRows()</tt> and <tt>getLineCount()</tt> methods. A + * possible extension, create an interface to return this rows/linecount. + * + * @author Paul Durbin (Mc...@ya...) + * @created January 29, 2002 + */ +public class LineNumberedBorder extends AbstractBorder { + + private static final long serialVersionUID = -3812536735962506061L; + + /** + * The line numbers should be drawn on the left side of the component. + */ + public static int LEFT_SIDE = -2; + + /** + * The line numbers should be drawn on the right side of the component. + */ + public static int RIGHT_SIDE = -1; + + /** + * The line number should be right justified. + */ + public static int RIGHT_JUSTIFY = 0; + + /** + * The line number should be left justified. + */ + public static int LEFT_JUSTIFY = 1; + + /** + * Indicates the justification of the text of the line number. + */ + private int lineNumberJustification = RIGHT_JUSTIFY; + + /** + * Indicates the location of the line numbers, w.r.t. the component. + */ + private int location = LEFT_SIDE; + + public LineNumberedBorder(int location, int justify) { + setLocation(location); + setLineNumberJustification(justify); + } + + public Insets getBorderInsets(Component c) { + return getBorderInsets(c, new Insets(0, 0, 0, 0)); + } + + /** + * This modifies the insets, by adding space for the line number on the left. + * Should be modified to add space on the right, depending upon Locale. + * + * @param c + * Description of the Parameter + * @param insets + * Description of the Parameter + * @return The borderInsets value + */ + public Insets getBorderInsets(Component c, Insets insets) { + // if c is not a SyntaxHighlighter...nothing is done... + if (c instanceof SyntaxHighlighter) { + int width = lineNumberWidth((SyntaxHighlighter) c); + if (location == LEFT_SIDE) { + insets.left = width; + } else { + insets.right = width; + } + } + return insets; + } + + public int getLineNumberJustification() { + return lineNumberJustification; + } + + public void setLineNumberJustification(int justify) { + if (justify == RIGHT_JUSTIFY || justify == LEFT_JUSTIFY) { + lineNumberJustification = justify; + } + } + + public int getLocation() { + return location; + } + + public void setLocation(int loc) { + if (loc == RIGHT_SIDE || loc == LEFT_SIDE) { + location = loc; + } + } + + /** + * Returns the width, in pixels, of the maximum line number, plus a trailing + * space. + * + * @param textArea + * Description of the Parameter + * @return Description of the Return Value + */ + private int lineNumberWidth(SyntaxHighlighter textArea) { + // + // note: should this be changed to use all nines for the lineCount? + // for example, if the number of rows is 111...999 could be wider + // (in pixels) in a proportionally spaced font... + // + int lineCount = Math.max(textArea.getRows(), textArea.getLineCount() + 1); + return textArea.getFontMetrics(textArea.getFont()).stringWidth( + lineCount + " "); + } + + // + // NOTE: This method is called every time the cursor blinks... + // so...optimize (later and if possible) for speed... + // + public void paintBorder(Component c, Graphics g, int x, int y, int width, + int height) { + + java.awt.Rectangle clip = g.getClipBounds(); + + FontMetrics fm = g.getFontMetrics(); + int fontHeight = fm.getHeight(); + + // starting location at the "top" of the page... + // y is the starting baseline for the font... + // should "font leading" be applied? + int ybaseline = y + fm.getAscent(); + + // + // now determine if it is the "top" of the page...or somewhere else + // + int startingLineNumber = (clip.y / fontHeight) + 1; + + // + // use any one of the following if's: + // + // if (startingLineNumber != 1) + if (ybaseline < clip.y) { + // + // not within the clip rectangle...move it... + // determine how many fontHeight's there are between + // y and clip.y...then add that many fontHeights + // + ybaseline = + y + startingLineNumber * fontHeight - (fontHeight - fm.getAscent()); + } + + // + // options: + // . write the number rows in the document (current) + // . write the number of existing lines in the document (to do) + // see getLineCount() + // + + // determine which the "drawing" should end... + // add fontHeight: make sure...part of the line number is drawn + // + // could also do this by determining what the last line + // number to draw. + // then the "while" loop whould change accordingly. + // + // int yend = y + clip.height + fontHeight; + // int yend = ybaseline + height + fontHeight; // original + int yend = ybaseline + height; + if (yend > (y + height)) { + yend = y + height; + } + + SyntaxHighlighter jta = (SyntaxHighlighter) c; + int lineWidth = lineNumberWidth(jta); + + // base x position of the line number + int lnxstart = x; + if (location == LEFT_SIDE) { + // x (LEFT) or (x + lineWidth) (RIGHT) + // (depends upon justification) + if (lineNumberJustification == LEFT_JUSTIFY) { + lnxstart = x; + } else { + // RIGHT JUSTIFY + lnxstart = x + lineWidth; + } + } else { + // RIGHT SIDE + // (y + width) - lineWidth (LEFT) or (y + width) (RIGHT) + // (depends upon justification) + if (lineNumberJustification == LEFT_JUSTIFY) { + lnxstart = (y + width) - lineWidth; + } else { + // RIGHT JUSTIFY + lnxstart = (y + width); + } + } + + g.setColor(c.getForeground()); + // + // loop until out of the "visible" region... + // + int length = + ("" + Math.max(jta.getRows(), jta.getLineCount() + 1)).length(); + while (ybaseline < yend) { + // + // options: + // . left justify the line numbers + // . right justify the line numbers + // + + if (lineNumberJustification == LEFT_JUSTIFY) { + g.drawString(startingLineNumber + " ", lnxstart, ybaseline); + } else { + // right justify + String label = padLabel(startingLineNumber, length, true); + g.drawString(label, lnxstart - fm.stringWidth(label), ybaseline); + } + + ybaseline += fontHeight; + startingLineNumber++; + } + } + + // paintComponent + + /** + * Create the string for the line number. NOTE: The <tt>length</tt> param + * does not include the <em>optional</em> space added after the line number. + * + * @param lineNumber + * to stringize + * @param length + * the length desired of the string + * @param addSpace + * Description of the Parameter + * @return the line number for drawing + */ + private static String padLabel(int lineNumber, int length, boolean addSpace) { + StringBuffer buffer = new StringBuffer(); + buffer.append(lineNumber); + for (int count = (length - buffer.length()); count > 0; count--) { + buffer.insert(0, ' '); + } + if (addSpace) { + buffer.append(' '); + } + return buffer.toString(); + } +} +// LineNumberedBorder Added: mspsim/se/sics/mspsim/extutil/highlight/Scan.java =================================================================== --- mspsim/se/sics/mspsim/extutil/highlight/Scan.java (rev 0) +++ mspsim/se/sics/mspsim/extutil/highlight/Scan.java 2007-12-06 16:40:33 UTC (rev 39) @@ -0,0 +1,38 @@ +package se.sics.mspsim.extutil.highlight; +// Illustrate the use of the scanner by reading in a file and displaying its +// tokens. Public domain, no restrictions, Ian Holyer, University of Bristol. + +import java.io.*; + +public class Scan { + // Get the filename from the command line + public static void main(String[] args) throws IOException { + Scan program = ne... [truncated message content] |
From: <jo...@us...> - 2007-12-06 15:11:35
|
Revision: 38 http://mspsim.svn.sourceforge.net/mspsim/?rev=38&view=rev Author: joxe Date: 2007-12-06 07:11:27 -0800 (Thu, 06 Dec 2007) Log Message: ----------- fixed minor bugs related to source view Modified Paths: -------------- mspsim/se/sics/mspsim/platform/sky/SkyNode.java mspsim/se/sics/mspsim/util/ControlUI.java Modified: mspsim/se/sics/mspsim/platform/sky/SkyNode.java =================================================================== --- mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 14:24:30 UTC (rev 37) +++ mspsim/se/sics/mspsim/platform/sky/SkyNode.java 2007-12-06 15:11:27 UTC (rev 38) @@ -169,7 +169,7 @@ // Monitor execution cpu.setMonitorExec(true); //cpu.setDebug(true); - + ELF elf = null; int[] memory = cpu.getMemory(); if (args[0].endsWith("ihex")) { @@ -177,7 +177,7 @@ IHexReader reader = new IHexReader(); reader.readFile(memory, args[0]); } else { - ELF elf = ELF.readELF(args[0]); + elf = ELF.readELF(args[0]); elf.loadPrograms(memory); MapTable map = elf.getMap(); cpu.getDisAsm().setMap(map); @@ -187,7 +187,7 @@ cpu.reset(); SkyNode node = new SkyNode(cpu); node.gui = new SkyGui(node); - ControlUI control = new ControlUI(cpu); + ControlUI control = new ControlUI(cpu, elf); if (args.length > 1) { MapTable map = new MapTable(args[1]); Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 14:24:30 UTC (rev 37) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 15:11:27 UTC (rev 38) @@ -176,9 +176,9 @@ // } else if ("Single Step".equals(cmd)) { // cpu.step(); // dui.repaint(); - } else if ("View Source".equals(cmd)) { + } else if ("Show Source".equals(cmd)) { int pc = cpu.readRegister(cpu.PC); - if (sourceViewer != null) { + if (elfData != null) { DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { if (sourceViewer != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2007-12-06 14:24:34
|
Revision: 37 http://mspsim.svn.sourceforge.net/mspsim/?rev=37&view=rev Author: joxe Date: 2007-12-06 06:24:30 -0800 (Thu, 06 Dec 2007) Log Message: ----------- added some utils for viewing source Modified Paths: -------------- mspsim/se/sics/mspsim/util/ControlUI.java mspsim/se/sics/mspsim/util/DebugInfo.java mspsim/se/sics/mspsim/util/ELFDebug.java Added Paths: ----------- mspsim/se/sics/mspsim/util/SourceViewer.java Modified: mspsim/se/sics/mspsim/util/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 11:47:45 UTC (rev 36) +++ mspsim/se/sics/mspsim/util/ControlUI.java 2007-12-06 14:24:30 UTC (rev 37) @@ -65,9 +65,16 @@ private JFrame stackWindow; private StackUI stackUI; + private ELF elfData; + private SourceViewer sourceViewer; + private Action stepAction; public ControlUI(MSP430 cpu) { + this(cpu, null); + } + + public ControlUI(MSP430 cpu, ELF elf) { super(new GridLayout(0, 1)); this.cpu = cpu; @@ -103,6 +110,9 @@ JButton stepButton = new JButton(stepAction); add(stepButton); + if (elf != null) { + createButton("Show Source"); + } createButton("Profile Dump"); // Setup standard actions @@ -114,8 +124,14 @@ WindowUtils.restoreWindowBounds("ControlUI", window); WindowUtils.addSaveOnShutdown("ControlUI", window); window.setVisible(true); - } + elfData = elf; + } + private void setSourceViewer(SourceViewer viewer) { + sourceViewer = viewer; + } + + private JButton createButton(String text) { JButton jb = new JButton(text); jb.addActionListener(this); @@ -160,6 +176,20 @@ // } else if ("Single Step".equals(cmd)) { // cpu.step(); // dui.repaint(); + } else if ("View Source".equals(cmd)) { + int pc = cpu.readRegister(cpu.PC); + if (sourceViewer != null) { + DebugInfo dbg = elfData.getDebugInfo(pc); + if (dbg != null) { + if (sourceViewer != null) { + sourceViewer.viewFile(dbg.getFile()); + sourceViewer.viewLine(dbg.getLine()); + } else { + System.out.println("File: " + dbg.getFile()); + System.out.println("LineNr: " + dbg.getLine()); + } + } + } } dui.updateRegs(); } Modified: mspsim/se/sics/mspsim/util/DebugInfo.java =================================================================== --- mspsim/se/sics/mspsim/util/DebugInfo.java 2007-12-06 11:47:45 UTC (rev 36) +++ mspsim/se/sics/mspsim/util/DebugInfo.java 2007-12-06 14:24:30 UTC (rev 37) @@ -27,11 +27,9 @@ * * This file is part of MSPSim. * - * $Id: ELF.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ - * * ----------------------------------------------------------------- * - * ELF + * DebugInfo - contains some debug info * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 Modified: mspsim/se/sics/mspsim/util/ELFDebug.java =================================================================== --- mspsim/se/sics/mspsim/util/ELFDebug.java 2007-12-06 11:47:45 UTC (rev 36) +++ mspsim/se/sics/mspsim/util/ELFDebug.java 2007-12-06 14:24:30 UTC (rev 37) @@ -27,11 +27,9 @@ * * This file is part of MSPSim. * - * $Id: ELF.java,v 1.3 2007/10/21 21:17:34 nfi Exp $ - * * ----------------------------------------------------------------- * - * ELF + * ELFDebug * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 Added: mspsim/se/sics/mspsim/util/SourceViewer.java =================================================================== --- mspsim/se/sics/mspsim/util/SourceViewer.java (rev 0) +++ mspsim/se/sics/mspsim/util/SourceViewer.java 2007-12-06 14:24:30 UTC (rev 37) @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * + * ----------------------------------------------------------------- + * + * Source Viewer + * + * Author : Joakim Eriksson + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date: 2007/10/21 22:02:22 $ + * $Revision: 1.4 $ + */ + +package se.sics.mspsim.util; + + +public interface SourceViewer { + + public void viewFile(String file); + public void viewLine(int line); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |