diff --git a/Src/PCompiler/CompilerCore/Backend/CSharp/CompilationContext.cs b/Src/PCompiler/CompilerCore/Backend/CSharp/CompilationContext.cs index 2c8de713b..e3c064ec6 100644 --- a/Src/PCompiler/CompilerCore/Backend/CSharp/CompilationContext.cs +++ b/Src/PCompiler/CompilerCore/Backend/CSharp/CompilationContext.cs @@ -12,7 +12,6 @@ public CompilationContext(ICompilerConfiguration job) Names = new CSharpNameManager("PGEN_"); FileName = $"{ProjectName}.cs"; - ProjectDependencies = job.ProjectDependencies.Count == 0 ? new List() { ProjectName } : job.ProjectDependencies; GlobalFunctionClassName = "GlobalFunctions"; } @@ -24,8 +23,6 @@ public CompilationContext(ICompilerConfiguration job) public string FileName { get; } - public IList ProjectDependencies { get; } - public string GetStaticMethodQualifiedName(Function function) { return $"{GlobalFunctionClassName}.{Names.GetNameForDecl(function)}"; diff --git a/Src/PCompiler/CompilerCore/Backend/Java/CompilationContext.cs b/Src/PCompiler/CompilerCore/Backend/Java/CompilationContext.cs index 10c637d2e..786cfd6e5 100644 --- a/Src/PCompiler/CompilerCore/Backend/Java/CompilationContext.cs +++ b/Src/PCompiler/CompilerCore/Backend/Java/CompilationContext.cs @@ -11,7 +11,6 @@ public CompilationContext(ICompilerConfiguration job) Types = new TypeManager(Names); FileName = $"{ProjectName}.java"; - ProjectDependencies = job.ProjectDependencies.Count == 0 ? new List() { ProjectName } : job.ProjectDependencies; } public NameManager Names { get; } @@ -21,7 +20,5 @@ public CompilationContext(ICompilerConfiguration job) public string FileName { get; } - public IList ProjectDependencies { get; } - } } diff --git a/Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs b/Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs index ca905d570..947585259 100644 --- a/Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs +++ b/Src/PCompiler/CompilerCore/TypeChecker/Analyzer.cs @@ -161,7 +161,7 @@ private static void ApplyPropagations(IEnumerable functions, params private static Scope BuildGlobalScope(ICompilerConfiguration config, PParser.ProgramContext[] programUnits) { - var globalScope = Scope.CreateGlobalScope(config.Handler); + var globalScope = Scope.CreateGlobalScope(config); var nodesToDeclarations = new ParseTreeProperty(); // Add built-in events to the table. diff --git a/Src/PCompiler/CompilerCore/TypeChecker/DeclarationStubVisitor.cs b/Src/PCompiler/CompilerCore/TypeChecker/DeclarationStubVisitor.cs index 9db70965c..d1955be79 100644 --- a/Src/PCompiler/CompilerCore/TypeChecker/DeclarationStubVisitor.cs +++ b/Src/PCompiler/CompilerCore/TypeChecker/DeclarationStubVisitor.cs @@ -211,8 +211,11 @@ public override object VisitSafetyTestDecl([NotNull] PParser.SafetyTestDeclConte { var symbolName = context.testName.GetText(); var decl = CurrentScope.Put(symbolName, context); - decl.Main = context.mainMachine?.GetText(); - nodesToDeclarations.Put(context, decl); + if (decl != null) + { + decl.Main = context.mainMachine?.GetText(); + nodesToDeclarations.Put(context, decl); + } return null; } diff --git a/Src/PCompiler/CompilerCore/TypeChecker/Scope.cs b/Src/PCompiler/CompilerCore/TypeChecker/Scope.cs index 70abd4cf8..f41958ade 100644 --- a/Src/PCompiler/CompilerCore/TypeChecker/Scope.cs +++ b/Src/PCompiler/CompilerCore/TypeChecker/Scope.cs @@ -20,7 +20,7 @@ public class Scope private readonly IDictionary events = new Dictionary(); private readonly IDictionary eventSets = new Dictionary(); private readonly IDictionary functions = new Dictionary(); - private readonly ITranslationErrorHandler handler; + private readonly ICompilerConfiguration config; private readonly IDictionary implementations = new Dictionary(); private readonly IDictionary interfaces = new Dictionary(); private readonly IDictionary machines = new Dictionary(); @@ -32,9 +32,9 @@ public class Scope private readonly IDictionary typedefs = new Dictionary(); private readonly IDictionary variables = new Dictionary(); - private Scope(ITranslationErrorHandler handler, Scope parent = null) + private Scope(ICompilerConfiguration config, Scope parent = null) { - this.handler = handler; + this.config = config; parent?.children.Remove(this); Parent = parent; parent?.children.Add(this); @@ -80,14 +80,14 @@ private Scope(ITranslationErrorHandler handler, Scope parent = null) public IEnumerable Implementations => implementations.Values; public IEnumerable NamedModules => namedModules.Values; - public static Scope CreateGlobalScope(ITranslationErrorHandler handler) + public static Scope CreateGlobalScope(ICompilerConfiguration config) { - return new Scope(handler); + return new Scope(config); } public Scope MakeChildScope() { - return new Scope(handler, this); + return new Scope(config, this); } public IEnumerable GetAllMethods() @@ -599,6 +599,16 @@ public Implementation Put(string name, PParser.ImplementationDeclContext tree) public SafetyTest Put(string name, PParser.SafetyTestDeclContext tree) { + // check if test is from an imported project, if so, return null + string filePath = config.LocationResolver.GetLocation(tree).File.FullName; + foreach (var dependencyPath in config.ProjectDependencies) + { + if (filePath.StartsWith(dependencyPath)) + { + return null; + } + } + var safetyTest = new SafetyTest(tree, name); CheckConflicts(safetyTest, Namespace(implementations), @@ -631,7 +641,7 @@ private void CheckConflicts(IPDecl decl, params TableReader[] namespaces) IPDecl existingDecl = null; if (namespaces.Any(table => table(decl.Name, out existingDecl))) { - throw handler.DuplicateDeclaration(decl.SourceLocation, decl, existingDecl); + throw config.Handler.DuplicateDeclaration(decl.SourceLocation, decl, existingDecl); } } diff --git a/Src/PCompiler/PCommandLine/Parser/ParsePProjectFile.cs b/Src/PCompiler/PCommandLine/Parser/ParsePProjectFile.cs index 32ba18363..a7179a8df 100644 --- a/Src/PCompiler/PCommandLine/Parser/ParsePProjectFile.cs +++ b/Src/PCompiler/PCommandLine/Parser/ParsePProjectFile.cs @@ -115,7 +115,6 @@ public void ParseProjectFileForChecker(string projectFile, CheckerConfiguration var projectDependencies = new HashSet(preProjectDependencies); var inputFiles = new HashSet(preInputFiles); var projectXml = XElement.Load(projectFilePath.FullName); - projectDependencies.Add(GetProjectName(projectFilePath)); // add all input files from the current project inputFiles.UnionWith(ReadAllInputFiles(projectFilePath)); @@ -129,7 +128,9 @@ public void ParseProjectFileForChecker(string projectFile, CheckerConfiguration CommandLineOutput.WriteInfo($"==== Loading project file: {fullProjectDepenPathName.FullName}"); - if (projectDependencies.Contains(GetProjectName(fullProjectDepenPathName))) continue; + if (projectDependencies.Contains(fullProjectDepenPathName.DirectoryName)) continue; + // add path of imported project as project dependency + projectDependencies.Add(fullProjectDepenPathName.DirectoryName); var inputsAndDependencies = GetAllProjectDependencies(fullProjectDepenPathName, inputFiles, projectDependencies); projectDependencies.UnionWith(inputsAndDependencies.projectDependencies); inputFiles.UnionWith(inputsAndDependencies.inputFiles);