Skip to content

Commit 61c23eb

Browse files
committed
Merge branch 'main' into test-for-2455
2 parents d69c2ac + 5936c9e commit 61c23eb

File tree

70 files changed

+2466
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2466
-457
lines changed

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.rascalmpl</groupId>
55
<artifactId>rascal</artifactId>
6-
<version>0.41.0-RC74-SNAPSHOT</version>
6+
<version>0.41.0-RC79-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<scm>
@@ -250,7 +250,9 @@
250250
<include>**/org/rascalmpl/test/library/LibraryLangPaths.java</include>
251251
<include>**/org/rascalmpl/test/value/AllTests.java</include>
252252
<include>**/org/rascalmpl/test/repl/*Test.java</include>
253-
<include>**/org/rascalmpl/util/maven/**/*Test.java</include>
253+
<include>**/org/rascalmpl/test/rpc/*Test.java</include>
254+
<include>**/org/rascalmpl/util/**/*Test.java</include>
255+
<include>**/org/rascalmpl/util/**/*Tests.java</include>
254256
<include>**/org/rascalmpl/uri/**/*Test.java</include>
255257
<include>**/org/rascalmpl/*Test.java</include>
256258
</includes>
@@ -470,7 +472,7 @@
470472
<dependency>
471473
<groupId>io.usethesource</groupId>
472474
<artifactId>vallang</artifactId>
473-
<version>1.0.0-RC19</version>
475+
<version>1.0.0-RC20</version>
474476
</dependency>
475477
<dependency>
476478
<groupId>org.apache.commons</groupId>

src/org/rascalmpl/compiler/lang/rascalcore/check/ModuleLocations.rsc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ loc getSearchPathLoc(str filePath, PathConfig pcfg){
5555
throw "Module with path <filePath> not found";
5656
}
5757
58-
list[Message] getCausesFromPathConfig(PathConfig pcfg){
59-
causes = [ info("In srcs", src) | src <- pcfg.srcs ];
60-
if(!isEmpty(pcfg.libs)){
61-
causes += [ info("In libs", lib) | lib <- pcfg.libs ];
62-
}
63-
return causes;
64-
}
65-
6658
@synopsis{Get the location of a named module, search for `src` in srcs and `tpl` in libs}
6759
loc getRascalModuleLocation(str qualifiedModuleName, PathConfig pcfg){
6860
fileName = makeFileName(qualifiedModuleName, extension="rsc");
@@ -80,7 +72,8 @@ loc getRascalModuleLocation(str qualifiedModuleName, PathConfig pcfg){
8072
return fileLoc;
8173
}
8274
}
83-
throw error("Module `<qualifiedModuleName>` not found", |unknown:///|, causes=getCausesFromPathConfig(pcfg));
75+
mloc = |unknown:///|;
76+
throw error("Module `<qualifiedModuleName>` not found", mloc, causes=[info("Using PathConfig: <iprintToString(pcfg)>", mloc)] );
8477
}
8578
8679
tuple[str,str] splitFileExtension(str path){

src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ value rewriteTypeModel(value model, map[loc,str] paths, loc sourceLookup)
7070
// any location in the wild:
7171
case loc l => inheritPosition(sourceLookup + paths[l.top], l)
7272
when l.top in paths
73-
73+
7474
// \loc annotations on Trees are not visited by `visit` automatically
7575
case Tree t => t[@\loc = inheritPosition(sourceLookup + paths[Top], t@\loc)]
7676
when t@\loc?, loc Top := t@\loc.top, Top in paths
77+
78+
// remove infos and warnings
79+
case set[Message] msgs => {msg | msg <- msgs, msg is error}
80+
case list[Message] msgs => [msg | msg <- msgs, msg is error]
7781
};
7882
7983
loc inheritPosition(loc new, loc original) {

src/org/rascalmpl/debug/DebugHandler.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121
import java.util.Set;
2222
import java.util.function.IntSupplier;
2323

24+
import org.rascalmpl.ast.AbstractAST;
25+
import org.rascalmpl.ast.Case;
2426
import org.rascalmpl.debug.IDebugMessage.Detail;
27+
import org.rascalmpl.semantics.dynamic.Statement.For;
28+
import org.rascalmpl.semantics.dynamic.Statement.Switch;
29+
import org.rascalmpl.semantics.dynamic.Statement.Visit;
30+
import org.rascalmpl.semantics.dynamic.Statement.While;
31+
2532
import io.usethesource.vallang.ISourceLocation;
2633

2734
public final class DebugHandler implements IDebugHandler {
@@ -49,7 +56,7 @@ private enum DebugStepMode {
4956
/**
5057
* Referring to {@link ISourceLocation} responsible for last suspension.
5158
*/
52-
private ISourceLocation referenceAST = null;
59+
private AbstractAST referenceAST = null;
5360

