Beispiel #1
0
        Predicate GetOrCreatePredicate(ParsedPredicateReferenceExpression parsedPred,
                                        Dictionary<string, KAOSTools.MetaModel.Entity> declarations)
        {
            var idOrName = parsedPred.PredicateSignature;
            Predicate predicate;
            if (idOrName is NameExpression)
                predicate = model.Predicates().SingleOrDefault (t => t.Name == idOrName.Value);
            else if (idOrName is IdentifierExpression)
                predicate = model.Predicates().SingleOrDefault (t => t.Identifier == idOrName.Value);
            else
                throw new NotImplementedException (idOrName.GetType().Name + " is not yet supported");

            if (predicate == null) {
                if (idOrName is NameExpression)
                    predicate = new Predicate(model) { Name = idOrName.Value, Implicit = true };
                else if (idOrName is IdentifierExpression)
                    predicate = new Predicate(model) { Identifier = idOrName.Value, Implicit = true };
                else
                    throw new NotImplementedException ();

                foreach (var arg in parsedPred.ActualArguments) {
                    predicate.Arguments.Add (new PredicateArgument() { Name = arg, Type = declarations[arg] });
                }

                model.Add (predicate);
                Declarations.Add (predicate, new List<Declaration> () {
                    new Declaration (idOrName.Line, idOrName.Col, idOrName.Filename, relativePath, DeclarationType.Reference)
                });

            } else {
                // Check that same number of arguments are used (if none is already declared)
                if (predicate.Arguments.Count > 0 && parsedPred.ActualArguments.Count != predicate.Arguments.Count) {
                    throw new CompilationException ("Predicate '" + idOrName.Value + "' arguments mismatch. " +
                                                    "Expect " + predicate.Arguments.Count + " arguments but " + parsedPred.ActualArguments.Count + " received.");
                } else {
                    // Check that arguments match the declared type (if none is already declared)
                    if (predicate.Arguments.Count > 0) {
                        for (int i = 0; i < parsedPred.ActualArguments.Count; i++) {
                            var parsedArg = parsedPred.ActualArguments[i];
                            if (!declarations[parsedArg].Ancestors().Contains(predicate.Arguments[i].Type)) {
                                throw new BuilderException ("Predicate '" + idOrName + "' arguments mismatch. " +
                                                            "Argument '" + parsedArg + "' is type '" + declarations[parsedArg].FriendlyName + "' " +
                                                            "but type '" + predicate.Arguments[i].Type.FriendlyName + "' is expected. Make sure that you do not mix names and identifiers.",
                                                            parsedPred.Filename, parsedPred.Line, parsedPred.Col);
                            }
                        }
                    }

                    // Otherwise, create all needed arguments
                    else {
                        for (int i = 0; i < parsedPred.ActualArguments.Count; i++) {
                            var parsedArg = parsedPred.ActualArguments[i];
                            predicate.Arguments.Add (new PredicateArgument () {
                                Name = parsedArg,
                                Type = declarations[parsedArg]
                            });
                        }
                    }
                }

                Declarations[predicate].Add (
                    new Declaration (idOrName.Line, idOrName.Col, idOrName.Filename, relativePath, DeclarationType.Reference)
                    );

            }

            return predicate;
        }
 public static Goal Goal(this KAOSModel model, Predicate<Goal> pred)
 {
     return (Goal) model.Elements.SingleOrDefault (x => x is Goal && pred (x as Goal));
 }
Beispiel #3
0
 public static MvcHtmlString GetLink(this HtmlHelper helper, Predicate predicate)
 {
     return helper.ActionLink (predicate.FriendlyName, "GoalModel");
 }
 public static GivenType GivenType(this KAOSModel model, Predicate<GivenType> pred)
 {
     return model.Elements.SingleOrDefault (x => x is GivenType && pred(x as GivenType)) as GivenType;
 }
 public static IEnumerable<GivenType> GivenTypes(this KAOSModel model, Predicate<GivenType> pred)
 {
     return model.Elements.Where (x => x is GivenType && pred(x as GivenType)).Cast<GivenType>();
 }
 public static Entity Entity(this KAOSModel model, Predicate<Entity> pred)
 {
     return model.Elements.SingleOrDefault (x => (x is Entity & !(x is Relation)) && pred(x as Entity)) as Entity;
 }
 public static IEnumerable<Entity> Entities(this KAOSModel model, Predicate<Entity> pred)
 {
     return model.Elements.Where (x => (x is Entity & !(x is Relation)) && pred(x as Entity)).Cast<Entity>();
 }
 public static IEnumerable<Obstacle> Obstacles(this KAOSModel model, Predicate<Obstacle> pred)
 {
     return model.Elements.Where (x => x is Obstacle && pred (x as Obstacle)).Cast<Obstacle>();
 }
 public static Obstacle Obstacle(this KAOSModel model, Predicate<Obstacle> pred)
 {
     return (Obstacle) model.Elements.SingleOrDefault (x => x is Obstacle && pred (x as Obstacle));
 }
 public static IEnumerable<Goal> Goals(this KAOSModel model, Predicate<Goal> pred)
 {
     return model.Elements.Where (x => x is Goal && pred (x as Goal)).Cast<Goal>();
 }