Skip to content

Commit

Permalink
Merge pull request #3 from HammerMaximilian/development
Browse files Browse the repository at this point in the history
development --> master 2.0.0
  • Loading branch information
HammerMaximilian authored May 24, 2024
2 parents 62c10a8 + 8c88470 commit 7b6eae1
Show file tree
Hide file tree
Showing 366 changed files with 100,074 additions and 33 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ For detailed information, please see the [User Guide](fUML-CSharp_User_Guide.pdf
* NOTE: it is suggested to store user-defined source code projects in common directory `"<fUML-C#-rootdir>\fUML-CSharp\usersrc"`
* The *usersrc* directory may contain arbitrary nested subdirectories
* Add required assemblies for uml, fuml and pscs to your project's references
* Create a `<model-name>Environment` class by deriving from class `fuml.environment.Environment`
* Create a `<model-name>Environment` class by deriving from class `fuml.environment.Environment` (or `pscs.environment.Environment` for PSCS-compatibility)
* Create a `<model-name>Model` class by deriving from class `uml.environment.InMemoryModel` (this class will contain all of your model elements)
* Create a class containing a main method and call `<model-name>Environment.Instance().Execute("<behavior-name>");` for each behavior you want to execute in subsequent order
* Build project and run executable
Expand All @@ -55,4 +55,5 @@ For detailed information, please see the [User Guide](fUML-CSharp_User_Guide.pdf
* Choose your model file
* Choose a target directory for the generated source code (`"<fUML-C#-rootdir>\fUML-CSharp\usersrc\<model-name>"` is suggested)
* Open newly generated C# project in Visual Studio and build executable(s)
* **NOTE**: Depending on the target directory path it might be necessary to adapt the project's dependencies to the *uml*, *fuml* and *pscs* assemblies since they are referenced by relative paths. This only applies if you choose a target directory structure that differes from the one suggested above.
* Run executable from command line using `<executable-name> <behavior-name> [<behavior-name> <behavior-name> <behavior-name> <...>]`
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using fuml.semantics.structuredclassifiers;
using uml.classification;
using uml.commonstructure;

namespace fuml.extensions.structuredclassifiers
{
public class UMLConformingDispatchStrategy : RedefinitionBasedDispatchStrategy
{
public override bool OperationsMatch(
Operation ownedOperation,
Operation baseOperation)
{
// Check if the owned operation is equal to or overrides the base operation.
// In this context, an owned operation overrides a base operation if:
// - base operation is directly or indirectly redefined by owned operation
// - the class that owns base operation is equal to or a base class of the class that owns owned operation
// - they have the same number of owned parameters and for each parameter the following holds:
// - direction, ordering and uniqueness are the same
// - the corresponding types are covariant, contravariant or invariant
// - the multiplicities are compatible depending on the parameter direction

bool matches = base.OperationsMatch(ownedOperation, baseOperation);
if (matches)
{
matches = IsConsistentWith(ownedOperation, baseOperation);
}

return matches;
} // operationsMatch

public bool IsConsistentWith(
Operation ownedOperation,
Operation baseOperation)
{
bool isConsistentWith;

isConsistentWith = ConformsTo(ownedOperation.class_!, baseOperation.class_!);

List<Parameter> ownedOperationParameters = ownedOperation.ownedParameter;
List<Parameter> baseOperationParameters = baseOperation.ownedParameter;

isConsistentWith = isConsistentWith && (baseOperationParameters.Count == ownedOperationParameters.Count);

for (int i = 0; isConsistentWith == true && i < ownedOperationParameters.Count; i++)
{
Parameter redefiningParameter = ownedOperationParameters.ElementAt(i);
Parameter redefinedParameter = baseOperationParameters.ElementAt(i);

isConsistentWith = isConsistentWith && (redefiningParameter.multiplicityElement.isUnique == redefinedParameter.multiplicityElement.isUnique);
isConsistentWith = isConsistentWith && (redefiningParameter.multiplicityElement.isOrdered == redefinedParameter.multiplicityElement.isOrdered);
isConsistentWith = isConsistentWith && (redefiningParameter.direction == redefinedParameter.direction);

Classifier redefiningParameterType = (Classifier)redefiningParameter.type!;
Classifier redefinedParameterType = (Classifier)redefinedParameter.type!;
isConsistentWith = isConsistentWith && (ConformsTo(redefiningParameterType, redefinedParameterType) || ConformsTo(redefinedParameterType, redefiningParameterType));

if (redefinedParameter.direction == ParameterDirectionKind.inout)
{
isConsistentWith = isConsistentWith &&
(
CompatibleWith(redefiningParameter.multiplicityElement, redefinedParameter.multiplicityElement) &&
CompatibleWith(redefinedParameter.multiplicityElement, redefiningParameter.multiplicityElement)
);
}
else if (redefinedParameter.direction == ParameterDirectionKind.in_)
{
isConsistentWith = isConsistentWith && CompatibleWith(redefinedParameter.multiplicityElement, redefiningParameter.multiplicityElement);
}
else // i.e. if((redefinedParameter.direction == ParameterDirectionKind.out_) || (redefinedParameter.direction == ParameterDirectionKind.return_))
{
isConsistentWith = isConsistentWith && CompatibleWith(redefiningParameter.multiplicityElement, redefinedParameter.multiplicityElement);
}
}

return isConsistentWith;
}

public bool ConformsTo(Classifier type, Classifier otherType)
{
bool conformsTo = false;

if (type == otherType)
{
conformsTo = true;
}
else
{
int i = 1;
while (conformsTo is false && i <= type.general.Count)
{
Classifier general = type.general.ElementAt(i);
conformsTo = ConformsTo(general, otherType);
}
}

return conformsTo;
}

public bool CompatibleWith(MultiplicityElement self, MultiplicityElement other)
{
bool compatibleWith = (other.lower <= self.lower) && ((other.upper.naturalValue == -1) || (self.upper.naturalValue <= other.upper.naturalValue));

return compatibleWith;
}
} // UMLConformingDispatchStrategy
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override bool IsReady()

List<InputPin> inputPins = ((uml.actions.Action)node!).input;
int j = 1;
while (ready & j <= inputPins.Count)
while (ready && j <= inputPins.Count)
{
ready = GetPinActivation(inputPins.ElementAt(j - 1)).IsReady();
j++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void DestroyObject(Value value,
{
List<ExtensionalValue> extensionalValues =
GetExecutionLocus().extensionalValues;
foreach (ExtensionalValue extensionalValue in extensionalValues)
foreach (ExtensionalValue extensionalValue in extensionalValues.ToList())
{
if (extensionalValue is Link link)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void StartBehavior(
// Start EventDispatchLoop
_startObjectBehavior();

if (classifier is not null)
if (classifier is null)
{
Debug.Println("[startBehavior] Starting behavior for all classifiers...");
// *** Start all classifier behaviors concurrently. ***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ public virtual Execution Dispatch(
bool isExplicitBaseClassCall = false)
{
// Extends Reference.Dispatch(Operation) by flag "isExplicitBaseClassCall"
// Propagate "isExplicitBaseClassCall" to Object_.GetMethod
// If "isExplicitBaseClassCall" is true, delegate to Object_.Dispatch(Operation, bool).
// Else, call standard method Dispatch(Operation) to maintain possible method overriding.

return (referent is not null) ? referent.Dispatch(operation, isExplicitBaseClassCall) : null!;
if(isExplicitBaseClassCall)
{
return (referent is not null) ? referent.Dispatch(operation, isExplicitBaseClassCall) : null!;
}
else
{
return Dispatch(operation);
}

} // Dispatch
} // Reference
}
Loading

0 comments on commit 7b6eae1

Please sign in to comment.