コード例 #1
0
        public static Field GenerateConstValueFromMacro(this ASTContext context,
                                                        MacroExpansion macro)
        {
            if (macro.Text != null && macro.Text.Contains("M_PI"))
            {
                Debugger.Break();
            }

            PrimitiveTypeExpression builtinTypeExpression = PrimitiveTypeExpression.TryCreate(macro.Text);

            if (builtinTypeExpression == null)
            {
                return(null);
            }
            var valueType = new QualifiedType(new BuiltinType(builtinTypeExpression.Type))
            {
                Qualifiers = new TypeQualifiers {
                    IsConst = true
                }
            };
            var item = new Field
            {
                Name       = macro.Name,
                DebugText  = macro.DebugText,
                Access     = AccessSpecifier.Public,
                Expression =
                    builtinTypeExpression,
                QualifiedType = valueType
            };

            return(item);
        }
コード例 #2
0
ファイル: ASTConverter.cs プロジェクト: gpetrou/CppSharp
        public override AST.Declaration VisitMacroExpansion(MacroExpansion decl)
        {
            var _macro = new AST.MacroExpansion();

            VisitPreprocessedEntity(decl, _macro);
            _macro.Text = decl.Text;
            return(_macro);
        }
コード例 #3
0
        private bool MatchDeclType(Declaration decl, MacroExpansion macroExpansion)
        {
            if (decl is Class)
            {
                return(macroExpansion.Location == MacroLocation.ClassHead);
            }

            if (decl is Function)
            {
                return(macroExpansion.Location == MacroLocation.FunctionHead);
            }

            if (decl is Parameter)
            {
                return(macroExpansion.Location == MacroLocation.FunctionParameters);
            }

            if (decl is Field)
            {
                return(macroExpansion.Location == MacroLocation.ClassBody);
            }

            return(false);
        }
コード例 #4
0
        public void CheckSpecReferences()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId)
            };
            var specs = new List<OracularSpec>
            {
                new OracularSpec("isBaz", "Foobar", "Foobar.Id != null")
            };
            var config = new OracularConfig (tables, specs);
            var checker = new RefChecker (config);

            var reference = new Reference (new [] { "Foobar" });
            var fn = new Reference (new [] { "isBaz" });
            var call = new MacroExpansion (fn, new [] { reference });

            var initial = new []{ "Foobar" };

            var result = call.Walk (checker, initial);

            Assert.AreEqual (1, result.Length);
            Assert.Contains ("Foobar", result);
        }
コード例 #5
0
        public void ExpectSpecTableToMatchInput()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId),
                new OracularTable("SomethingElse", null, null, justAnId)
            };
            var specs = new List<OracularSpec>
            {
                new OracularSpec("isBaz", "SomethingElse", "SomethingElse.Id = null")
            };
            var config = new OracularConfig (tables, specs);

            var fnRef = new Reference (new string[]{ "isBaz" });
            var foobarRef = new Reference (new string[]{ "Foobar" });
            var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });

            var ex = Assert.Throws<TypeCheckException> (() => isFoobarBaz.Walk (new TypeChecker (config)));

            Assert.That (ex.Message, Is.StringContaining ("mismatch"));
        }
コード例 #6
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 private MacroExpansion(MacroExpansion.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
コード例 #7
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 public static MacroExpansion __CreateInstance(MacroExpansion.Internal native)
 {
     return new MacroExpansion(native);
 }
コード例 #8
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 private MacroExpansion(MacroExpansion.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
コード例 #9
0
 private static void* __CopyValue(MacroExpansion.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(64);
     global::CppSharp.Parser.AST.MacroExpansion.__Internal.cctor_1(ret, new global::System.IntPtr(&native));
     return ret.ToPointer();
 }
コード例 #10
0
        public void ExpectSpecToExist()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId)
            };
            var specs = new List<OracularSpec>();
            var config = new OracularConfig (tables, specs);
            var checker = new RefChecker (config);

            var reference = new Reference (new [] { "Foobar" });
            var fn = new Reference (new [] { "isBaz" });
            var call = new MacroExpansion (fn, new [] { reference });

            var initial = new []{ "Foobar" };

            var ex = Assert.Throws<RefCheckException>(() => call.Walk (checker, initial));

            Assert.That (REFERENCE_RE.IsMatch (ex.Message));
        }
