Esempio n. 1
0
        public void NamespaceTest()
        {
            TypesTable             typeTable = new TypesTable();
            StandardLibraryCreator sl        = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typeTable);
            Namespace basic        = typeTable.Library.RootNamespace;
            Namespace subNamespace = new Namespace("subNamespace", basic);

            Classifier integerType = typeTable.Library.Integer;
            Classifier realType    = typeTable.Library.Real;
            Classifier anyType     = typeTable.Library.Any;

            Class baseClass = new Class(typeTable, subNamespace, "Base");

            baseClass.Properties.Add(new Property("Name", PropertyType.One, integerType));
            baseClass.Operations.Add(new Operation("Work", true, integerType, new Parameter[] { }));

            Class A = new Class(typeTable, basic, "A");
            Class B = new Class(typeTable, basic, "B");

            A.SuperClass.Add(baseClass);
            B.SuperClass.Add(baseClass);

            typeTable.RegisterType(baseClass);
            typeTable.RegisterType(A);
            typeTable.RegisterType(B);
            Assert.IsTrue(B.ConformsTo(baseClass));
            Assert.IsFalse(B.ConformsTo(A));

            Assert.AreEqual(baseClass.ToString(), "::subNamespace::Base");
        }
Esempio n. 2
0
        TupleType CreateTupleType(IToken rootToken, List <VariableDeclarationBag> variables)
        {
            if (TestNull(rootToken, variables))
            {
                TupleType tupleType = new TupleType(TypesTable, new List <Property>());
                TypesTable.RegisterType(tupleType);
                return(tupleType);
            }


            Dictionary <string, Property> tupleParts = new Dictionary <string, Property>();

            foreach (var variable in variables)
            {
                if (tupleParts.Keys.Contains(variable.Name))  // Kontrola nad ramec specifikace
                {
                    Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, variable.Name), rootToken, rootToken));
                    continue;
                }
                Classifier propertyType = variable.Type;
                if (variable.Type == null)
                {
                    propertyType = Library.Invalid;
                }
                tupleParts.Add(variable.Name, new Property(variable.Name, PropertyType.One, propertyType));
            }
            TupleType tuple = new TupleType(TypesTable, tupleParts.Values);

            TypesTable.RegisterType(tuple);

            return(tuple);
        }
Esempio n. 3
0
        public void TranslateSchema(Schema pimSchema, bool translateAsOldVersion = false)
        {
            List <PIMBridgeClass> classToProcess = new List <PIMBridgeClass>();
            //vytvoreni prazdnych trid
            //musi predchazet propertam a associacim, aby se neodkazovalo na neexistujici typy

            // JM: usporadani trid tak, aby predkove byli zalozeni pred potomky
            List <PIMClass> pimClassesHierarchy = ModelIterator.GetPIMClassesInheritanceBFS((PIMSchema)pimSchema).ToList();

            foreach (PIMClass pimClass in pimClassesHierarchy)
            {
                // JM: parent - predek v PIM modelu
                PIMBridgeClass parent       = pimClass.GeneralizationAsSpecific != null ? PIMClasses[pimClass.GeneralizationAsSpecific.General] : null;
                string         nameOverride = translateAsOldVersion ? pimClass.Name + @"_old" : null;
                PIMBridgeClass newClass     = new PIMBridgeClass(TypesTable, TypesTable.Library.RootNamespace, pimClass, parent, nameOverride);

                //  tt.Library.RootNamespace.NestedClassifier.Add(newClass);
                TypesTable.RegisterType(newClass);
                classToProcess.Add(newClass);
                //Hack
                newClass.Tag = pimClass;
                //Registred to find
                PIMClasses.Add(pimClass, newClass);
            }

            //Translates classes members
            classToProcess.ForEach(cl => cl.TranslateMembers());
        }
Esempio n. 4
0
        AST.TupleLiteralExp CreateTupleLiteral(IToken rootToken, List <VariableDeclarationBag> vars)
        {
            if (TestNull(rootToken, vars))
            {
                TupleType tupleTypeErr = new TupleType(TypesTable, new List <Property>());
                TypesTable.RegisterType(tupleTypeErr);
                return(new AST.TupleLiteralExp(new Dictionary <string, AST.TupleLiteralPart>(), tupleTypeErr)
                       .SetCodeSource(new CodeSource(rootToken)));
            }

            Dictionary <string, AST.TupleLiteralPart> parts = new Dictionary <string, AST.TupleLiteralPart>();

            List <Property> tupleParts = new List <Property>();

            foreach (var var in vars)
            {
                if (parts.ContainsKey(var.Name))
                {
                    Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_CreateTupleLiteral_Name_repeated_1, var.Name), rootToken, rootToken));
                    continue;
                }

                AST.OclExpression expr = var.Expression;
                if (var.Expression == null)
                {
                    expr = new AST.ErrorExp(Library.Invalid);
                }

                Classifier type = var.Type;
                if (type == null)
                {
                    type = expr.Type;
                }

                if (expr.Type.ConformsTo(type) == false)
                {
                    Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_CreateTupleLiteral_Type_does_not_comform_to_declared_type));
                }


                //hodnota
                var newProterty = new Property(var.Name, PropertyType.One, type);
                var newPart     = new AST.TupleLiteralPart(newProterty, expr);
                parts.Add(var.Name, newPart);

                //typ
                tupleParts.Add(newProterty);
            }
            TupleType tupleType = new TupleType(TypesTable, tupleParts);

            TypesTable.RegisterType(tupleType);

            return(new AST.TupleLiteralExp(parts, tupleType)
                   .SetCodeSource(new CodeSource(rootToken)));;
        }