5461
/**
5562
* Referring to the stack depth at last suspension suspension.
@@ -88,7 +95,7 @@ protected void clearSuspensionState() {
8895
setSuspended(false);
8996
}
9097

91-
protected void updateSuspensionState(int callStackSize, ISourceLocation currentAST) {
98+
protected void updateSuspensionState(int callStackSize, AbstractAST currentAST) {
9299
setReferenceAST(currentAST);
93100

94101
// TODO: remove cast to {@link Evaluator} and rework {@link IEvaluator}.
@@ -97,14 +104,14 @@ protected void updateSuspensionState(int callStackSize, ISourceLocation currentA
97104
}
98105

99106
@Override
100-
public void suspended(Object runtime, IntSupplier getCallStackSize, ISourceLocation currentAST) {
107+
public void suspended(Object runtime, IntSupplier getCallStackSize, AbstractAST currentAST) {
101108
if (isSuspendRequested()) {
102109
updateSuspensionState(getCallStackSize.getAsInt(), currentAST);
103110
getEventTrigger().fireSuspendByClientRequestEvent();
104111
setSuspendRequested(false);
105112
}
106113
else {
107-
ISourceLocation location = currentAST;
114+
AbstractAST location = currentAST;
108115
switch (getStepMode()) {
109116

110117
case STEP_INTO:
@@ -130,10 +137,35 @@ public void suspended(Object runtime, IntSupplier getCallStackSize, ISourceLocat
130137
* frame, positions are compared to ensure that the
131138
* statement was finished executing.
132139
*/
133-
int referenceStart = getReferenceAST().getOffset();
134-
int referenceAfter = getReferenceAST().getOffset() + getReferenceAST().getLength();
135-
int currentStart = location.getOffset();
136-
int currentAfter = location.getOffset() + location.getLength();
140+
int referenceStart = getReferenceAST().getLocation().getOffset();
141+
int referenceAfter = getReferenceAST().getLocation().getOffset() + getReferenceAST().getLocation().getLength();
142+
int currentStart = location.getLocation().getOffset();
143+
int currentAfter = location.getLocation().getOffset() + location.getLocation().getLength();
144+
145+
// Special handling for For, While and Switch statements to step over inside their body
146+
if(getReferenceAST() instanceof For){
147+
For forStmt = (For) getReferenceAST();
148+
referenceAfter = forStmt.getBody().getLocation().getOffset();
149+
}
150+
if(getReferenceAST() instanceof While){
151+
While whileStmt = (While) getReferenceAST();
152+
referenceAfter = whileStmt.getBody().getLocation().getOffset();
153+
}
154+
if(getReferenceAST() instanceof Switch){
155+
Switch switchStmt = (Switch) getReferenceAST();
156+
if (switchStmt.getCases().size() > 0) {
157+
Case lastCase = switchStmt.getCases().get(0);
158+
referenceAfter = lastCase.getLocation().getOffset();
159+
}
160+
}
161+
if(getReferenceAST() instanceof Visit){
162+
Visit visitStmt = (Visit) getReferenceAST();
163+
org.rascalmpl.ast.Visit visit = visitStmt.getVisit();
164+
if (visit.getCases().size() > 0) {
165+
Case lastCase = visit.getCases().get(0);
166+
referenceAfter = lastCase.getLocation().getOffset();
167+
}
168+
}
137169

