Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CUP Eclipse Plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr. Michael Petter
CUP Eclipse Plugin
Commits
d0e782b8
Commit
d0e782b8
authored
Nov 27, 2014
by
Sebastian Pretscher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git@github.com:jroith/cup-eclipse.git
parents
a8fb2740
a93cb319
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
289 additions
and
195 deletions
+289
-195
CupPlugin/META-INF/MANIFEST.MF
CupPlugin/META-INF/MANIFEST.MF
+2
-1
CupPlugin/src/de/tum/in/www2/cupplugin/Activator.java
CupPlugin/src/de/tum/in/www2/cupplugin/Activator.java
+34
-6
CupPlugin/src/de/tum/in/www2/cupplugin/debug/BreakpointMapper.java
.../src/de/tum/in/www2/cupplugin/debug/BreakpointMapper.java
+13
-3
CupPlugin/src/de/tum/in/www2/cupplugin/debug/Debugger.java
CupPlugin/src/de/tum/in/www2/cupplugin/debug/Debugger.java
+13
-9
CupPlugin/src/de/tum/in/www2/cupplugin/debug/ToggleBreakpointsTarget.java
.../tum/in/www2/cupplugin/debug/ToggleBreakpointsTarget.java
+70
-59
CupPlugin/src/de/tum/in/www2/cupplugin/wizards/CupJavaProjectWizard.java
...e/tum/in/www2/cupplugin/wizards/CupJavaProjectWizard.java
+125
-100
CupPlugin/templates/Driver.java
CupPlugin/templates/Driver.java
+1
-0
CupPlugin/templates/build.xml
CupPlugin/templates/build.xml
+5
-3
CupPlugin/templates/java-cup-11b.jar
CupPlugin/templates/java-cup-11b.jar
+0
-0
CupPlugin/templates/lexer.jflex
CupPlugin/templates/lexer.jflex
+5
-11
CupPlugin/templates/parser.cup
CupPlugin/templates/parser.cup
+21
-3
No files found.
CupPlugin/META-INF/MANIFEST.MF
View file @
d0e782b8
...
...
@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt;bundle-version="3.10.0",
org.eclipse.jdt.debug;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
CupPlugin/src/de/tum/in/www2/cupplugin/Activator.java
View file @
d0e782b8
package
de.tum.in.www2.cupplugin
;
import
org.eclipse.core.resources.IResourceChangeEvent
;
import
org.eclipse.core.resources.IResourceChangeListener
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.jface.resource.ImageDescriptor
;
import
org.eclipse.ui.plugin.AbstractUIPlugin
;
import
org.osgi.framework.BundleContext
;
import
org.eclipse.core.resources.IWorkspace
;
import
de.tum.in.www2.cupplugin.debug.BreakpointMapper
;
import
de.tum.in.www2.cupplugin.debug.Debugger
;
/**
* The activator class controls the plug-in life cycle
*/
public
class
Activator
extends
AbstractUIPlugin
{
public
class
DebugListener
implements
IResourceChangeListener
{
public
void
resourceChanged
(
IResourceChangeEvent
event
)
{
System
.
out
.
println
(
"GOT EVENT: "
+
event
.
getType
());
Debugger
.
getBreakpointMapper
().
remap
();
if
(
event
.
getType
()
!=
IResourceChangeEvent
.
POST_BUILD
)
return
;
System
.
out
.
println
(
"GOT POST BUILD EVENT!"
);
}
}
// The plug-in ID
public
static
final
String
PLUGIN_ID
=
"CupPlugin"
;
//$NON-NLS-1$
// The shared instance
private
static
Activator
plugin
;
/**
* The constructor
*/
public
Activator
()
{
IWorkspace
workspace
=
ResourcesPlugin
.
getWorkspace
();
workspace
.
addResourceChangeListener
(
new
DebugListener
());
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public
void
start
(
BundleContext
context
)
throws
Exception
{
super
.
start
(
context
);
...
...
@@ -32,7 +56,10 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
* )
*/
public
void
stop
(
BundleContext
context
)
throws
Exception
{
plugin
=
null
;
...
...
@@ -49,10 +76,11 @@ public class Activator extends AbstractUIPlugin {
}
/**
* Returns an image descriptor for the image file at the given
*
plug-in
relative path
* Returns an image descriptor for the image file at the given
plug-in
* relative path
*
* @param path the path
* @param path
* the path
* @return the image descriptor
*/
public
static
ImageDescriptor
getImageDescriptor
(
String
path
)
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/debug/BreakpointMapper.java
View file @
d0e782b8
...
...
@@ -20,12 +20,17 @@ import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import
org.eclipse.jdt.debug.core.JDIDebugModel
;
import
de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping
;
import
de.in.tum.www2.cup.ast.ParserResult
;
import
de.tum.in.www2.cupplugin.GeneratedFileLocator
;
import
de.tum.in.www2.cupplugin.PluginUtility
;
public
class
BreakpointMapper
{
private
Map
<
CupLineBreakpoint
,
IBreakpoint
>
mappings
=
new
HashMap
<
CupLineBreakpoint
,
IBreakpoint
>();
private
Set
<
CupLineBreakpoint
>
breakpoints
=
new
HashSet
<
CupLineBreakpoint
>();
private
GeneratedFileLocator
locator
=
new
GeneratedFileLocator
();
public
IBreakpoint
getRemoteBreakpoint
(
CupLineBreakpoint
breakpoint
)
{
return
mappings
.
get
(
breakpoint
);
}
...
...
@@ -47,8 +52,13 @@ public class BreakpointMapper {
if
(
originResource
==
null
){
return
;
}
IFile
resource
=
PluginUtility
.
findGenerated
(((
IFile
)
origin
.
getResource
()));
ParserResult
astModel
=
Debugger
.
getInstance
(
originResource
).
getParserResult
();
if
(
astModel
==
null
){
return
;
}
IFile
resource
=
locator
.
find
((
IFile
)
originResource
,
astModel
);
if
(
resource
==
null
){
return
;
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/debug/Debugger.java
View file @
d0e782b8
...
...
@@ -23,8 +23,7 @@ public class Debugger {
static
HashMap
<
IResource
,
Debugger
>
delayedInstances
=
new
HashMap
<
IResource
,
Debugger
>();
private
static
final
BreakpointMapper
breakpointMapper
=
new
BreakpointMapper
();
private
static
final
String
DEFAULT_CLASS
=
"Test"
;
// TODO: auf Parser
// umstellen
private
static
final
String
DEFAULT_CLASS
=
"Parser"
;
/**
* Add Debug hooks to an editor
...
...
@@ -94,7 +93,7 @@ public class Debugger {
}
current
=
null
;
}
Debugger
tmp
=
new
Debugger
(
new
CupTextEditor
());
Debugger
tmp
=
new
Debugger
(
new
CupTextEditor
());
// TODO: lösen
delayedInstances
.
put
(
resource
,
tmp
);
return
tmp
;
...
...
@@ -151,11 +150,9 @@ public class Debugger {
* @return the class name
*/
public
String
getGeneratedTargetClass
(
CupLineBreakpoint
breakpoint
)
{
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocumentProvider
()
.
getDocument
(
myEditor
.
getEditorInput
()));
try
{
String
rname
=
m
.
getAstModel
().
className
.
getName
().
name
;
String
rname
=
getParserResult
().
className
.
getName
().
name
;
if
(!
rname
.
trim
().
equals
(
""
))
{
return
rname
;
}
...
...
@@ -167,9 +164,7 @@ public class Debugger {
}
public
Mapping
getDebugId
(
int
lineNumber
)
{
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocumentProvider
()
.
getDocument
(
myEditor
.
getEditorInput
()));
ParserResult
astModel
=
m
.
getAstModel
();
ParserResult
astModel
=
getParserResult
();
if
(
astModel
==
null
)
{
return
null
;
...
...
@@ -186,4 +181,13 @@ public class Debugger {
}
public
ParserResult
getParserResult
(){
if
(
myEditor
==
null
){
System
.
out
.
println
(
"myEditor: NULL"
);
}
Model
m
=
Model
.
getInstanceForDocument
(
myEditor
.
getDocument
());
ParserResult
astModel
=
m
.
getAstModel
();
return
astModel
;
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/debug/ToggleBreakpointsTarget.java
View file @
d0e782b8
...
...
@@ -22,30 +22,31 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
/*
* find out where the editor is
*/
if
(
part
instanceof
CupTextEditor
){
if
(
part
instanceof
CupTextEditor
)
{
textEditor
=
(
CupTextEditor
)
part
;
}
else
if
(
part
instanceof
MultiPageEditor
)
{
}
else
if
(
part
instanceof
MultiPageEditor
)
{
Object
editor
=
((
MultiPageEditor
)
part
).
getSelectedPage
();
if
(
editor
instanceof
CupTextEditor
)
textEditor
=
(
CupTextEditor
)
editor
;
}
if
(
textEditor
!=
null
)
{
//prepare everything
//
prepare everything
IResource
resource
=
(
IResource
)
textEditor
.
getEditorInput
()
.
getAdapter
(
IResource
.
class
);
ITextSelection
textSelection
=
(
ITextSelection
)
selection
;
int
lineNumber
=
textSelection
.
getStartLine
();
int
nextPossibleLine
=
(
Debugger
.
getInstance
((
CupTextEditor
)
textEditor
).
getNextCodeBlockForLineBreakpoint
(((
ITextSelection
)
selection
).
getStartLine
()));
if
(
nextPossibleLine
!=
-
1
){
int
nextPossibleLine
=
(
Debugger
.
getInstance
((
CupTextEditor
)
textEditor
)
.
getNextCodeBlockForLineBreakpoint
(((
ITextSelection
)
selection
)
.
getStartLine
()));
if
(
nextPossibleLine
!=
-
1
)
{
lineNumber
=
nextPossibleLine
;
}
else
{
}
else
{
return
;
}
// get doc identifier:
IDocument
doc
=
null
;
...
...
@@ -55,18 +56,18 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
if
(
doc
==
null
)
{
return
;
}
//create preakpoint and give it to IDE
IBreakpoint
[]
breakpoints
=
(
IBreakpoint
[])
Debugger
.
getBreakpointManager
()
.
getBreakpoints
();
//
create preakpoint and give it to IDE
IBreakpoint
[]
breakpoints
=
(
IBreakpoint
[])
Debugger
.
getBreakpoint
Manager
().
getBreakpoint
s
();
if
(
breakpoints
!=
null
)
{
for
(
int
i
=
0
;
i
<
breakpoints
.
length
;
i
++)
{
IBreakpoint
breakpoint
=
breakpoints
[
i
];
if
(
resource
.
equals
(
breakpoint
.
getMarker
().
getResource
()))
{
if
(((
ILineBreakpoint
)
breakpoint
).
getLineNumber
()
==
(
lineNumber
+
1
))
{
// existing breakpoint; delete
Debugger
.
getBreakpointManager
()
.
removeBreakpoint
(
breakpoint
,
true
);
Debugger
.
getBreakpointManager
()
.
removeBreakpoint
(
breakpoint
,
true
);
return
;
}
}
...
...
@@ -76,11 +77,11 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
// new breakpoint; create
CupLineBreakpoint
lineBreakpoint
=
new
CupLineBreakpoint
(
resource
,
lineNumber
+
1
);
Debugger
.
getBreakpointManager
()
.
addBreakpoint
(
lineBreakpoint
);
/*System.out.println("CREATED! Length: "
+ Debugger.getBreakpointManager()
.getBreakpoints().length);
*/
// TODO: DELETE
Debugger
.
getBreakpointManager
()
.
addBreakpoint
(
lineBreakpoint
);
/*
* System.out.println("CREATED! Length: " +
* Debugger.getBreakpointManager() .getBreakpoints().length);
*/
// TODO: DELETE
}
}
...
...
@@ -89,19 +90,30 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
public
boolean
canToggleLineBreakpoints
(
IWorkbenchPart
part
,
ISelection
selection
)
{
// true, if we have an CupTextEditor
if
(
part
instanceof
CupTextEditor
)
return
true
;
if
(
part
instanceof
CupTextEditor
)
{
if
(
selection
instanceof
ITextSelection
)
{
return
(
Debugger
.
getInstance
((
CupTextEditor
)
part
)
.
getNextCodeBlockForLineBreakpoint
(
((
ITextSelection
)
selection
).
getStartLine
())
!=
-
1
);
}
else
{
return
false
;
}
}
if
(
part
instanceof
MultiPageEditor
)
{
Object
editor
=
((
MultiPageEditor
)
part
).
getSelectedPage
();
/*System.out.println("" + editor
+ " is a CupTextEditor(Breakpoints):"
+ (editor instanceof CupTextEditor));*/
// TODO: DELETE
if
(
editor
instanceof
CupTextEditor
){
if
(
selection
instanceof
ITextSelection
){
return
(
Debugger
.
getInstance
((
CupTextEditor
)
editor
).
getNextCodeBlockForLineBreakpoint
(((
ITextSelection
)
selection
).
getStartLine
())
!=
-
1
);
}
else
{
/*
* System.out.println("" + editor +
* " is a CupTextEditor(Breakpoints):" + (editor instanceof
* CupTextEditor));
*/
// TODO: DELETE
if
(
editor
instanceof
CupTextEditor
)
{
if
(
selection
instanceof
ITextSelection
)
{
return
(
Debugger
.
getInstance
((
CupTextEditor
)
editor
)
.
getNextCodeBlockForLineBreakpoint
(
((
ITextSelection
)
selection
).
getStartLine
())
!=
-
1
);
}
else
{
return
false
;
}
}
...
...
@@ -112,54 +124,53 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
@Override
public
void
toggleMethodBreakpoints
(
IWorkbenchPart
part
,
ISelection
selection
)
throws
CoreException
{
//not implemented
//System.out.println("toggle watchpoints called");// TODO: DELETE
//
not implemented
//
System.out.println("toggle watchpoints called");// TODO: DELETE
}
@Override
public
boolean
canToggleMethodBreakpoints
(
IWorkbenchPart
part
,
ISelection
selection
)
{
//default answer: false
//
default answer: false
return
false
;
//do this, if you want to toggle method bps
/*
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(MethodBreakpoints):"
+ (editor instanceof CupTextEditor));
*/
// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;
*/
//
do this, if you want to toggle method bps
/*
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(MethodBreakpoints):" + (editor instanceof
* CupTextEditor));
*/
// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
@Override
public
void
toggleWatchpoints
(
IWorkbenchPart
part
,
ISelection
selection
)
throws
CoreException
{
//System.out.println("toggleWatchpoints called");
//
System.out.println("toggleWatchpoints called");
}
@Override
public
boolean
canToggleWatchpoints
(
IWorkbenchPart
part
,
ISelection
selection
)
{
return
false
;
/*
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Watchpoints):"
+ (editor instanceof CupTextEditor));*/
// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(Watchpoints):" + (editor instanceof
* CupTextEditor));
*/
// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/wizards/CupJavaProjectWizard.java
View file @
d0e782b8
This diff is collapsed.
Click to expand it.
CupPlugin/templates/Driver.java
View file @
d0e782b8
package
cup.example
;
class
Driver
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
CupPlugin/templates/build.xml
View file @
d0e782b8
...
...
@@ -5,21 +5,23 @@
<property
name=
"result"
location=
"bin/jar"
/>
<property
name=
"lib"
location=
"lib"
/>
<property
name=
"tools"
location=
"tools"
/>
<property
name=
"base"
location=
"."
/>
<taskdef
name=
"jflex"
classname=
"JFlex.anttask.JFlexTask"
classpath=
"${tools}/JFlex.jar"
/>
<taskdef
name=
"cup"
classname=
"java_cup.anttask.CUPTask"
classpath=
"${tools}/java-cup-11b.jar"
/>
<target
name=
"generate"
>
<jflex
file=
"lexer.jflex"
destdir=
"${java}"
/>
<cup
srcfile=
"parser.cup"
destdir=
"${java}"
<cup
srcfile=
"
${base}/
parser.cup"
destdir=
"${java}"
parser=
"Parser"
interface=
"true"
locations=
"true"
debugsymbols=
"true"
/>
<jflex
file=
"lexer.jflex"
destdir=
"${java}"
/>
</target>
<path
id=
"libraries"
>
<files
includes=
"${
lib
}/java-cup-11b-runtime.jar"
/>
<files
includes=
"${
tools
}/java-cup-11b-runtime.jar"
/>
</path>
<target
name=
"compile"
depends=
"generate"
>
...
...
CupPlugin/templates/java-cup-11b.jar
View file @
d0e782b8
No preview for this file type
CupPlugin/templates/lexer.jflex
View file @
d0e782b8
package
de
.
in
.
tum
.
www2
.
cup
.
internal
;
package
cup
.
example
;
import
java_cup
.
runtime
.
ComplexSymbolFactory
;
import
java_cup
.
runtime
.
ComplexSymbolFactory
.
Location
;
import
java_cup
.
runtime
.
Symbol
;
import
de
.
in
.
tum
.
www2
.
cup
.
Position
;
import
de
.
in
.
tum
.
www2
.
cup
.
ErrorManager
;
import
de
.
in
.
tum
.
www2
.
cup
.
ErrorSource
;
import
java
.
lang
.
Error
;
import
java
.
io
.
InputStreamReader
;
...
...
@@ -19,7 +16,7 @@ import java.io.InputStreamReader;
%
cup
%
char
%{
private
ErrorManager
errMan
;
public
Lexer
(
ComplexSymbolFactory
sf
,
java
.
io
.
InputStream
is
){
this
(
is
);
...
...
@@ -47,12 +44,12 @@ import java.io.InputStreamReader;
}
protected
void
emit_warning
(
String
message
){
System
.
out
.
println
(
"scanner warning: "
+
message
+
" at : 2 +
System
.
out
.
println
(
"scanner warning: "
+
message
+
" at : 2
"
+
(
yyline
+
1
)
+
" "
+
(
yycolumn
+
1
)
+
" "
+
yychar
);
}
protected
void
emit_error
(
String
message
){
System.out.println("
scanner
error
:
" + message + "
at
:
2
+
System
.
out
.
println
(
"scanner error: "
+
message
+
" at : 2
"
+
(
yyline
+
1
)
+
" "
+
(
yycolumn
+
1
)
+
" "
+
yychar
);
}
%}
...
...
@@ -84,10 +81,7 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
"other"
{
return
symbol
(
"OTHERTERMINAL"
,
OTHERTERMINAL
);
}
}
<
CODESEG
>
{
":}"
{
yybegin
(
YYINITIAL
);
return
symbolFactory
.
newSymbol
(
"CODE_STRING"
,
CODE_STRING
,
new
Location
(
csline
,
cscolumn
),
new
Location
(
yyline
+
1
,
yycolumn
+
1
+
yylength
()),
sb
.
toString
());
}
.|\
n
{
sb
.
append
(
yytext
());
}
}
//
error
fallback
.|\
n
{
emit_warning
(
"Unrecognized character '"
+
yytext
()+
"' -- ignored"
);
}
CupPlugin/templates/parser.cup
View file @
d0e782b8
package
cup
.
example
;
import
java_cup
.
runtime
.*;
import
java
.
io
.
File
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
IOException
;
parser
code
{:
:}
init with {: :}
scan with {: :}
/*
override
error
routines
*/
protected
Lexer
lexer
;
:};
init
with
{:
ComplexSymbolFactory
f
=
new
ComplexSymbolFactory
();
symbolFactory
=
f
;
File
file
=
new
File
(
"input.txt"
);
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
lexer
=
new
Lexer
(
f
,
fis
);
:};
scan
with
{:
return
lexer
.
next_token
();
:};
terminal
MYTERMINAL
,
OTHERTERMINAL
;
non
terminal
Integer
expr
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment