trinnguyen / bahndsl

BahnDSL: A Domain-Specific Language for Configuring and Modelling Model Railways
GNU General Public License v3.0
1 stars 0 forks source link

Bug: compiler fails to process the function with standardlib (using classpath:/) #12

Closed trinnguyen closed 3 years ago

trinnguyen commented 3 years ago
def request_route(string src_signal_id, string dst_signal_id, string train_id): string
    return get_shortest_route({"r1"})
end
eyip002 commented 3 years ago

When generating scchart get_shortest_route, variables declared in an outer scope are not resolved:

eyip002 commented 3 years ago

Caused by #10

eyip002 commented 3 years ago

The standardlib has to be validated in order to resolve variable scopes. Otherwise, variable references are not linked to their declarations. This can be done just before BahnModel is validated in generator/StandaloneApp.java in runGenerator().

eyip002 commented 3 years ago

Compilation of BahnDSL methods no longer work in Eclipse: null pointer exception. Same waiting problem with VSCode extension.

eyip002 commented 3 years ago

When setting up the standardlib URI in BahnImportURIGlobalScopeProvider, the Xtext resource set load options also have to be set:

resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);

eyip002 commented 3 years ago

Compilation to C and shared library in Eclipse not working: Couldn't find resource on classpath. URI was 'classpath:/standardlib.bahn'

eyip002 commented 3 years ago

In Eclipse, the context menu command for compilation creates an instance of StandaloneApp which tries to validate the standardlib and model file before the XtextResourceSet setClasspathUriResolver has been set to our own CustomClassPathUriResolver. This causes an exception because standardlib cannot be found in the resourceSets and cannot be loaded with the default classloader.

The fix is to setClasspathUriResolver when calling loadResource in StandaloneApp.

When editing in Eclipse, BahnScopeProvider is automatically called, which invokes BahnImportURIGlobalScopeProvider.getImportedUris() to set the custom URI resolver.

trinnguyen commented 3 years ago

@eyip002 Thanks for solving this!!!