コード例 #11
0
ファイル: AST.cs プロジェクト: vovkasm/CppSharp
 internal MacroExpansion(MacroExpansion.Internal native)
     : this(__CopyValue(native))
 {
 }
コード例 #12
0
        public void SerializeSpecReferences()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var idAndBarId = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("BarId", null)
            };
            var barRelationship = new List<ParentConfig>
            {
                new ParentConfig("Bar", null, null)
            };
            var foo = new OracularTable ("Foo", null, barRelationship, idAndBarId);
            var tables = new List<OracularTable>
            {
                foo,
                new OracularTable("Bar", null, null, justAnId)
            };
            var specs = new List<OracularSpec>
            {
                new OracularSpec("barHasId", "Bar", "Bar.Id != null")
            };
            var config = new OracularConfig (tables, specs);

            var foobarReference = new Reference (new [] { "Foo", "Bar" });
            var specReference = new Reference (new [] { "barHasId" });
            var macroExpansion = new MacroExpansion (specReference, new [] { foobarReference });

            var builder = new Sqlizer (foo, config);
            var sql = macroExpansion.Walk (builder);

            Assert.AreEqual ("([Foo.Bar].[Id] != NULL)", sql);

            Assert.AreEqual (1, builder.JoinTables.Count ());
            var joinClause = builder.JoinTables.First();

            Assert.AreEqual ("INNER JOIN [Bar] [Foo.Bar] ON [Foo.Bar].[Id] = [Foo].[BarId]", joinClause);
        }
コード例 #13
0
        public void SerializeReducer(string macro, string prefix, string suffix, string value, string equality)
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var idAndBarId = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("BarId", null)
            };
            var barRelationship = new List<ParentConfig>
            {
                new ParentConfig("Bar", null, null)
            };
            var foo = new OracularTable ("Foo", null, barRelationship, idAndBarId);
            var bar = new OracularTable("Bar", null, null, justAnId);
            var tables = new List<OracularTable>{ foo, bar };
            var specs = new List<OracularSpec> ();
            var config = new OracularConfig (tables, specs);

            var macroReference = new Reference (new[]{ macro });
            var fooReference = new Reference (new[]{ "Foo" });
            var idNotNull = new BinaryOperation ("!=",
                new Reference (new[]{ "Foo", "Id" }),
                new NullLiteral ()
            );

            var macroExpansion = new MacroExpansion (macroReference, new AstNode[] { fooReference, idNotNull });

            var builder = new Sqlizer (bar, config);
            var sql = macroExpansion.Walk (builder);

            var expected = String.Format ("[AnnotatedBar{0}].[{1}Foo{0}]{2}", idNotNull.Id, prefix, suffix);
            Assert.AreEqual (expected, sql);

            Assert.AreEqual (1, builder.JoinTables.Count ());
            var join = builder.JoinTables.First ();

            expected = String.Format ("LEFT JOIN [AnnotatedBar{0}] ON [AnnotatedBar{0}].[Id] = [Bar].[Id]", idNotNull.Id);
            Assert.AreEqual (expected, join);

            Assert.AreEqual (1, builder.CommonTableExpressions.Count ());
            var annotated = builder.CommonTableExpressions.First ();

            expected = String.Format (@"[AnnotatedBar{0}] AS (
            SELECT DISTINCT [Bar].[Id], {2} [{1}Foo{0}]
            FROM [Bar]
            LEFT JOIN [Foo] ON [Foo].[BarId] = [Bar].[Id]
            WHERE ([Foo].[Id] {3} NULL)
            )", idNotNull.Id, prefix, value, equality);
            Assert.AreEqual (expected, annotated);
        }
