Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dr. Michael Petter
CUP Eclipse Plugin
Commits
683d4c0f
Commit
683d4c0f
authored
Feb 27, 2016
by
Michael Schwarz
🤔
Browse files
fixed bug if separator string is present, but no productions afterwards
show error message in case buildfile was not found
parent
0c1acc13
Changes
5
Hide whitespace changes
Inline
Side-by-side
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/BuildfileUpdater.java
View file @
683d4c0f
...
...
@@ -28,46 +28,58 @@ import org.xml.sax.SAXException;
public
class
BuildfileUpdater
{
public
static
void
updateExpectedConflicts
(
IProject
project
,
int
number
)
throws
ParserConfigurationException
,
SAXException
,
CoreException
,
TransformerConfigurationException
,
TransformerException
,
TransformerFactoryConfigurationError
,
IOException
{
boolean
modified
=
false
;
Path
path
=
new
Path
(
"build.xml"
);
IFile
file
=
project
.
getFile
(
path
);
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
db
=
dbf
.
newDocumentBuilder
();
Document
doc
=
db
.
parse
(
file
.
getContents
());
if
(
doc
.
getElementsByTagName
(
"cup"
).
getLength
()
!=
1
){
throw
new
IOException
();
}
else
{
Node
n
=
doc
.
getElementsByTagName
(
"cup"
).
item
(
0
);
public
static
class
BuildfileNotFoundException
extends
Exception
{
public
BuildfileNotFoundException
(
Exception
e
)
{
super
(
e
);
}
}
public
static
void
updateExpectedConflicts
(
IProject
project
,
int
number
)
throws
BuildfileNotFoundException
{
try
{
boolean
modified
=
false
;
Node
expect
=
n
.
getAttributes
().
getNamedItem
(
"expect"
);
Path
path
=
new
Path
(
"build.xml"
);
IFile
file
=
project
.
getFile
(
path
);
if
(
expect
==
null
){
Attr
expectedA
=
doc
.
createAttribute
(
"expect"
);
n
.
getAttributes
().
setNamedItem
(
expectedA
);
expect
=
n
.
getAttributes
().
getNamedItem
(
"expect"
);
expect
.
setTextContent
(
String
.
valueOf
(
number
));
modified
=
true
;
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
db
=
dbf
.
newDocumentBuilder
(
);
Document
doc
=
db
.
parse
(
file
.
getContents
()
);
if
(
doc
.
getElementsByTagName
(
"cup"
).
getLength
()
!=
1
){
throw
new
IOException
()
;
}
else
if
(!
expect
.
getTextContent
().
equals
(
String
.
valueOf
(
number
))){
expect
.
setTextContent
(
String
.
valueOf
(
number
));
modified
=
true
;
else
{
Node
n
=
doc
.
getElementsByTagName
(
"cup"
).
item
(
0
);
Node
expect
=
n
.
getAttributes
().
getNamedItem
(
"expect"
);
if
(
expect
==
null
){
Attr
expectedA
=
doc
.
createAttribute
(
"expect"
);
n
.
getAttributes
().
setNamedItem
(
expectedA
);
expect
=
n
.
getAttributes
().
getNamedItem
(
"expect"
);
expect
.
setTextContent
(
String
.
valueOf
(
number
));
modified
=
true
;
}
else
if
(!
expect
.
getTextContent
().
equals
(
String
.
valueOf
(
number
))){
expect
.
setTextContent
(
String
.
valueOf
(
number
));
modified
=
true
;
}
}
}
if
(
modified
){
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
Source
xmlSource
=
new
DOMSource
(
doc
);
Result
outputTarget
=
new
StreamResult
(
outputStream
);
TransformerFactory
.
newInstance
().
newTransformer
().
transform
(
xmlSource
,
outputTarget
);
InputStream
is
=
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
file
.
setContents
(
is
,
true
,
true
,
null
);
is
.
close
();
if
(
modified
){
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
Source
xmlSource
=
new
DOMSource
(
doc
);
Result
outputTarget
=
new
StreamResult
(
outputStream
);
TransformerFactory
.
newInstance
().
newTransformer
().
transform
(
xmlSource
,
outputTarget
);
InputStream
is
=
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
file
.
setContents
(
is
,
true
,
true
,
null
);
is
.
close
();
}
}
catch
(
Exception
e
){
throw
new
BuildfileNotFoundException
(
e
);
}
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ConflictFilter.java
View file @
683d4c0f
...
...
@@ -68,7 +68,7 @@ public class ConflictFilter {
}
}
p
rivate
int
computeIgnoreRRAfter
()
{
p
ublic
int
computeIgnoreRRAfter
()
{
int
offset
=
document
.
get
().
indexOf
(
TRESHOLD_STRING
);
if
(
offset
==
-
1
)
{
return
-
1
;
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReduceReduceReorder.java
View file @
683d4c0f
...
...
@@ -68,7 +68,6 @@ public class ReduceReduceReorder {
rangesToRemove
.
add
(
new
RangeToRemove
(
p
.
getBegin
().
getOffsetFromStart
(),
p
.
getEnd
().
getOffsetFromStart
()
-
p
.
getBegin
().
getOffsetFromStart
()));
}
catch
(
BadLocationException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
...
...
@@ -144,10 +143,21 @@ public class ReduceReduceReorder {
private
void
insert
()
throws
BadLocationException
{
int
positionForProd
=
0
;
ParserResult
r
=
Model
.
getInstanceForDocument
(
document
).
getAstModel
();
// Grammar can be assumed to have at least two productions -> safe
positionForProd
=
r
.
productions
.
get
(
r
.
productions
.
size
()-
1
).
getEnd
().
getOffsetFromStart
();
//If separator string is present, but no productions afterwards
int
ignoreLine
=
(
new
ConflictFilter
(
document
)).
computeIgnoreRRAfter
();
if
(
ignoreLine
>
0
){
int
ignoreOffset
=
document
.
getLineOffset
(
ignoreLine
);
if
(
ignoreOffset
>
positionForProd
){
positionForProd
=
ignoreOffset
;
}
}
document
.
replace
(
positionForProd
,
0
,
textToAppend
);
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReordersToDo.java
View file @
683d4c0f
...
...
@@ -15,7 +15,6 @@ import de.in.tum.www2.cup.ReduceReduceConflict;
import
de.in.tum.www2.cup.internal.internal_error
;
import
de.in.tum.www2.cup.internal.lalr_item
;
import
de.in.tum.www2.cup.internal.lr_item_core
;
import
de.tum.in.www2.cupplugin.conflictresolution.ReordersToDo.OrderCyclicException
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
public
class
ReordersToDo
extends
GraphHelper
<
lr_item_core
>
implements
ResolutionStrategy
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
View file @
683d4c0f
...
...
@@ -86,6 +86,8 @@ public class CupConflictsView extends FailableView
public
int
ignoreRRAfterLine
;
private
int
expectedRR
=
-
1
;
public
class
ShiftReduceDetails
{
public
terminal
shift
;
public
terminal
reduce
;
...
...
@@ -214,14 +216,13 @@ public class CupConflictsView extends FailableView
IProject
project
=
file
.
getProject
();
BuildfileUpdater
.
updateExpectedConflicts
(
project
,
number
);
}
catch
(
ParserConfigurationException
|
SAXException
|
IOException
|
CoreException
|
TransformerException
|
TransformerFactoryConfigurationError
e1
)
{
}
catch
(
BuildfileUpdater
.
BuildfileNotFoundException
e
)
{
Shell
shell
=
new
Shell
(
Display
.
getCurrent
());
MessageBox
box
=
new
MessageBox
(
shell
,
SWT
.
ICON_WARNING
|
SWT
.
OK
);
box
.
setText
(
"Information"
);
box
.
setMessage
(
"Failed to update the expect label in the buildfile.\nThere was no file named build.xml containing a cup section.\n"
+
"Please update your buildfile and set the expect label to number."
);
+
"Please update your buildfile and set the expect label to
"
+
number
+
"
."
);
box
.
open
();
}
...
...
@@ -239,8 +240,15 @@ public class CupConflictsView extends FailableView
addToOrderSet
(
c
);
}
// Do this less often
updateBuildfile
(
cf
.
getResolvedCountLastRun
());
int
newResolved
=
cf
.
getResolvedCountLastRun
();
// We assume that if there are already conflicts solved when we do this first, that they
//were solved on purpose and so the buildfile is up-to-date
if
(
newResolved
!=
expectedRR
&&
expectedRR
!=
-
1
){
updateBuildfile
(
newResolved
);
}
expectedRR
=
newResolved
;
scrolled
.
setLayoutDeferred
(
true
);
...
...
Write
Preview
Supports
Markdown
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