Esempio n. 5
0
        public void PrimitiveTypeConformsToTest()
        {
            TypesTable             typesTalbe = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTalbe);

            Classifier integerType      = typesTalbe.Library.Integer;
            Classifier realType         = typesTalbe.Library.Real;
            Classifier unlimnaturalType = typesTalbe.Library.UnlimitedNatural;

            typesTalbe.RegisterType(integerType);
            typesTalbe.RegisterType(realType);
            typesTalbe.RegisterType(unlimnaturalType);

            Assert.IsTrue(integerType.ConformsTo(realType));
            Assert.IsFalse(realType.ConformsTo(integerType));
            Assert.IsTrue(unlimnaturalType.ConformsTo(integerType));
            Assert.IsFalse(integerType.ConformsTo(unlimnaturalType));
            Assert.IsTrue(unlimnaturalType.ConformsTo(realType));
            //Pridat dalsi
        }
Esempio n. 6
0
        public void TupleTest()
        {
            TypesTable             typesTalbe = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTalbe);

            Classifier integerType = typesTalbe.Library.Integer;
            Classifier realType    = typesTalbe.Library.Real;
            Classifier anyType     = typesTalbe.Library.Any;

            typesTalbe.RegisterType(integerType);
            typesTalbe.RegisterType(realType);
            typesTalbe.RegisterType(anyType);

            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("prop1", PropertyType.One, integerType));
            tupleParts1.Add(new Property("prop2", PropertyType.One, integerType));
            TupleType tuple = new TupleType(typesTalbe, tupleParts1);

            typesTalbe.RegisterType(tuple);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("prop1", PropertyType.One, realType));
            tupleParts2.Add(new Property("prop2", PropertyType.One, integerType));
            TupleType tuple2 = new TupleType(typesTalbe, tupleParts2);

            typesTalbe.RegisterType(tuple2);


            Assert.IsTrue(tuple.ConformsTo(tuple2));
            Assert.IsFalse(tuple2.ConformsTo(tuple));

            List <Property> tupleParts3 = new List <Property>();

            tupleParts3.Add(new Property("prop1", PropertyType.One, realType));
            tupleParts3.Add(new Property("prop2", PropertyType.One, integerType));
            tupleParts3.Add(new Property("prop3", PropertyType.One, anyType));
            TupleType tuple3 = new TupleType(typesTalbe, tupleParts3);

            typesTalbe.RegisterType(tuple3);

            Assert.IsFalse(tuple.ConformsTo(tuple3));
            Assert.IsTrue(tuple.ConformsTo(anyType));


            Assert.IsTrue(tuple["prop1"].Type == integerType);
            Assert.AreEqual(tuple.Name, "Tuple(prop1:Integer,prop2:Integer)");
        }
Esempio n. 7
0
        public void ReflexivityConformsToTest()
        {
            TypesTable             typesTable = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTable);

            Classifier integerType = typesTable.Library.Integer;

            Assert.IsTrue(integerType.ConformsTo(integerType));

            Classifier realType = typesTable.Library.Real;

            Assert.IsTrue(realType.ConformsTo(realType));

            CollectionType collType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            CollectionType collType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);

            typesTable.RegisterType(collType);
            typesTable.RegisterType(collType2);

            Assert.IsTrue(collType.ConformsTo(collType));
            Assert.IsTrue(collType.ConformsTo(collType2));

            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("ahoj", PropertyType.One, integerType));
            TupleType tuple = new TupleType(typesTable, tupleParts1);

            typesTable.RegisterType(tuple);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("ahoj", PropertyType.One, integerType));
            TupleType tuple2 = new TupleType(typesTable, tupleParts2);

            typesTable.RegisterType(tuple2);

            Assert.IsTrue(tuple.ConformsTo(tuple));
            Assert.IsTrue(tuple.ConformsTo(tuple2));

            CollectionType bagType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            CollectionType bagType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);

            Assert.IsTrue(bagType.ConformsTo(bagType));
            Assert.IsTrue(bagType.ConformsTo(bagType2));


            CollectionType setType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);
            CollectionType setType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);

            Assert.IsTrue(setType.ConformsTo(setType));
            Assert.IsTrue(setType.ConformsTo(setType2));

            Classifier voidType = typesTable.Library.Void;

            typesTable.RegisterType(voidType);
            Assert.IsTrue(voidType.ConformsTo(voidType));

            Classifier anyType = typesTable.Library.Any;

            typesTable.RegisterType(anyType);
            Assert.IsTrue(anyType.ConformsTo(anyType));

            Classifier invalidType = typesTable.Library.Invalid;

            typesTable.RegisterType(invalidType);
            Assert.IsTrue(invalidType.ConformsTo(invalidType));
            //pridat class
        }