コード例 #14
0
        public void SerializeNestedReducers()
        {
            var bazFields = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var barFields = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("BazId", null)
            };
            var barbazRelationship = new List<ParentConfig>
            {
                new ParentConfig("Baz", null, null)
            };
            var fooFields = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("BarId", null),
                new FieldConfig("IsQux", FieldType.Boolean)
            };
            var foobarRelationship = new List<ParentConfig>
            {
                new ParentConfig("Bar", null, null)
            };
            var baz = new OracularTable ("Baz", null, null, bazFields);
            var tables = new List<OracularTable>
            {
                new OracularTable ("Foo", null, foobarRelationship, fooFields),
                new OracularTable("Bar", null, barbazRelationship, barFields),
                baz
            };
            var specs = new List<OracularSpec> ();
            var config = new OracularConfig (tables, specs);

            var fooIsQuxNode = new Reference (new [] { "Foo", "IsQux" });
            var anyFooNode = new MacroExpansion (
                new Reference (new [] { "ANY" }),
                new [] {
                    new Reference(new [] { "Foo" }),
                    fooIsQuxNode
                }
            );

            var anyBarNode = new MacroExpansion (
                new Reference(new [] { "ANY" }),
                new AstNode[] {
                    new Reference(new [] { "Bar" }),
                    anyFooNode
                }
            );

            var builder = new Sqlizer (baz, config);
            var whereClause = anyBarNode.Walk (builder);

            var expected = String.Format ("[AnnotatedBaz{0}].[AnyBar{0}] = 1", anyFooNode.Id);
            Assert.AreEqual (expected, whereClause);

            Assert.AreEqual (1, builder.JoinTables.Count ());
            var join = builder.JoinTables.First ();

            expected = String.Format ("LEFT JOIN [AnnotatedBaz{0}] ON [AnnotatedBaz{0}].[Id] = [Baz].[Id]", anyFooNode.Id);
            Assert.AreEqual (expected, join);

            Assert.AreEqual (2, builder.CommonTableExpressions.Count ());

            var annotatedBar = builder.CommonTableExpressions.First ();
            expected = String.Format (@"[AnnotatedBar{0}] AS (
            SELECT DISTINCT [Bar].[Id], 1 [AnyFoo{0}]
            FROM [Bar]
            LEFT JOIN [Foo] ON [Foo].[BarId] = [Bar].[Id]
            WHERE [Foo].[IsQux] = 1
            )", fooIsQuxNode.Id);
            Assert.AreEqual (expected, annotatedBar);

            var annotatedBaz = builder.CommonTableExpressions.Last ();
            expected = String.Format(@"[AnnotatedBaz{0}] AS (
            SELECT DISTINCT [Baz].[Id], 1 [AnyBar{0}]
            FROM [Baz]
            LEFT JOIN [Bar] ON [Bar].[BazId] = [Baz].[Id]
            LEFT JOIN [AnnotatedBar{1}] ON [AnnotatedBar{1}].[Id] = [Bar].[Id]
            WHERE [AnnotatedBar{1}].[AnyFoo{1}] = 1
            )", anyFooNode.Id, fooIsQuxNode.Id);
            Assert.AreEqual (expected, annotatedBaz);
        }
コード例 #15
0
        public void ExpectSpecToExist()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId)
            };
            var config = new OracularConfig (tables, new List<OracularSpec> ());

            var fnRef = new Reference (new string[]{ "isBaz" });
            var foobarRef = new Reference (new string[]{ "Foobar" });
            var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });

            var ex = Assert.Throws<TypeCheckException> (() => isFoobarBaz.Walk (new TypeChecker (config)));

            Assert.That (ex.Message, Is.StringContaining ("name"));
        }
コード例 #16
0
        public void ExpectJoinTableToExist()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId)
            };
            var specs = new List<OracularSpec>();
            var config = new OracularConfig (tables, specs);
            var checker = new RefChecker (config);

            var fingerlingPotatoes = new BinaryOperation("=",
                new Reference(new [] { "Potato", "Type" }),
                new StringLiteral("Fingerling")
            );

            var call = new MacroExpansion(
                new Reference(new [] { "ANY" }),
                new [] { fingerlingPotatoes }
            );

            var initial = new []{ "Foobar" };

            var ex = Assert.Throws<RefCheckException> (() => call.Walk (checker, initial));

            Assert.That (REFERENCE_RE.IsMatch (ex.Message));
        }
