add AppMode for best boundaries over stdlib
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.98% (17344/27983)
* Branch Coverage: 53.07% (6720/12663)
* Lines of Code: 27983
* Cyclomatic Complexity: 11207
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 11, passed: 581
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.98% (17344/27983)
* Branch Coverage: 53.07% (6720/12663)
* Lines of Code: 27983
* Cyclomatic Complexity: 11207
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 11, passed: 581
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
This commit is contained in:
+3
-1
@@ -1,5 +1,6 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.AppMode;
|
||||
import p.studio.compiler.models.FrontendSemanticToken;
|
||||
import p.studio.compiler.models.FrontendSemanticTokenProvider;
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
@@ -26,6 +27,7 @@ import java.util.Set;
|
||||
public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProvider {
|
||||
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "float", "bool", "string", "i32", "i64", "f32", "f64");
|
||||
private static final int DEFAULT_STDLIB_VERSION = 1;
|
||||
private static final AppMode DEFAULT_TARGET = AppMode.Game;
|
||||
private static final ResourceStdlibEnvironmentResolver STDLIB_RESOLVER = new ResourceStdlibEnvironmentResolver();
|
||||
private static final Map<PbsTokenKind, PbsSemanticKind> DECLARATION_KINDS = declarationKinds();
|
||||
|
||||
@@ -210,7 +212,7 @@ public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProv
|
||||
}
|
||||
|
||||
private Map<String, PbsSemanticKind> resolveStdlibExportKinds(final PbsAst.ModuleRef moduleRef) {
|
||||
final var stdlibEnvironment = STDLIB_RESOLVER.resolve(DEFAULT_STDLIB_VERSION);
|
||||
final var stdlibEnvironment = STDLIB_RESOLVER.resolve(DEFAULT_STDLIB_VERSION, DEFAULT_TARGET);
|
||||
return stdlibEnvironment.resolveModule(moduleRef.project(), moduleRef.pathSegments())
|
||||
.map(this::parseStdlibVisibleKinds)
|
||||
.orElseGet(Map::of);
|
||||
|
||||
+3
-10
@@ -1,21 +1,14 @@
|
||||
package p.studio.compiler.pbs.stdlib;
|
||||
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
import p.studio.AppMode;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class EmptyStdlibEnvironmentResolver implements StdlibEnvironmentResolver {
|
||||
private static final StdlibEnvironment EMPTY = new StdlibEnvironment() {
|
||||
@Override
|
||||
public Optional<StdlibModuleSource> resolveModule(
|
||||
final String project,
|
||||
final ReadOnlyList<String> pathSegments) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
private static final StdlibEnvironment EMPTY = (project, pathSegments) -> Optional.empty();
|
||||
|
||||
@Override
|
||||
public StdlibEnvironment resolve(final int stdlibVersion) {
|
||||
public StdlibEnvironment resolve(final int stdlibVersion, final AppMode target) {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,26 +1,23 @@
|
||||
package p.studio.compiler.pbs.stdlib;
|
||||
|
||||
import p.studio.AppMode;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmentResolver {
|
||||
private static final String STDLIB_ROOT = "stdlib";
|
||||
|
||||
@Override
|
||||
public StdlibEnvironment resolve(final int stdlibVersion) {
|
||||
return new ResourceStdlibEnvironment(stdlibVersion);
|
||||
public StdlibEnvironment resolve(final int stdlibVersion, final AppMode target) {
|
||||
return new ResourceStdlibEnvironment(stdlibVersion, target);
|
||||
}
|
||||
|
||||
private static final class ResourceStdlibEnvironment implements StdlibEnvironment {
|
||||
private final int stdlibVersion;
|
||||
|
||||
private ResourceStdlibEnvironment(final int stdlibVersion) {
|
||||
this.stdlibVersion = stdlibVersion;
|
||||
}
|
||||
private record ResourceStdlibEnvironment(int stdlibVersion, AppMode target) implements StdlibEnvironment {
|
||||
|
||||
@Override
|
||||
public Optional<StdlibModuleSource> resolveModule(
|
||||
@@ -36,7 +33,7 @@ public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmen
|
||||
return Optional.of(new StdlibModuleSource(
|
||||
project,
|
||||
pathSegments,
|
||||
ReadOnlyList.wrap(java.util.List.of(new StdlibModuleSource.SourceFile("main.pbs", mainSource.get()))),
|
||||
ReadOnlyList.wrap(List.of(new StdlibModuleSource.SourceFile("main.pbs", mainSource.get()))),
|
||||
barrelSource.get()));
|
||||
}
|
||||
|
||||
@@ -44,7 +41,10 @@ public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmen
|
||||
final String project,
|
||||
final ReadOnlyList<String> pathSegments) {
|
||||
final var pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(STDLIB_ROOT)
|
||||
pathBuilder
|
||||
.append(target.exportReferenceName().toLowerCase())
|
||||
.append('/')
|
||||
.append(STDLIB_ROOT)
|
||||
.append('/')
|
||||
.append(stdlibVersion)
|
||||
.append('/')
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package p.studio.compiler.pbs.stdlib;
|
||||
|
||||
import p.studio.AppMode;
|
||||
|
||||
public interface StdlibEnvironmentResolver {
|
||||
StdlibEnvironment resolve(int stdlibVersion);
|
||||
StdlibEnvironment resolve(int stdlibVersion, AppMode target);
|
||||
}
|
||||
|
||||
|
||||
+15
-12
@@ -1,5 +1,6 @@
|
||||
package p.studio.compiler.services;
|
||||
|
||||
import p.studio.AppMode;
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.IRGlobalVisibility;
|
||||
@@ -99,7 +100,8 @@ final class PbsModuleAssemblyService {
|
||||
projectIdByName,
|
||||
defaultSyntheticOwnerProjectId,
|
||||
diagnostics,
|
||||
ctx.stdlibVersion());
|
||||
ctx.stdlibVersion(),
|
||||
ctx.target());
|
||||
|
||||
final var modules = new ArrayList<PbsModuleVisibilityValidator.ModuleUnit>(modulesByCoordinates.size());
|
||||
for (final var entry : modulesByCoordinates.entrySet()) {
|
||||
@@ -206,28 +208,29 @@ final class PbsModuleAssemblyService {
|
||||
final Map<String, ProjectId> projectIdByName,
|
||||
final ProjectId defaultSyntheticOwnerProjectId,
|
||||
final DiagnosticSink diagnostics,
|
||||
final int stdlibVersion) {
|
||||
final var stdlibEnvironment = stdlibEnvironmentResolver.resolve(stdlibVersion);
|
||||
final int stdlibVersion,
|
||||
final AppMode target) {
|
||||
final var stdlibEnvironment = stdlibEnvironmentResolver.resolve(stdlibVersion, target);
|
||||
final var pending = new ArrayDeque<PbsModuleVisibilityValidator.ModuleCoordinates>();
|
||||
final var resolved = new HashSet<ModuleId>();
|
||||
|
||||
enqueueReservedImportsFromKnownModules(modulesByCoordinates, pending);
|
||||
while (!pending.isEmpty()) {
|
||||
final var target = pending.removeFirst();
|
||||
final var targetId = moduleId(moduleTable, target);
|
||||
if (!resolved.add(targetId)) {
|
||||
final var moduleCoordinates = pending.removeFirst();
|
||||
final var moduleId = moduleId(moduleTable, moduleCoordinates);
|
||||
if (!resolved.add(moduleId)) {
|
||||
continue;
|
||||
}
|
||||
if (modulesByCoordinates.containsKey(target)) {
|
||||
if (modulesByCoordinates.containsKey(moduleCoordinates)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var moduleSource = stdlibEnvironment.resolveModule(target.project(), target.pathSegments());
|
||||
final var moduleSource = stdlibEnvironment.resolveModule(moduleCoordinates.project(), moduleCoordinates.pathSegments());
|
||||
if (moduleSource.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var syntheticOwnerProjectId = projectIdByName.getOrDefault(target.project(), defaultSyntheticOwnerProjectId);
|
||||
final var syntheticOwnerProjectId = projectIdByName.getOrDefault(moduleCoordinates.project(), defaultSyntheticOwnerProjectId);
|
||||
if (syntheticOwnerProjectId == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -241,15 +244,15 @@ final class PbsModuleAssemblyService {
|
||||
moduleData.barrels.addAll(loadedModule.barrelFiles().asList());
|
||||
modulesByCoordinates.put(loadedModule.coordinates(), moduleData);
|
||||
for (final var sourceFile : loadedModule.sourceFiles()) {
|
||||
moduleIdByFile.put(sourceFile.fileId(), targetId);
|
||||
moduleIdByFile.put(sourceFile.fileId(), moduleId);
|
||||
parsedSourceFiles.add(new PbsParsedSourceFile(
|
||||
sourceFile.fileId(),
|
||||
sourceFile.ast(),
|
||||
targetId,
|
||||
moduleId,
|
||||
SourceKind.SDK_INTERFACE));
|
||||
}
|
||||
for (final var barrelFile : loadedModule.barrelFiles()) {
|
||||
moduleIdByFile.put(barrelFile.fileId(), targetId);
|
||||
moduleIdByFile.put(barrelFile.fileId(), moduleId);
|
||||
}
|
||||
enqueueReservedImportsFromSourceFiles(loadedModule.sourceFiles().asList(), pending);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user