Exemple #1
0
        public void TransformName()
        {
            var @namespace = new NamespaceDefinition();
            var @enum      = new EnumDefinition("CppEnum");

            @enum.AddChild(new EnumeratorDefinition("COMMON_PREFIX_NONE", "0"));
            @enum.AddChild(new EnumeratorDefinition("COMMON_PREFIX_VALUE1", "1"));
            @enum.AddChild(new EnumeratorDefinition("COMMON_PREFIX_VALUE2", "COMMON_PREFIX_VALUE1*2"));

            @namespace.AddChild(@enum);

            new EnumTransformer().Transform(@namespace, null);

            Assert.AreEqual(3, @enum.Children.Count());
            Assert.AreEqual(3, @enum.Enumerators.Count());

            EnumeratorDefinition enumerator0 = (EnumeratorDefinition)@enum.Children[0];

            Assert.AreEqual("None", enumerator0.Name);
            Assert.AreEqual("0", enumerator0.Value);

            EnumeratorDefinition enumerator1 = (EnumeratorDefinition)@enum.Children[1];

            Assert.AreEqual("Value1", enumerator1.Name);
            Assert.AreEqual("1", enumerator1.Value);

            EnumeratorDefinition enumerator2 = (EnumeratorDefinition)@enum.Children[2];

            Assert.AreEqual("Value2", enumerator2.Name);
            Assert.AreEqual("Value1*2", enumerator2.Value);
        }
Exemple #2
0
        public void IsFlags()
        {
            var @enum = new EnumDefinition("CppEnum");

            @enum.AddChild(new EnumeratorDefinition("None", "0x00"));
            @enum.AddChild(new EnumeratorDefinition("Value1", "0x01"));
            @enum.AddChild(new EnumeratorDefinition("Value2", "0x02"));
            @enum.AddChild(new EnumeratorDefinition("Value3", "4"));
            @enum.AddChild(new EnumeratorDefinition("Value4", "0x40000000"));

            Assert.IsTrue(@enum.IsFlags());
        }
 private static void EnsureNoneValue(EnumDefinition @enum)
 {
     if (@enum.IsFlags() && HasZeroValue(@enum))
     {
         var enumerator = new EnumeratorDefinition("None", "0");
         @enum.AddChild(enumerator);
         @enum.Children.Remove(enumerator);
         @enum.Children.Insert(0, enumerator);
     }
 }
        public void AddNoneValueToEnum()
        {
            var @namespace = new NamespaceDefinition();
            var @enum      = new EnumDefinition("CppEnum");

            @enum.AddChild(new EnumeratorDefinition("VALUE1", "1"));
            @enum.AddChild(new EnumeratorDefinition("VALUE2", "2"));
            @enum.AddChild(new EnumeratorDefinition("VALUE3", "4"));

            @namespace.AddChild(@enum);

            new EnumTransformer().Transform(@namespace, null);

            Assert.AreEqual(4, @enum.Enumerators.Count());

            EnumeratorDefinition enumerator0 = (EnumeratorDefinition)@enum.Children[0];

            Assert.AreEqual("None", enumerator0.Name);
            Assert.AreEqual("0", enumerator0.Value);
        }
Exemple #5
0
        public void Parse(Cursor cursor, CppParserContext context)
        {
            var parent = context.GetContainingClassOrNamespace();
            var @enum  = new EnumDefinition(cursor.Spelling);

            foreach (var constantDecl in cursor.Children
                     .Where(c => c.Kind == CursorKind.EnumConstantDecl))
            {
                string name  = constantDecl.Spelling;
                string value = GetEnumeratorValue(constantDecl, context);
                @enum.AddChild(new EnumeratorDefinition(name, value));
            }

            parent.AddChild(@enum);
            if (parent is NamespaceDefinition)
            {
                context.Header.AddNode(@enum);
            }
        }