コード例 #17
0
        public void ExpectNestedSpecToRefcheck()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var potatoFields = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("FoobarId", null)
            };
            var foobarRelationship = new ParentConfig ("Foobar", null, null);
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId),
                new OracularTable("Potato", null, new List<ParentConfig>{foobarRelationship}, potatoFields)
            };
            var specs = new List<OracularSpec>();
            var config = new OracularConfig (tables, specs);
            var checker = new RefChecker (config);

            var fingerlingPotatoes = new MacroExpansion(
                new Reference(new [] { "isFingerling" }),
                new [] { new Reference(new [] { "Potato" }) }
            );

            var call = new MacroExpansion(
                new Reference(new [] { "ANY" }),
                new AstNode[] {
                    new Reference(new [] { "Potato" }),
                    fingerlingPotatoes
                }
            );

            var initial = new []{ "Foobar" };

            var ex = Assert.Throws<RefCheckException> (() => call.Walk (checker, initial));

            Assert.That (REFERENCE_RE.IsMatch (ex.Message));
        }
コード例 #18
0
ファイル: AST.cs プロジェクト: KonajuGames/CppSharp
 private MacroExpansion(MacroExpansion.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
コード例 #19
0
        public void CheckJoinTables()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var potatoFields = new List<FieldConfig>
            {
                new FieldConfig("Id", null),
                new FieldConfig("FoobarId", null),
                new FieldConfig("Type", null)
            };
            var foobarRelationship = new ParentConfig ("Foobar", null, null);
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId),
                new OracularTable("Potato", null, new List<ParentConfig>{foobarRelationship}, potatoFields)
            };
            var specs = new List<OracularSpec>();
            var config = new OracularConfig (tables, specs);
            var checker = new RefChecker (config);

            var fingerlingPotatoes = new BinaryOperation("=",
                new Reference(new [] { "Potato", "Type" }),
                new StringLiteral("Fingerling")
            );

            var call = new MacroExpansion(
                new Reference(new [] { "ANY" }),
                new AstNode[] {
                    new Reference(new [] { "Potato" }),
                    fingerlingPotatoes
                }
            );

            var initial = new []{ "Foobar" };

            var result = call.Walk (checker, initial);

            Assert.AreEqual (2, result.Length);
            Assert.Contains ("Foobar", result);
            Assert.Contains ("Potato", result);
        }
