diff --git a/org.coreasm.engine/pom.xml b/org.coreasm.engine/pom.xml index 049f7cbd..00d989c2 100644 --- a/org.coreasm.engine/pom.xml +++ b/org.coreasm.engine/pom.xml @@ -11,6 +11,10 @@ ../org.coreasm.parent + + true + + @@ -60,7 +64,7 @@ maven-surefire-plugin 2.16 - true + ${skipTests} false 0 @@ -103,7 +107,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.0 + 3.8.0 1.7 1.7 @@ -138,7 +142,7 @@ junit junit - 4.8.2 + 4.12 org.coreasm diff --git a/org.coreasm.engine/src/org/coreasm/engine/Specification.java b/org.coreasm.engine/src/org/coreasm/engine/Specification.java index 3666e54f..ba3f046c 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/Specification.java +++ b/org.coreasm.engine/src/org/coreasm/engine/Specification.java @@ -323,11 +323,12 @@ public Set getPluginNames() { * @see #loadSpec(String) */ public static ArrayList loadSpec(Specification mainSpec, String fileName) throws IOException { - String specRoot = ""; - if (mainSpec != null) - specRoot = mainSpec.getFileDir() + File.separator; - - return loadSpec(specRoot + fileName); + if (mainSpec == null) { + return loadSpec(new File(fileName)); + } + else { + return loadSpec(new File(mainSpec.getFileDir(), fileName)); + } } /** diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java index 8dce06f0..db93a3a4 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/AbstractStorage.java @@ -173,7 +173,7 @@ public interface AbstractStorage extends State { * This method should only be called when there is a state in the stack. * * @param u the update multiset - * @see #pushState() + * @see #pushState(String pluginName) */ public void apply(Set u); diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java index ca1bb38b..71129f57 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/HashStorage.java @@ -140,7 +140,8 @@ private Stack getUpdateStackPluginNames() { private boolean isStateStacked() { return !getUpdateStack().isEmpty(); } - + + @Override public void initAbstractStorage() { clearState(); @@ -217,7 +218,8 @@ private void loadVocabularyExtender(VocabularyExtender ve) throws NameConflictEx addRule(name, veRules.get(name)); } } - + + @Override public synchronized void fireUpdateSet(Set updateSet) throws InvalidLocationException { // Cannot fire updates while state stack is not empty. // Doing this check will allow us to bypass calling setValue(...) @@ -231,16 +233,14 @@ public synchronized void fireUpdateSet(Set updateSet) throws InvalidLoca monitoredCache.clear(); } + @Override public Element getChosenProgram(Element agent) { - Element p = null; - Element s = null; - try { - p = getValue(new Location(PROGRAM_FUNCTION_NAME, ElementList.create(agent))); + Element p = getValue(new Location(PROGRAM_FUNCTION_NAME, ElementList.create(agent))); if (p instanceof RuleElement) return p; else { - capi.error("Value of program(" + s + ") is not a Rule element."); + capi.error("Value of program(" + agent + ") is not a Rule element."); return Element.UNDEF; } } catch (InvalidLocationException e) { @@ -250,23 +250,6 @@ public Element getChosenProgram(Element agent) { } } -// /** -// * @see org.coreasm.engine.absstorage.AbstractStorage#getState() -// */ -// public State getState() { -// return this; -// } -// -// /** -// * @see org.coreasm.engine.absstorage.AbstractStorage#setState(org.coreasm.engine.absstorage.State) -// */ -// public void setState(State newState) { -// if (!stateStacked) -// this.state = newState; -// else -// throw new EngineError("Cannot set state when the state stack is not empty."); -// } -// public Element getValue(Location l) throws InvalidLocationException { Element e = null; FunctionElement f = this.getFunction(l.name); @@ -339,6 +322,7 @@ private Element getStackedValue(Location loc) { return null; } + @Override public void aggregateUpdates() { logger.debug("Aggregating updates."); UpdateMultiset updateInsts = capi.getScheduler().getUpdateInstructions(); @@ -359,14 +343,15 @@ public void aggregateUpdates() { /** * @see AbstractStorage#compose(UpdateMultiset, UpdateMultiset) */ + @Override public UpdateMultiset compose(UpdateMultiset updateSet1, UpdateMultiset updateSet2) { // instantiate engine composition API, and set update multiset CompositionAPIImp compAPI = new CompositionAPIImp(); compAPI.setUpdateInstructions(updateSet1, updateSet2); - for (Aggregator p: aggregatorPlugins) + for (Aggregator p : aggregatorPlugins) // synchronized (p) { - ((Aggregator)p).compose(compAPI); + p.compose(compAPI); // } // if (compAPI.isConsistent() == false) @@ -379,16 +364,17 @@ public UpdateMultiset compose(UpdateMultiset updateSet1, UpdateMultiset updateSe /** * @see AbstractStorage#performAggregation(UpdateMultiset) */ + @Override public Set performAggregation(UpdateMultiset updateInsts) { // instantiate engine aggregation API, and set update multiset AggregationAPIImp aggAPI = new AggregationAPIImp(); aggAPI.setUpdateInstructions(updateInsts); // for each plugin - for (Aggregator p: aggregatorPlugins) - ((Aggregator)p).aggregateUpdates(aggAPI); + for (Aggregator p : aggregatorPlugins) + p.aggregateUpdates(aggAPI); - if (aggAPI.isConsistent() == false) { + if (!aggAPI.isConsistent()) { String msg = "Inconsistent aggregated results."; if (aggAPI.getFailedInstructions().size() > 0) { @@ -405,7 +391,8 @@ public Set performAggregation(UpdateMultiset updateInsts) { // get resultant updates from agg API return aggAPI.getResultantUpdates(); } - + + @Override public synchronized boolean isConsistent(Collection updateSet) { Collection uSet = updateSet; lastInconsistentUpdates = null; @@ -430,6 +417,7 @@ public synchronized boolean isConsistent(Collection updateSet) { return true; } + @Override public Element getNewElement() { return new Element(); } @@ -481,8 +469,9 @@ public void popState(String pluginName) { * This method should only be called when there is a state in the stack. * * @param updates the update multiset - * @see #pushState() + * @see #pushState(String pluginName) */ + @Override public synchronized void apply(Set updates) { if (isStateStacked()) { Stack> updateStack = getUpdateStack(); @@ -541,6 +530,7 @@ public Set getLocations() { * Return true if the given name is the name * of a function in the state. */ + @Override public boolean isFunctionName(String token) { return getFunction(token) != null; } @@ -549,6 +539,7 @@ public boolean isFunctionName(String token) { * Return true if the given name is the name * of a function in the state. */ + @Override public boolean isUniverseName(String token) { return getUniverse(token) != null; } @@ -557,23 +548,14 @@ public boolean isUniverseName(String token) { * Return true if the given name is the name * of a rule in the state. */ + @Override public boolean isRuleName(String token) { return getRule(token) != null; } + @Override public synchronized void clearState() { state = new HashState(); - /* - * The following universe and functions are moved to Kernel - try { - state.addFunction(SELF_FUNCTION_NAME, new MapFunction(Element.UNDEF)); - state.addFunction(PROGRAM_FUNCTION_NAME, new MapFunction(Element.UNDEF)); - state.addUniverse(AGENTS_UNIVERSE_NAME, new UniverseElement()); - } catch (NameConflictException e) { - // This should not happen! - throw new EngineError(e); - } - /**/ } public String getFunctionName(FunctionElement function) { @@ -584,6 +566,7 @@ public String toString() { return state.toString(); } + @Override public Set getLastInconsistentUpdate() { return lastInconsistentUpdates; } @@ -637,9 +620,17 @@ public void setValue(List args, Element value) throws Unmodif public E getValue(String name) { return table.get(name); } + + public String getKey(E value) { + for (Entry f: table.entrySet()) { + if (f.getValue().equals(value)) + return f.getKey(); + } + return null; + } public Collection values() { - return (Collection)table.values(); + return table.values(); } public Collection getNames() { @@ -723,10 +714,17 @@ public HashState() { functionElements.setValue(FUNCTION_ELEMENT_FUNCTION_NAME, functionElements); } + @Override public Map getUniverses() { return universeElements.getTableClone(); } + @Override + public AbstractUniverse getUniverse(String name) { + return universeElements.getValue(name); + } + + @Override public synchronized void addUniverse(String name, AbstractUniverse universe) throws NameConflictException { if (universe == null) throw new NullPointerException(); @@ -735,10 +733,32 @@ public synchronized void addUniverse(String name, AbstractUniverse universe) thr universeElements.setValue(name, universe); } + @Override public Map getFunctions() { return functionElements.getTableClone(); } + @Override + public FunctionElement getFunction(String name) { + FunctionElement res = functionElements.getValue(name); + if (res == null) + res = universeElements.getValue(name); + return res; + } + + /* (non-Javadoc) + * @see org.coreasm.engine.absstorage.State#getFunctionName(org.coreasm.engine.absstorage.FunctionElement) + */ + @Override + public String getFunctionName(FunctionElement function) { + String result = functionElements.getKey(function); + if (result == null && function instanceof AbstractUniverse) { + result = universeElements.getKey((AbstractUniverse)function); + } + return result; + } + + @Override public synchronized void addFunction(String name, FunctionElement function) throws NameConflictException { if (function instanceof AbstractUniverse) addUniverse(name, (AbstractUniverse)function); @@ -749,10 +769,17 @@ public synchronized void addFunction(String name, FunctionElement function) thro functionElements.setValue(name, function); } + @Override public Map getRules() { return ruleElements.getTableClone(); } + @Override + public RuleElement getRule(String name) { + return ruleElements.getValue(name); + } + + @Override public synchronized void addRule(String name, RuleElement rule) throws NameConflictException { if (rule == null) throw new NullPointerException(); @@ -761,6 +788,7 @@ public synchronized void addRule(String name, RuleElement rule) throws NameConfl ruleElements.setValue(name, rule); } + @Override public Set getLocations() { HashSet locations = new HashSet(); Map funcs = getFunctions(); @@ -770,6 +798,7 @@ public Set getLocations() { return locations; } + @Override public Element getValue(Location loc) throws InvalidLocationException { if (nameExists(loc.name)) { Element id; @@ -808,6 +837,7 @@ public Element getValue(Location loc) throws InvalidLocationException { * @throws InvalidLocationException if the location is not modifiable. * @see State#setValue(Location, Element) */ + @Override public synchronized void setValue(Location l, Element v) throws InvalidLocationException { if (!nameExists(l.name)) { FunctionElement f = new MapFunction(Element.UNDEF); @@ -836,30 +866,6 @@ public synchronized void setValue(Location l, Element v) throws InvalidLocationE throw new InvalidLocationException(l + " is not a valid location."); } - /* - public synchronized void setValue(Location l, Element v) throws InvalidLocationException { - if (nameExists(l.name)) { - Element id; - try { - id = getIdentifier(l.name); - } catch (IdentifierNotFoundException e) { - throw new InvalidLocationException(e); - } - if (id instanceof FunctionElement && ((FunctionElement)id).isModifiable()) - try { - ((FunctionElement) id).setValue(l.args, v); - } catch (UnmodifiableFunctionException e) { - throw new InvalidLocationException(e); - } - else - throw new InvalidLocationException("Not a valid location."); - } else { - FunctionElement f = new MapFunction(Element.UNDEF); - addFunction(id, f); - throw new InvalidLocationException("There is no such function in the state."); - } - } - */ /** * Returns the rule/function/universe in the state @@ -870,7 +876,7 @@ public synchronized void setValue(Location l, Element v) throws InvalidLocationE * @throws IdentifierNotFoundException if there * is no such rule/function/universe in the state */ - public Element getIdentifier(String name) + private Element getIdentifier(String name) throws IdentifierNotFoundException { Element id = null; id = (Element)universeElements.getValue(name); @@ -901,21 +907,6 @@ private boolean nameExists(String name) { || ruleElements.containsName(name); } - public FunctionElement getFunction(String name) { - FunctionElement res = functionElements.getValue(name); - if (res == null) - res = universeElements.getValue(name); - return res; - } - - public AbstractUniverse getUniverse(String name) { - return universeElements.getValue(name); - } - - public RuleElement getRule(String name) { - return ruleElements.getValue(name); - } - public String toString() { StringWriter strWriter = new StringWriter(); PrintWriter writer = new PrintWriter(strWriter); @@ -977,21 +968,6 @@ public String toString() { return strWriter.toString(); } - /* (non-Javadoc) - * @see org.coreasm.engine.absstorage.State#getFunctionName(org.coreasm.engine.absstorage.FunctionElement) - */ - public String getFunctionName(FunctionElement function) { - for (Entry f: functionElements.table.entrySet()) { - if (f.getValue().equals(function)) - return f.getKey(); - } - for (Entry u : universeElements.table.entrySet()) { - if (u.getValue().equals(function)) - return u.getKey(); - } - return null; - } - /* * Cut the string to a specific length */ @@ -1006,15 +982,18 @@ private String reformatFunctionValue(String value) { return result.toString(); } - + + @Override public FunctionElement getFunctionElementFunction() { return functionElements; } + @Override public FunctionElement getRuleElementFunction() { return ruleElements; } + @Override public FunctionElement getUniverseElementFunction() { return universeElements; } diff --git a/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java b/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java index 66919d06..f2e00e3d 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java +++ b/org.coreasm.engine/src/org/coreasm/engine/absstorage/State.java @@ -52,16 +52,6 @@ public interface State { public void addUniverse(String name, AbstractUniverse universe) throws NameConflictException; -// /** -// * Removes a universe from the state. -// * -// * @param universe universe to be removed -// * @throws IdentifierNotFoundException if no such universe -// * is found in the state -// */ -// public void removeUniverse(UniverseElement universe) -// throws IdentifierNotFoundException; - /** * Set of all the functions (including universes) defined in the state. * @@ -95,16 +85,6 @@ public void addUniverse(String name, AbstractUniverse universe) */ public void addFunction(String name, FunctionElement function) throws NameConflictException; - -// /** -// * Removes a function from the state. -// * -// * @param function function to be removed. -// * @throws IdentifierNotFoundException if there is no -// * such function in the state. -// */ -// public void removeFunction(FunctionElement function) -// throws IdentifierNotFoundException; /** * Set of all the rules defined in @@ -133,16 +113,6 @@ public void addFunction(String name, FunctionElement function) public void addRule(String name, RuleElement rule) throws NameConflictException; -// /** -// * Removes a rule from the state. -// * -// * @param rule the rule to be removed -// * @throws IdentifierNotFoundException if there is no -// * such rule in the state. -// */ -// public void removeRule(RuleElement rule) -// throws IdentifierNotFoundException; - /** * Set of all the defined locations in the state * that have a value other than undef diff --git a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java index 84e36f57..ef3c1108 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java +++ b/org.coreasm.engine/src/org/coreasm/engine/interpreter/InterpreterImp.java @@ -362,7 +362,6 @@ else if (token.equals(Kernel.KW_SELF)) private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { final AbstractStorage storage = capi.getStorage(); final String gClass = pos.getGrammarClass(); - String x = pos.getToken(); // If the current node is a function/rule term if (gClass.equals(ASTNode.FUNCTION_RULE_CLASS)) { @@ -372,7 +371,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { // If the current node is of the form 'x' or 'x(...)' if (frNode.hasName()) { - x = frNode.getName(); + final String x = frNode.getName(); // If the current node is of the form 'x' with no arguments if (!frNode.hasArguments()) { @@ -383,14 +382,14 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { else { // If this 'x' refers to a function in the state... final FunctionElement f = storage.getFunction(x); -// if (storage.isFunctionName(x)) { + if (f != null) { final Location l = new Location(x, ElementList.NO_ARGUMENT, f.isModifiable()); try { pos.setNode(l, null, storage.getValue(l)); } catch (InvalidLocationException e) { throw new EngineError("Location is invalid in 'interpretExpressions()'." + - "This cannot happen!"); + "This cannot happen!", e); } } else // if this 'x' is not defined before... @@ -399,11 +398,19 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { } } } else { // if current node is 'x(...)' (with arguments) - + // If this 'x' refers to a function in the state... FunctionElement f = storage.getFunction(x); - if (getEnv(x) instanceof FunctionElement) - f = (FunctionElement)getEnv(x); + String name = null; + if (f != null) { + name = x; + } + + if (getEnv(x) instanceof FunctionElement) { + f = (FunctionElement) getEnv(x); + name = null; + } + if (f == null) { try { Element value = storage.getValue(new Location(x, ElementList.NO_ARGUMENT)); @@ -412,6 +419,7 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { } catch (InvalidLocationException e) { } } + if (f != null) { final List args = frNode.getArguments(); // look for the parameter that needs to be evaluated @@ -419,14 +427,13 @@ private ASTNode interpretExpressions(ASTNode pos) throws InterpreterException { if (toBeEvaluated == null) { // if all nodes are evaluated... final ElementList vList = EngineTools.getValueList(args); - final String name = storage.getFunctionName(f); if (name != null) { final Location l = new Location(name, vList, f.isModifiable()); try { pos.setNode(l, null, storage.getValue(l)); } catch (InvalidLocationException e) { throw new EngineError("Location is invalid in 'interpretExpressions()'." + - "This cannot happen!"); + "This cannot happen!", e); } } else diff --git a/org.coreasm.engine/src/org/coreasm/engine/parser/_.java b/org.coreasm.engine/src/org/coreasm/engine/parser/_.java deleted file mode 100644 index 398f35c0..00000000 --- a/org.coreasm.engine/src/org/coreasm/engine/parser/_.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.coreasm.engine.parser; - -public class _ { - -} diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java index 077eda44..35d99a96 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugin/Plugin.java @@ -51,9 +51,10 @@ public Plugin() { super(); } + private final String pluginName = this.getClass().getSimpleName(); @Override public final String getName() { - return this.getClass().getSimpleName(); + return pluginName; } @Override diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java index 8a71a96d..ba03a105 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/kernelextensions/KernelExtensionsPlugin.java @@ -243,10 +243,18 @@ public ASTNode interpret(Interpreter interpreter, ASTNode pos) if (toBeEvaluated == null) { // if all nodes are evaluated... ElementList vList = EngineTools.getValueList(args); - - //look for the function in the state - Element value = null; - String fname = capi.getStorage().getFunctionName(fe); + + Element value; + String fname; + if (fe.getFClass().equals(FunctionElement.FunctionClass.fcStatic)) { + // value can be returned directly + fname = null; + } + else { + // look for the function in the state + fname = capi.getStorage().getFunctionName(fe); + } + Location loc = null; if (fname != null) { try { diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java index ec3b8b8d..3447233a 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/modularity/ModularityPlugin.java @@ -63,8 +63,8 @@ public class ModularityPlugin extends Plugin implements ParserPlugin, public static final String PLUGIN_NAME = ModularityPlugin.class.getSimpleName(); - private final String[] keywords = {"CoreModule", "include"}; - private final String[] operators = {}; + private static final String[] keywords = {"CoreModule", "include"}; + private static final String[] operators = {}; private Map parsers = null; @@ -230,21 +230,18 @@ public Node map(Object[] from) { private ArrayList injectModules(List lines, String relativePath) { // CHANGE: Includes inside included specifications will be looked up relative to the including specification now ArrayList newSpec = new ArrayList(); - String useRegex; - Pattern usePattern; - Matcher useMatcher; // compile pattern to find "include " directives using regular expression - useRegex = "^[\\s]*[i][n][c][l][u][d][e][\\s]+"; - usePattern = Pattern.compile(useRegex); + String useRegex = "^[\\s]*[i][n][c][l][u][d][e][\\s]+"; + Pattern usePattern = Pattern.compile(useRegex); - for (SpecLine line: lines) { + for (SpecLine line : lines) { // get an "include" directive matcher object for the line - useMatcher = usePattern.matcher(line.text); + Matcher useMatcher = usePattern.matcher(line.text); // if match found if (useMatcher.find()) { // are there inner include files? - + // get the include file name and load the file String fileName = useMatcher.replaceFirst("").trim(); // remove potential quotation marks @@ -252,28 +249,29 @@ private ArrayList injectModules(List lines, String relativeP fileName = fileName.substring(1, fileName.length()-1); // CHANGE: make sure that filenames have the same format to ensure that equal paths match, not only equal include statements try { - fileName = (new File(relativePath + File.separator + fileName)).getCanonicalPath(); + fileName = (new File(relativePath, fileName)).getCanonicalPath(); } catch (IOException e) { + logger.info("ModularityPlugin: unable to get canonical path for module '" + fileName + "'. Check " + line.fileName + ":" + line.line + "."); } + if (loadedModules.contains(fileName)) - logger.info( - "ModularityPlugin: Skipping module '" + fileName + "' since it's already loaded."); - else + logger.info("ModularityPlugin: Skipping module '" + fileName + "' since it's already loaded."); + else try { loadedModules.add(fileName); - logger.info( - "ModularityPlugin: Loading module '" + fileName + "'."); + logger.info("ModularityPlugin: Loading module '" + fileName + "'."); + List newLines = injectModules(Specification.loadSpec(fileName), fileName.substring(0, fileName.lastIndexOf(File.separator))); - for (SpecLine newLine: newLines) - newSpec.add(newLine); + newSpec.addAll(newLines); } catch (IOException e) { - capi.error("Modularity plugin cannot load module file '" + capi.error("Modularity plugin cannot load module file '" + fileName + "'. The error is:" + Tools.getEOL() + e.getMessage() + Tools.getEOL() + "Check " + line.fileName + ":" + line.line + "."); } - } else + } else { newSpec.add(line); + } } return newSpec; } diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java index ff70e169..bbc282dd 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/options/OptionsPlugin.java @@ -252,11 +252,10 @@ public void fireOnModeTransition(EngineMode source, EngineMode target) { private void loadProperties() { Set definedOptions = capi.getSpec().getOptions(); ASTNode currentNode = capi.getParser().getRootNode().getFirst(); - OptionNode optionNode = null; while (currentNode != null) { if (currentNode instanceof OptionNode) { - optionNode = (OptionNode)currentNode; + OptionNode optionNode = (OptionNode)currentNode; if (definedOptions.contains(optionNode.getOptionName())) { try { String pluginName = optionNode.getOptionName().substring(0, optionNode.getOptionName().indexOf('.')); diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java index 009a179e..df5bfc06 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/set/SetPlugin.java @@ -835,13 +835,16 @@ private Update aggregateLocationForComposition(Location l, PluginCompositionAPI // value should be a set if (value instanceof SetElement) { Set resultSet = new HashSet(((SetElement)value).enumerate()); + Set removeFromSet = new HashSet(); for (Element e: resultSet) { Update removeUpdate = new Update(l, e, SETREMOVE_ACTION, (Element)null, null); - if (!uMset2.contains(removeUpdate)) - resultSet.add(e); + if (uMset2.contains(removeUpdate)) + removeFromSet.add(e); } + + resultSet.removeAll(removeFromSet); for (Update u: uMset2) { if (u.action.equals(SETADD_ACTION)) diff --git a/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java b/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java index 2b385c2b..6ccd4ebe 100644 --- a/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java +++ b/org.coreasm.engine/src/org/coreasm/engine/plugins/signature/SignaturePlugin.java @@ -610,6 +610,7 @@ else if (typeCheckingMode == CheckMode.WARN) { "The " + Tools.getIth(i+1) + " argument in update '" + updateToString(u) + "' is not a member of " + domName + " and does not match the signature of " + "function '" + u.loc.name + ": " + func.getSignature() + "'." + + (!isUpdateSuccessful && domain instanceof UniverseElement ? " The update was not successful so it might not be added to the universe." : "") + getContextInfo(u); /* @@ -652,6 +653,7 @@ else if (typeCheckingMode == CheckMode.WARN) { "The value of update '" + updateToString(u) + "' is not a member of " + rangeName + " and does not match the signature of " + "function '" + u.loc.name + ": " + func.getSignature() + "'." + + (!isUpdateSuccessful && range instanceof UniverseElement ? " The update was not successful so it might not be added to the universe." : "") + getContextInfo(u); /* "There is an update for function '" + u.loc.name + diff --git a/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm b/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm new file mode 100644 index 00000000..23504059 --- /dev/null +++ b/org.coreasm.engine/test-rsc/plugin-tests/set/Set4_compose.casm @@ -0,0 +1,190 @@ +CoreASM Set4_compose + +use Standard + +init Start + +/* + * @minsteps 1 + * @maxsteps 1 + */ + +function foo : -> SET +rule Start = seqblock + Case1a() + + Case1b() + + Case2() + + Case3a_add() + + Case3a_remove() + + Case3a_mixed() + + Case3b_i() + + Case3b_ii_1() + + Case3b_ii_2() + + Case3b_iii() +endseqblock + + +rule Case1a = { + seq + foo := {} + next { + seq + add 1 to foo + next + skip + } + next { + // @require "Case1a: {1}" + print "Case1a: " + foo + } +} + +rule Case1b = { + seq + foo := {} + next { + seq + skip + next + add 1 to foo + } + next { + // @require "Case1b: {1}" + print "Case1b: " + foo + } +} + +rule Case2 = { + seq + foo := {3} + next { + seq + skip + next { + remove 1 from foo + foo := {2} + add 2 to foo + } + } + next { + // @require "Case2: {2}" + print "Case2: " + foo + } +} + +rule Case3a_add = { + seq + foo := {} + next { + seq + foo := {1} + next + add 2 to foo + } + next { + // @require "Case3a_add: {1, 2}" + print "Case3a_add: " + foo + } +} + +rule Case3a_remove = { + seq + foo := {} + next { + seq + foo := {1, 2} + next + remove 2 from foo + } + next { + // @require "Case3a_remove: {1}" + print "Case3a_remove: " + foo + } +} + + +rule Case3a_mixed = { + seq + foo := {} + next { + seq + foo := {1, 2} + next { + remove 2 from foo + add 3 to foo + } + } + next { + // @require "Case3a_mixed: {1, 3}" + print "Case3a_mixed: " + foo + } +} + +rule Case3b_i = { + seq + foo := {3} + next { + seq + add 1 to foo + next + remove 1 from foo + } + next { + // @require "Case3b_i: {3}" + print "Case3b_i: " + foo + } +} + +rule Case3b_ii_1 = { + seq + foo := {3} + next { + seq + remove 3 from foo + next + add 3 to foo + } + next { + // @require "Case3b_ii_1: {3}" + print "Case3b_ii_1: " + foo + } +} + +rule Case3b_ii_2 = { + seq + foo := {3} + next { + seq + remove 1 from foo + next + add 1 to foo + } + next { + // @require "Case3b_ii_2: {1, 3}" + print "Case3b_ii_2: " + foo + } +} + +rule Case3b_iii = { + seq + foo := {3} + next { + seq + add 1 to foo + next + remove 2 from foo + } + next { + // @require "Case3b_iii: {1, 3}" + print "Case3b_iii: " + foo + } +} \ No newline at end of file diff --git a/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java b/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java new file mode 100644 index 00000000..5159f938 --- /dev/null +++ b/org.coreasm.engine/test/org/coreasm/engine/test/plugins/set/Set4_compose.java @@ -0,0 +1,25 @@ +package org.coreasm.engine.test.plugins.set; + +import org.coreasm.engine.test.TestAllCasm; +import org.junit.BeforeClass; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.LinkedList; + +public class Set4_compose extends TestAllCasm { + + @BeforeClass + public static void onlyOnce() { + URL url = Set4_compose.class.getClassLoader().getResource("."); + + try { + testFiles = new LinkedList(); + getTestFile(testFiles, new File(url.toURI()).getParentFile(), Set4_compose.class); + } + catch (URISyntaxException e) { + e.printStackTrace(); + } + } +} diff --git a/org.coreasm.parent/pom.xml b/org.coreasm.parent/pom.xml index 68a81859..f70c2c45 100644 --- a/org.coreasm.parent/pom.xml +++ b/org.coreasm.parent/pom.xml @@ -98,10 +98,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.0 1.7 1.7 + false diff --git a/org.coreasm.ui.carma/pom.xml b/org.coreasm.ui.carma/pom.xml index 360c722b..cec3b479 100644 --- a/org.coreasm.ui.carma/pom.xml +++ b/org.coreasm.ui.carma/pom.xml @@ -60,9 +60,11 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.0 1.7 1.7 + false @@ -87,4 +89,4 @@ org.coreasm - \ No newline at end of file +