Issue reading file. IO: ("Unsupported scheme \'java+compilationUnit\'") - rascal

I have run into and issue. I have been trying to read the content of a file for an example project which contains I single file. Below you will find the code and the error which I get. I have tried running this code with Rascal version 0.22.0, 0.23.0, and 0.24,2. In all versions I have the same issue, but I do not understand what is wrong, and I am pretty sure this code worked for me over a year ago.
void demoFunc() {
list[str] output = [];
m3x = createM3FromEclipseProject(|project://testProject|);
projectFiles = files(m3x);
for(file <- projectFiles) {
output = readFileLines(file);
}
}
rascal>demoFunc();
|std:///IO.rsc|(15157,756,<620,0>,<640,24>): IO("Unsupported scheme \'java+compilationUnit\'")
at *** somewhere ***(|std:///IO.rsc|(15157,756,<620,0>,<640,24>))
at readFileLines(|project://TQM/src/Helper.rsc|(998,4,<39,26>,<39,30>))
at $root$(|prompt:///|(0,11,<1,0>,<1,11>)ok

Looks like the latest rascal-eclipse release has a new bug. To work around this one you could resolve the source file from the logical name yourself:
loc sourceFile(loc logical, M3 model) {
if (loc f <- model.declarations[logical]) {
return f;
}
throw FileNotFound(logical);
}
That simulates what analysis::m3::Registry would have done for you. The returned loc is a slice of the file where the declared entity is found. If you want the entire file, use myLoc.top.

Related

Rollupjs: function is being called before definition bundled code?

When running my bundle, I get this error:
can't access property "call", Readable$1 is undefined
So I looked in the bundled code, and noticed this on line 71481:
function Duplex$2(options) {
if (!(this instanceof Duplex$2)) return new Duplex$2(options);
Readable$1.call(this, options);
The on line 71463 (correctly before usage):
var Readable$1 = _stream_readable;
But then on line 72148 (so Readable$1 is actually undefined at this point, which links to the above error):
var _stream_readable = Readable;
/*<replacement>*/
If I manually move this definition to before var Readable$1 = _stream_readable; then it works. My question is, how do I fix rollup mixing up the order?
Ok so it's a known issue with rollup, and readable-stream, as pointed out here: https://github.com/rollup/rollup/issues/4231 and documented in the various issues listed: https://github.com/rollup/rollup/issues/4231#issuecomment-937772340
I managed to solve the issue this way: https://github.com/nodejs/readable-stream/issues/348#issuecomment-937971694, basically:
npm i readable-stream#npm:vite-compatible-readable-stream
The relevant concept is detailed here: https://github.com/nodejs/readable-stream/issues/348#issuecomment-473804926

RxSwift .asDriverOnErrorJustComplete() not being part of core/utility library

Trying to figure out how to make an app with RxSwift and exploring multiple open source projects (namely CleanArchitectureRxSwift and SwiftHub) I often find usage of
extension ObservableType {
func asDriverOnErrorJustComplete() -> Driver<E> {
return asDriver { error in
return Driver.empty()
}
}
}
Given that this method is useful in many situation and literally copied in mentioned projects I wonder why is it not a part of some utility library (like for example RxSwiftExt) or even RxSwift itself.
I find it really suspicious that given how many Rx pods there are in SwiftHub Podfile none of them actually contain this function.
My question is that are there any real reasons behind that? Does asDriverOnErrorJustComplete somehow violates come Rx contracts or considered bad practice etc?
Am I biased in sense that those two projects are most likely copied architecture from each other and are not representative? If so, are there any good open source projects that demonstrate RxSwift+MVVM and maybe avoid asDriverOnErrorJustComplete or approach problems solved by asDriverOnErrorJustComplete differently?
I wouldn't call the method bad practice per se but it allows for an error that will get silently ignored which I don't particularly like. Using such a construct is rather pernicious in that your chain will silently fail without any notice at all. It could be a problem if your QA department (you with a different hat on?) doesn't notice the fact that the label isn't updating anymore.
I'm also not a big fan of the particular GitHub repos you call out because they add a lot of IMHO unnecessary boilerplate. I prefer code that is more direct.
In my sample app RxEarthquake, I use the following:
public func asDriverLogError(_ file: StaticString = #file, _ line: UInt = #line) -> SharedSequence<DriverSharingStrategy, E> {
return asDriver(onErrorRecover: { print("Error:", $0, " in file:", file, " atLine:", line); return .empty() })
}
So at least a record of the error is made in debug.
I also think the following is an excellent alternative:
public func asDriverOrAbort(_ file: StaticString = #file, _ line: UInt = #line) -> SharedSequence<DriverSharingStrategy, E> {
return asDriver(onErrorRecover: { fatalError("Error: \($0) in file: \(file) atLine: \(line)") })
}
By using such a method, you are making it clear to the reader that you are absolutely sure that the chain won't produce an error.
I think asDriverOnErrorJustComplete is not included in the standard library, because with any type of observable except void, the application will be crashed when receiving an error.
When I started writing SwiftHub, I couldn’t understand why the application crashes when I got an error from the server :)

How do I copy DOORS modules between folders/projects using DXL?

I am new to both DOORS and DXL. I've been trying to copy a module in a project template to any given project folder using DXL, but my approaches haven't been working. Here's the part of my script where the copy and paste operations are attempted:
// Where string originalModule is the path to the module being copied.
// Where string targetPath is the path to where the copied module should be pasted.
ModName_ originalMMP = module(originalModule)
string originalMMPdesc = description(originalMMP)
clipCopy(originalMMP)
clipPaste(targetPath)
clipClear()
Whenever I run my script in the DOORS' DXL editor, I get an error indicating that the functions clipCopy() and clipPaste() have invalid arguments. In the DXL reference manual, it indicates that the type of the arguments should be of Item type, but I'm not totally sure I'm understanding that.
I have tried this other approach as well:
// The same conventions as above are used for the originalModule and targetPath
// string type variables.
// The variable string targetPathTemp contains the path to the replicated
// file New Module Temp
ModName_ originalMMP = module(originalModule)
string originalMMPdesc = description(originalMMP)
bool OK = copy(originalMMP,"New Module Temp", originalMMPdesc)
ModName_ newMMP = module(targetPathTemp)
// Moving and Renaming:
ErrMess = move(newMMP, targetPath)
ErrMess = rename(copiedMMP,newModuleName, originalMMPdesc)
I get the same errors as clipCopy() and clipPaste() for the functions: copy() and move().
Does anyone have any idea of what am I doing wrong, and what exactly am I not understanding?
Thanks in advance!
I think clipCopy and its brethren only work with Items. Use Item originalMMP = item(originalModule) instead of ModName_...

clang set metadata to allocainst

First I'm real noob with clang/llvm.
BUT I'm trying to modify clang for some purpose.
I'd like to add metadata whenever an Alloca instruction is emitted in IR code for a variable which has some annotation.
I noticed this function in CGDecl.cpp:
CodeGenFunction::AutoVarEmission
CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D)
which contains the nice line in the end:
if (D.hasAttr<AnnotateAttr>())
EmitVarAnnotations(&D, emission.Address);
this looks like the condition I need, so I modified it to
if (D.hasAttr<AnnotateAttr>()) {
AnnotateAttr* attr = D.getAttr<AnnotateAttr>();
if(attr->getAnnotation() == "_my_custom_annotation_") {
// set metadata...
}
EmitVarAnnotations(&D, emission.Address);
}
my Issue is I don't know how to add metadata at this point, because I can't find a way to access the instruction
In CGExp.cpp, however, I see where the AllocaInstr is built, but at this point I don't have access to the VarDecl, so I don't know if the annotation is there.
I tried anyway to add metadata (unconditionaly) in this function:
llvm::AllocaInst *CodeGenFunction::CreateIRTemp(QualType Ty,
const Twine &Name) {
llvm::AllocaInst *Alloc = CreateTempAlloca(ConvertType(Ty), Name);
// FIXME: Should we prefer the preferred type alignment here?
CharUnits Align = getContext().getTypeAlignInChars(Ty);
// how to put it conditionaly on the annotation?
llvm::MDNode* node = getRangeForLoadFromType(Ty);
Alloc->setMetadata("_my_custom_metadata", node);
Alloc->setAlignment(Align.getQuantity());
return Alloc;
}
by adding the setMetadata call.
However I don't see the metadata attached in the generated IR.
I compile with clang -g -S -target i686-pc-win32 -emit-llvm main.cpp -o output.ll
Maybe I'm totally wrong, but the thing is I don't master the code generation in clang :)
PS: here is the code I compile
int main() {
__attribute__ ((annotate("_my_custom_annotation_"))) float a[12];
}
Any help is appreciated!
Thanks
if (D.hasAttr<AnnotateAttr>()) {
AnnotateAttr* attr = D.getAttr<AnnotateAttr>();
if(attr->getAnnotation() == "_my_custom_annotation_") {
// set metadata...
}
EmitVarAnnotations(&D, emission.Address);
}
Looks like you are at the right place. In fact all EmitAutoVarAlloca has special handling for different kinds of variable declarations, but all end with the "address" (i.e., the instruction) in emission.Address.
So what you want to do is:
if (D.hasAttr<AnnotateAttr>()) {
AnnotateAttr* attr = D.getAttr<AnnotateAttr>();
if(attr->getAnnotation() == "_my_custom_annotation_") {
emission.Address->setMetadata(...); // <--- your MDNode goes here
}
EmitVarAnnotations(&D, emission.Address);
}
However, I would recommend a special attribute for adding metadata to instructions. If you read further through the code you will see that the AnnotateAttr has a special meaning and your emitted IR may not be as expected. You can add a custom attribute in the Attr.td file. I suggest a copy of the Annotate entry. Then you can follow the AnnotateAttr through the code and add code for your Attribute at the right places to get it recognized and handled by clang.

Irony AST generation throws nullreference excepttion

I'm getting started with Irony (version Irony_2012_03_15) but I pretty quickly got stuck when trying to generate an AST. Below is a completely strpped language that throws the exception:
[Language("myLang", "0.1", "Bla Bla")]
public class MyLang: Grammar {
public NModel()
: base(false) {
var number = TerminalFactory.CreateCSharpNumber("number");
var binExpr = new NonTerminal("binExpr", typeof(BinaryOperationNode));
var binOp = new NonTerminal("BinOp");
binExpr.Rule = number + binOp + number;
binOp.Rule = ToTerm("+");
RegisterOperators(1, "+");
//MarkTransient(binOp);
this.Root = binExpr;
this.LanguageFlags = Parsing.LanguageFlags.CreateAst; // if I uncomment this line it throws the error
}
}
As soon as I uncomment the last line it throws a NullReferenceException in the grammar explorer or when i want to parse a test. The error is on AstBuilder.cs line 96:
parseNode.AstNode = config.DefaultNodeCreator();
DefaultNodeCreator is a delegate that has not been set.
I've tried setting things with MarkTransient etc but no dice.
Can someone help me afloat here? I'm proably missing something obvious. Looked for AST tutorials all over the webs but I can't seem to find an explanation on how that works.
Thanks in advance,
Gert-Jan
Once you set the LanguageFlags.CreateAst flag on the grammar, you must provide additional information about how to create the AST.
You're supposed to be able to set AstContext.Default*Type for the whole language, but that is currently bugged.
Set TermFlags.NoAstNode. Irony will ignore this node and its children.
Set AstConfig.NodeCreator. This is a delegate that can do the right thing.
Set AstConfig.NodeType to the type of the AstNode. This type should be accessible, implement IAstInit, and have a public, no-parameters constructor. Accessible in this case means either public or internal with the InternalsVisibleTo attribute.
To be honest, I was facing the same problem and did not understand Jay Bazuzi answer, though it looks like valid one(maybe it's outdated).
If there's anyone like me;
I just inherited my Grammar from Irony.Interpreter.InterpretedLanguageGrammar class, and it works. Also, anyone trying to get AST working, make sure your nodes are "public" :- )
On top of Jay's and Erti-Chris's responses, this thread is also useful:
https://irony.codeplex.com/discussions/361018
The creator of Irony points out the relevant configuration code in InterpretedLanguageGrammar.BuildAst.
HTH

Resources