コード例 #20
0
ファイル: AST.cs プロジェクト: kidleon/CppSharp
 internal MacroExpansion(MacroExpansion.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
コード例 #21
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 public static MacroExpansion __CreateInstance(MacroExpansion.Internal native, bool skipVTables = false)
 {
     return new MacroExpansion(native, skipVTables);
 }
コード例 #22
0
ファイル: AST.cs プロジェクト: kidleon/CppSharp
 internal MacroExpansion(MacroExpansion.Internal native)
     : this(&native)
 {
 }
コード例 #23
0
ファイル: AST.cs プロジェクト: CSRedRat/CppSharp
 protected MacroExpansion(MacroExpansion.Internal* native, bool skipVTables = false)
     : base((CppSharp.Parser.AST.PreprocessedEntity.Internal*) null)
 {
     __PointerAdjustment = 0;
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
コード例 #24
0
ファイル: ASTConverter.cs プロジェクト: gpetrou/CppSharp
 public abstract TRet VisitMacroExpansion(MacroExpansion decl);
コード例 #25
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 private static MacroExpansion.Internal* __CopyValue(MacroExpansion.Internal native)
 {
     var ret = Marshal.AllocHGlobal(208);
     CppSharp.Parser.AST.MacroExpansion.Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return (MacroExpansion.Internal*) ret;
 }
コード例 #26
0
ファイル: ASTConverter.cs プロジェクト: gpetrou/CppSharp
        public virtual TRet Visit(Parser.AST.Declaration decl)
        {
            switch (decl.Kind)
            {
            case DeclarationKind.TranslationUnit:
            {
                var _decl = new TranslationUnit(decl.__Instance);
                return(VisitTranslationUnit(_decl));
            }

            case DeclarationKind.Namespace:
            {
                var _decl = new Namespace(decl.__Instance);
                return(VisitNamespace(_decl));
            }

            case DeclarationKind.Typedef:
            {
                var _decl = new TypedefDecl(decl.__Instance);
                return(VisitTypedef(_decl));
            }

            case DeclarationKind.Parameter:
            {
                var _decl = new Parameter(decl.__Instance);
                return(VisitParameter(_decl));
            }

            case DeclarationKind.Function:
            {
                var _decl = new Function(decl.__Instance);
                return(VisitFunction(_decl));
            }

            case DeclarationKind.Method:
            {
                var _decl = new Method(decl.__Instance);
                return(VisitMethod(_decl));
            }

            case DeclarationKind.Enumeration:
            {
                var _decl = new Enumeration(decl.__Instance);
                return(VisitEnumeration(_decl));
            }

            case DeclarationKind.EnumerationItem:
            {
                var _decl = new Enumeration.Item(decl.__Instance);
                return(VisitEnumerationItem(_decl));
            }

            case DeclarationKind.Variable:
            {
                var _decl = new Variable(decl.__Instance);
                return(VisitVariable(_decl));
            }

            case DeclarationKind.Field:
            {
                var _decl = new Field(decl.__Instance);
                return(VisitField(_decl));
            }

            case DeclarationKind.AccessSpecifier:
            {
                var _decl = new AccessSpecifierDecl(decl.__Instance);
                return(VisitAccessSpecifier(_decl));
            }

            case DeclarationKind.Class:
            {
                var _decl = new Class(decl.__Instance);
                return(VisitClass(_decl));
            }

            case DeclarationKind.ClassTemplate:
            {
                var _decl = new ClassTemplate(decl.__Instance);
                return(VisitClassTemplate(_decl));
            }

            case DeclarationKind.ClassTemplateSpecialization:
            {
                var _decl = new ClassTemplateSpecialization(decl.__Instance);
                return(VisitClassTemplateSpecialization(_decl));
            }

            case DeclarationKind.ClassTemplatePartialSpecialization:
            {
                var _decl = new ClassTemplatePartialSpecialization(decl.__Instance);
                return(VisitClassTemplatePartialSpecialization(_decl));
            }

            case DeclarationKind.FunctionTemplate:
            {
                var _decl = new FunctionTemplate(decl.__Instance);
                return(VisitFunctionTemplate(_decl));
            }

            case DeclarationKind.MacroDefinition:
            {
                var _decl = new MacroDefinition(decl.__Instance);
                return(VisitMacroDefinition(_decl));
            }

            case DeclarationKind.MacroExpansion:
            {
                var _decl = new MacroExpansion(decl.__Instance);
                return(VisitMacroExpansion(_decl));
            }
            }

            throw new ArgumentOutOfRangeException();
        }
コード例 #27
0
ファイル: AST.cs プロジェクト: RainsSoft/CppSharp
 protected MacroExpansion(MacroExpansion.Internal* native, bool isInternalImpl = false)
     : base((CppSharp.Parser.AST.PreprocessedEntity.Internal*) native)
 {
 }
コード例 #28
0
        public void CheckSpecAgainstTable()
        {
            var justAnId = new List<FieldConfig>
            {
                new FieldConfig("Id", null)
            };
            var tables = new List<OracularTable>
            {
                new OracularTable("Foobar", null, null, justAnId)
            };
            var specs = new List<OracularSpec>
            {
                new OracularSpec("isBaz", "Foobar", "Foobar.Id = null")
            };
            var config = new OracularConfig (tables, specs);

            var fnRef = new Reference (new string[]{ "isBaz" });
            var foobarRef = new Reference (new string[]{ "Foobar" });
            var isFoobarBaz = new MacroExpansion (fnRef, new AstNode[]{ foobarRef });

            var type = isFoobarBaz.Walk (new TypeChecker (config));

            Assert.AreEqual (SpecType.Boolean, type.Type);
        }