138170
if (currentStart < referenceStart
139171
|| currentStart >= referenceAfter
@@ -171,9 +203,9 @@ public void suspended(Object runtime, IntSupplier getCallStackSize, ISourceLocat
171203
break;
172204

173205
case NO_STEP:
174-
if (hasBreakpoint(location)) {
206+
if (hasBreakpoint(location.getLocation())) {
175207
updateSuspensionState(getCallStackSize.getAsInt(), currentAST);
176-
getEventTrigger().fireSuspendByBreakpointEvent(location);
208+
getEventTrigger().fireSuspendByBreakpointEvent(location.getLocation());
177209
}
178210
break;
179211

@@ -192,11 +224,11 @@ public void suspended(Object runtime, IntSupplier getCallStackSize, ISourceLocat
192224
}
193225
}
194226

195-
protected ISourceLocation getReferenceAST() {
227+
protected AbstractAST getReferenceAST() {
196228
return referenceAST;
197229
}
198230

199-
protected void setReferenceAST(ISourceLocation referenceAST) {
231+
protected void setReferenceAST(AbstractAST referenceAST) {
200232
this.referenceAST = referenceAST;
201233
}
202234

src/org/rascalmpl/debug/IRascalSuspendTriggerListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import java.util.function.IntSupplier;
1515

16-
import io.usethesource.vallang.ISourceLocation;
16+
import org.rascalmpl.ast.AbstractAST;
1717

1818
/**
1919
* Interface for suspending an program interpretation.
@@ -27,6 +27,6 @@ public interface IRascalSuspendTriggerListener {
2727
* @param evaluator the evaluator in charge of interpreting @param context.
2828
* @param currentAST the AST that is causes the suspension.
2929
*/
30-
public void suspended(Object runtime, IntSupplier getCallStackSize, ISourceLocation currentAST);
30+
public void suspended(Object runtime, IntSupplier getCallStackSize, AbstractAST currentAST);
3131

3232
}

src/org/rascalmpl/exceptions/RuntimeExceptionFactory.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@
1616
*******************************************************************************/
1717
package org.rascalmpl.exceptions;
1818

19+
import java.io.FileNotFoundException;
1920
import java.io.IOException;
2021
import java.net.URISyntaxException;
22+
import java.nio.file.DirectoryNotEmptyException;
23+
import java.nio.file.FileAlreadyExistsException;
24+
import java.nio.file.FileSystemException;
25+
import java.nio.file.NoSuchFileException;
26+
import java.nio.file.NotDirectoryException;
27+
2128
import org.rascalmpl.ast.AbstractAST;
29+
import org.rascalmpl.values.ValueFactoryFactory;
30+
2231
import io.usethesource.vallang.IInteger;
2332
import io.usethesource.vallang.IList;
2433
import io.usethesource.vallang.ISourceLocation;
@@ -28,7 +37,6 @@
2837
import io.usethesource.vallang.type.Type;
2938
import io.usethesource.vallang.type.TypeFactory;
3039
import io.usethesource.vallang.type.TypeStore;
31-
import org.rascalmpl.values.ValueFactoryFactory;
3240

3341
/**
3442
* This class defines and implements all dynamic (run-time) exceptions that
@@ -432,10 +440,44 @@ public static Throw invalidUseOfTime(String message, AbstractAST ast, StackTrace
432440
public static Throw io(IString msg) {
433441
return new Throw(VF.constructor(IO, msg));
434442
}
443+
435444

436445
public static Throw io(String msg) {
437-
return new Throw(VF.constructor(IO, VF.string(msg)));
446+
return io(VF.string(msg));
438447
}
448+
449+
private static String mapIOException(IOException ex) {
450+
var msg = ex.getMessage();
451+
if (ex instanceof FileSystemException) {
452+
// nio exceptions lack proper messages, they are encoded in the class name
453+
if (ex instanceof DirectoryNotEmptyException) {
454+
return "Directory is not empty: " + msg;
455+
}
456+
if (ex instanceof FileAlreadyExistsException) {
457+
return "File already exists: " + msg;
458+
}
459+
if (ex instanceof NoSuchFileException) {
460+
return "No such file: " + msg;
461+
}
462+
if (ex instanceof NotDirectoryException) {
463+
return "Not a directory: " + msg;
464+
}
465+
}
466+
if (ex instanceof FileNotFoundException) {
467+
// not all paths throw a proper message, they often only have the path name
468+
return "No such file: " + msg;
469+
}
470+
// otherwise fallback to the message
471+
return msg;
472+
}
473+
474+
public static Throw io(IOException ex) {
475+
return io(mapIOException(ex));
476+
}
477+
478+
public static Throw io(IOException ex, AbstractAST ast, StackTrace trace) {
479+
return io(VF.string(mapIOException(ex)), ast, trace);
480+
}
439481

440482
public static Throw io(IString msg, AbstractAST ast, StackTrace trace) {
441483
return new Throw(VF.constructor(IO, msg), ast != null ? ast.getLocation() : null, trace);

src/org/rascalmpl/ideservices/BasicIDEServices.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
import org.rascalmpl.uri.URIResolverRegistry;
2828
import org.rascalmpl.uri.URIUtil;
2929

30+
import io.usethesource.vallang.IInteger;
3031
import io.usethesource.vallang.IList;
3132
import io.usethesource.vallang.ISourceLocation;
33+
import io.usethesource.vallang.IString;
3234

3335
/**
3436
* IDEServices for a Desktop environment that rely on the
@@ -60,16 +62,11 @@ public Terminal activeTerminal() {
6062
return terminal;
6163
}
6264

63-
64-
public void browse(ISourceLocation loc, String title, int viewColumn){
65-
browse(loc.getURI(), title, viewColumn);
66-
}
67-
6865
/* (non-Javadoc)
6966
* @see org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.ideservices.IDEServices#browse(java.net.URI)
7067
*/
7168
@Override
72-
public void browse(URI uri, String _title, int _viewColumn) {
69+
public void browse(URI uri, IString title, IInteger viewColumn) {
7370
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
7471
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
7572
try {

0 commit comments

Comments
 (0)