Beispiel #1
0
        private If.StmtIfThenList ParseStmtIfThenList(JsonEntity o)
        {
            EntityMixin.CheckType(o, STMT_IF_THEN_LIST);
            EntityMixin.ValueMustBeNull(o);

            return(new If.StmtIfThenList(ParseChildren(o).OfType <If.StmtIfThen>().ToList()));
        }
Beispiel #2
0
        private DeclarationList ParseDeclarationList(JsonEntity o)
        {
            EntityMixin.CheckType(o, DECLARATION_LIST);
            EntityMixin.ValueMustBeNull(o);

            return(new DeclarationList(ParseChildren(o).OfType <Declaration>().ToList()));
        }
Beispiel #3
0
        private RoutineDeclaration.ParameterList ParseParameterList(JsonEntity o)
        {
            EntityMixin.CheckType(o, PARAMETER_LIST);
            EntityMixin.ValueMustBeNull(o);

            return(new RoutineDeclaration.ParameterList(ParseChildren(o).OfType <RoutineDeclaration.Parameter>()));
        }
Beispiel #4
0
        private ExpressionList ParseExpressionList(JsonEntity o)
        {
            EntityMixin.CheckType(o, EXPRESSION_LIST);
            EntityMixin.ValueMustBeNull(o);

            return(new ExpressionList(ParseChildren(o).OfType <Expression>()));
        }
Beispiel #5
0
        private RoutineDeclaration ParseRoutine(JsonEntity o)
        {
            EntityMixin.CheckType(o, ROUTINE);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                // name
                var name = children.OfType <Identifier>().Single();
                // is foreign? (may be null in JSON but not in an object model)
                var isForeign = children.OfType <ForeignSpec>().Select(spec => spec.IsForeign).DefaultIfEmpty(false)
                                .SingleOrDefault();
                // parameters list
                var parameters = children.OfType <RoutineDeclaration.ParameterList>().Single().Parameters;
                // return type (may be null is JSON but not in an object model)
                var returnType = children.OfType <UnitRef>().DefaultIfEmpty(UnitRef.Void).SingleOrDefault();
                // precondition body (may be null)
                var pre = children.OfType <PreCondition>().DefaultIfEmpty(new PreCondition()).SingleOrDefault();
                // routine body
                var body = children.OfType <EntityList>().Single().Children;
                // postcondition body (may be null)
                var post = children.OfType <PostCondition>().DefaultIfEmpty(new PostCondition()).SingleOrDefault();

                // ReSharper disable ArgumentsStyleNamedExpression
                return new RoutineDeclaration(
                    name: name,
                    isForeign: isForeign,
                    parameters: parameters,
                    returnType: returnType,
                    body: body,
                    preCondition: pre,
                    postCondition: post);
            }));
        }
Beispiel #6
0
        private EntityList ParseEntityList(JsonEntity o)
        {
            EntityMixin.CheckType(o, ENTITY_LIST);
            EntityMixin.ValueMustBeNull(o);

            return(new EntityList(ParseChildren(o).ToList()));
        }
Beispiel #7
0
        private Return ParseReturn(JsonEntity o)
        {
            EntityMixin.CheckType(o, RETURN);
            EntityMixin.ValueMustBeNull(o);

            var optionalExpression = ParseChildren(o).OfType <Expression>().FirstOrDefault();

            return(new Return(optionalExpression));
        }
Beispiel #8
0
        private PostCondition ParsePostCondition(JsonEntity o)
        {
            EntityMixin.CheckType(o, POSTCONDITION);
            EntityMixin.ValueMustBeNull(o);

            var expressions = ParseChildren(o).OfType <ExpressionList>().FirstOrDefault();

            return(new PostCondition(expressions));
        }
Beispiel #9
0
        private Callee ParseCallee(JsonEntity o)
        {
            EntityMixin.CheckType(o, CALLEE);
            EntityMixin.ValueMustBeNull(o);

            var unit    = o.Children[0] == null ? null : ParseIdentifier(o.Children[0]);
            var routine = ParseIdentifier(o.Children[1]);

            return(new Callee(unit, routine));
        }