Esempio n. 8
0
        public void CommonSuperTypeTest()
        {
            TypesTable             typesTable = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTable);

            Classifier integerType = typesTable.Library.Integer;
            Classifier realType    = typesTable.Library.Real;
            Classifier anyType     = typesTable.Library.Any;


            Classifier unlimitedType = typesTable.Library.UnlimitedNatural;
            Classifier stringType    = typesTable.Library.String;



            Assert.AreEqual(integerType.CommonSuperType(realType), realType);         //real,integer -> real
            Assert.AreEqual(realType.CommonSuperType(realType), realType);            //real,real -> real
            Assert.AreEqual(realType.CommonSuperType(integerType), realType);         //integer,real -> real
            Assert.AreEqual(unlimitedType.CommonSuperType(realType), realType);       //unlimited,real -> real
            Assert.AreEqual(integerType.CommonSuperType(unlimitedType), integerType); //integer,unlimited -> integer
            Assert.AreEqual(stringType.CommonSuperType(integerType), anyType);        // string,integer -> anytype


            //Collection
            BagType        bagIntegerType  = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            BagType        bagRealType     = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, realType);
            SetType        setType         = (SetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);
            SequenceType   seqType         = (SequenceType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Sequence, integerType);
            OrderedSetType ordType         = (OrderedSetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.OrderedSet, integerType);
            CollectionType collIntegerType = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, integerType);
            CollectionType collRealType    = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, realType);;


            Assert.AreEqual(setType.CommonSuperType(setType), setType);                         //set(integer),set(integer) -> set(integer)
            Assert.AreEqual(setType.CommonSuperType(ordType), collIntegerType);                 //set(integer),ord(integer) -> coll(integer)
            Assert.AreEqual(setType.CommonSuperType(collIntegerType), collIntegerType);         //set(integer),coll(Integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(collIntegerType), collIntegerType); //coll(integer),coll(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagIntegerType), collIntegerType);  //coll(integer),bag(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagRealType), collRealType);        // coll(Integer),bag(real) -> coll(real)
            Assert.AreEqual(setType.CommonSuperType(bagRealType), collRealType);                // set(integer),bag(real) ->col(real)
            Assert.AreEqual(ordType.CommonSuperType(ordType), ordType);                         // ord(integer),ord(integer) -> ord(integer)
            Assert.AreEqual(seqType.CommonSuperType(seqType), seqType);                         // seq(integer),seq(integer) -> seq(integer)

            Assert.AreEqual(setType.CommonSuperType(realType), anyType);                        //set(integer),real -> any

            //void test
            Classifier voidType = typesTable.Library.Void;

            Assert.AreEqual(voidType.CommonSuperType(integerType), integerType);
            Assert.AreEqual(realType.CommonSuperType(voidType), realType);
            Assert.AreEqual(voidType.CommonSuperType(seqType), seqType);
            Assert.AreEqual(collIntegerType.CommonSuperType(voidType), collIntegerType);
            Assert.AreEqual(voidType.CommonSuperType(anyType), anyType);

            //any test
            Assert.AreEqual(integerType.CommonSuperType(anyType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(stringType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(setType), anyType);
            Assert.AreEqual(setType.CommonSuperType(anyType), anyType);

            //tuple test
            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop2", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop3", PropertyType.Many, realType));
            TupleType tuple1 = new TupleType(typesTable, tupleParts1);


            typesTable.RegisterType(tuple1);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop4", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop3", PropertyType.One, anyType));
            TupleType tuple2 = new TupleType(typesTable, tupleParts2);


            typesTable.RegisterType(tuple2);

            TupleType tupleCommon = (TupleType)tuple1.CommonSuperType(tuple2);

            Assert.AreEqual(tupleCommon.TupleParts.Count, 2);
            Assert.AreEqual(tupleCommon["prop1"].PropertyType, tuple1["prop1"].PropertyType);
            Assert.AreEqual(tupleCommon["prop1"].Type, tuple1["prop1"].Type);


            Assert.AreEqual(tupleCommon["prop3"].PropertyType, tuple1["prop3"].PropertyType);
            Assert.AreEqual(tupleCommon["prop3"].Type, tuple2["prop3"].Type);

            Assert.AreEqual(tuple1.CommonSuperType(voidType), tuple1);
            Assert.AreEqual(tuple1.CommonSuperType(anyType), anyType);

            Assert.AreEqual(voidType.CommonSuperType(tuple1), tuple1);
            Assert.AreEqual(anyType.CommonSuperType(tuple1), anyType);

            Assert.AreEqual(tuple2.CommonSuperType(integerType), anyType);
            Assert.AreEqual(realType.CommonSuperType(tuple2), anyType);
        }