Example #1
0
        public static CSharpAbstractSyntaxTree GetAbstractSyntaxTree(
            ClangAbstractSyntaxTree clangAbstractSyntaxTree)
        {
            var functionExterns = MapFunctionExterns(
                clangAbstractSyntaxTree.FunctionExterns);
            var functionPointers = MapFunctionPointers(
                clangAbstractSyntaxTree.FunctionPointers);
            var structs = MapStructs(
                clangAbstractSyntaxTree.Records,
                clangAbstractSyntaxTree.AliasDataTypes,
                clangAbstractSyntaxTree.OpaquePointers);
            var opaqueDataTypes = MapOpaqueDataTypes(
                clangAbstractSyntaxTree.OpaqueDataTypes);
            var enums = MapEnums(
                clangAbstractSyntaxTree.Enums);

            var result = new CSharpAbstractSyntaxTree(
                functionExterns,
                functionPointers,
                structs,
                opaqueDataTypes,
                enums);

            return(result);
        }
Example #2
0
        public static string GenerateFile(string libraryName, CSharpAbstractSyntaxTree abstractSyntaxTree)
        {
            var members = new List <MemberDeclarationSyntax>();

            foreach (var functionExtern in abstractSyntaxTree.FunctionExterns)
            {
                var member = CreateExternMethod(functionExtern);
                members.Add(member);
            }

            foreach (var functionPointer in abstractSyntaxTree.FunctionPointers)
            {
                var member = CSharpCodeGenerator.CreateFunctionPointer(functionPointer);
                members.Add(member);
            }

            foreach (var @struct in abstractSyntaxTree.Structs)
            {
                var member = CreateStruct(@struct);
                members.Add(member);
            }

            foreach (var opaqueDataType in abstractSyntaxTree.OpaqueDataTypes)
            {
                var member = CreateOpaqueStruct(opaqueDataType);
                members.Add(member);
            }

            foreach (var @enum in abstractSyntaxTree.Enums)
            {
                var member = CreateEnum(@enum);
                members.Add(member);
            }

            var @class = CreatePInvokeClass(libraryName, members.ToImmutableArray());

            return(@class.ToFullString());
        }