Beispiel #10
0
        public Compilation ParseCompilation(JsonEntity o)
        {
            EntityMixin.CheckType(o, COMPILATION);
            EntityMixin.ValueMustBeNull(o);

            var children     = ParseChildren(o).ToList();
            var declarations = children.OfType <DeclarationList>().FirstOrDefault()?.Declarations;
            var routine      = children.OfType <RoutineDeclaration>().FirstOrDefault();

            return(new Compilation(declarations, routine));
        }
Beispiel #11
0
        private If.StmtIfThen ParseStmtIfThen(JsonEntity o)
        {
            EntityMixin.CheckType(o, STMT_IF_THEN);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var condition = children.OfType <Expression>().Single();
                var body = children.OfType <EntityList>().Single().Children;
                return new If.StmtIfThen(condition, body);
            }));
        }
Beispiel #12
0
        private Reference ParseReference(JsonEntity o)
        {
            EntityMixin.CheckType(o, REFERENCE);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var name = children.OfType <Identifier>().Single();

                return new Reference(name);
            }));
        }
Beispiel #13
0
        private If ParseIf(JsonEntity o)
        {
            EntityMixin.CheckType(o, IF);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var pairs = children.OfType <If.StmtIfThenList>().Single();
                var @else = children.OfType <EntityList>().SingleOrDefault();
                return new If(pairs, @else);
            }));
        }
Beispiel #14
0
        private RoutineDeclaration.Parameter ParseParameter(JsonEntity o)
        {
            EntityMixin.CheckType(o, PARAMETER);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                // TODO: replace with more general TYPE (when it will be specified and implemented)
                var type = children.OfType <UnitRef>().Single();
                var name = children.OfType <Identifier>().Single();
                return new RoutineDeclaration.Parameter(type, name);
            }));
        }
Beispiel #15
0
        private Call ParseCall(JsonEntity o)
        {
            EntityMixin.CheckType(o, CALL);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var callee = children.OfType <Callee>().Single();
                var arguments = children.OfType <ExpressionList>().SingleOrDefault();

                return new Call(callee, arguments);
            }));
        }
Beispiel #16
0
        private Assignment ParseAssignment(JsonEntity o)
        {
            EntityMixin.CheckType(o, ASSIGNMENT);
            EntityMixin.ValueMustBeNull(o);

            var children = ParseChildren(o).OfType <Expression>().ToList();

            if (children.Count != 2)
            {
                throw new JsonFormatException(o,
                                              $"assignment must have exactly 2 expression children, got: {children.Count}");
            }

            var lValue = children[0];
            var rValue = children[1];

            return(new Assignment(lValue, rValue));
        }
Beispiel #17
0
        private VariableDeclaration ParseVariable(JsonEntity o)
        {
            EntityMixin.CheckType(o, VARIABLE);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var name = children.OfType <Identifier>().Single();
                var refValSpec = children.OfType <UnitDeclaration.RefValSpec>()
                                 .DefaultIfEmpty(new UnitDeclaration.RefValSpec()).SingleOrDefault();
                var concurrentSpec = children.OfType <UnitDeclaration.ConcurrentSpec>().SingleOrDefault();
                var foreignSpec = children.OfType <ForeignSpec>().SingleOrDefault();

                var type = children.OfType <UnitRef>().Single();
                var init = children.OfType <Expression>().Single();

                return new VariableDeclaration(name, type, init);
            }));
        }
Beispiel #18
0
        private UnitDeclaration ParseUnit(JsonEntity o)
        {
            EntityMixin.CheckType(o, UNIT);
            EntityMixin.ValueMustBeNull(o);

            return(Guard(o, children =>
            {
                var name = children.OfType <Identifier>().Single();
                var refValSpec = children.OfType <UnitDeclaration.RefValSpec>().Single();
                var concurrentSpec = children.OfType <UnitDeclaration.ConcurrentSpec>().SingleOrDefault();
                var concurrent = concurrentSpec?.Concurrent ?? false;
                var foreignSpec = children.OfType <ForeignSpec>().SingleOrDefault();
                var isForeign = foreignSpec?.IsForeign ?? false;
                var declarations = children.OfType <DeclarationList>().SingleOrDefault()?.Declarations;
                var invariants = children.OfType <ExpressionList>().SingleOrDefault()?.Expressions;

                return new UnitDeclaration(name, refValSpec, concurrent, isForeign, declarations, invariants);
            }));
        }