From 0574b7973a19301ddc183df3e38ad0dafc6679c7 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 12 Oct 2018 14:25:07 +0200 Subject: [PATCH] (HOA path) ModulesFile, PropertiesFile: optionally store location (path to file) --- prism/src/parser/ast/ModulesFile.java | 29 +++++++++++++++++++++++- prism/src/parser/ast/PropertiesFile.java | 26 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/prism/src/parser/ast/ModulesFile.java b/prism/src/parser/ast/ModulesFile.java index c5c06f39..00de1563 100644 --- a/prism/src/parser/ast/ModulesFile.java +++ b/prism/src/parser/ast/ModulesFile.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Vector; +import java.nio.file.Path; import param.BigRational; import parser.IdentUsage; @@ -94,6 +95,9 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato // Actual values of (some or all) constants private Values constantValues; + /** (Optional) The location (file) from which this ModulesFile was obtained */ + private Path location; + // Constructor public ModulesFile() @@ -1560,6 +1564,26 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato return true; } + + /* + * Sets the path to the file underlying this ModulesFile, + * or {@code null} to designate "unknown". + */ + public void setLocation(Path location) + { + // System.err.println("Model: " + location); + this.location = location; + } + + /** + * Returns the path to the file underlying this ModulesFile, if known. + * Returns {@code null} otherwise. + */ + public Path getLocation() + { + return location; + } + // Methods required for ASTElement: /** @@ -1698,7 +1722,10 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato ret.observableTypes = (observableTypes == null) ? null : new ArrayList<>(observableTypes); ret.observableVars = (observableVars == null) ? null : new ArrayList<>(observableVars); ret.constantValues = (constantValues == null) ? null : new Values(constantValues); - + + // a Path is immutable, no need for deep-copy + ret.location = location; + return ret; } } diff --git a/prism/src/parser/ast/PropertiesFile.java b/prism/src/parser/ast/PropertiesFile.java index 4c678da8..f7fd7045 100644 --- a/prism/src/parser/ast/PropertiesFile.java +++ b/prism/src/parser/ast/PropertiesFile.java @@ -26,6 +26,7 @@ package parser.ast; +import java.nio.file.Path; import java.util.*; import parser.*; @@ -58,6 +59,9 @@ public class PropertiesFile extends ASTElement // Actual values of (some or all) constants private Values constantValues; + /** (Optional) The location (file) from which this PropertiesFile was obtained */ + private Path location; + // Constructor public PropertiesFile(ModelInfo modelInfo) @@ -618,6 +622,25 @@ public class PropertiesFile extends ASTElement return constantValues; } + /** + * Sets the path to the file underlying this PropertiesFile, + * or {@code null} to designate "unknown". + */ + public void setLocation(Path location) + { + // System.err.println("Properties: " + location); + this.location = location; + } + + /** + * Returns the path to the file underlying this PropertiesFile, if known. + * Returns {@code null} otherwise. + */ + public Path getLocation() + { + return location; + } + // Methods required for ASTElement: /** @@ -683,6 +706,9 @@ public class PropertiesFile extends ASTElement ret.identUsage = (identUsage == null) ? null : identUsage.deepCopy(); ret.constantValues = (constantValues == null) ? null : new Values(constantValues); + // a Path is immutable, no need for deep-copy + ret.location = location; + return ret; } }