Browse Source

Merge remote-tracking branch 'refs/remotes/mono/master'

pull/728/head
zillemarco 9 years ago
parent
commit
8602ad95cc
  1. 91
      examples/Clang/Clang.cs
  2. 36
      examples/Clang/Properties/AssemblyInfo.cs
  3. 5
      examples/SDL/SDL.cs
  4. 12
      src/AST/CppTypePrinter.cs
  5. 2
      src/Generator/BindingContext.cs
  6. 11
      src/Generator/Driver.cs
  7. 36
      src/Generator/Generators/CSharp/CSharpSources.cs
  8. 27
      src/Generator/Passes/CheckIgnoredDecls.cs
  9. 3
      src/Generator/Passes/FieldToPropertyPass.cs
  10. 52
      src/Generator/Utils/FileHashes.cs
  11. 34
      src/Generator/Utils/Glob.cs

91
examples/Clang/Clang.cs

@ -1,91 +0,0 @@ @@ -1,91 +0,0 @@
using Cxxi.Generators;
using Cxxi.Passes;
using Cxxi.Templates;
using Generator = Cxxi.Generators.Generator;
namespace Cxxi
{
/// <summary>
/// Transform the Clang library declarations to something more .NET friendly.
/// </summary>
class Clang : ILibrary
{
public void Preprocess(LibraryHelpers g)
{
//g.SetNameOfEnumWithMatchingItem("SDL_LOG_CATEGORY_CUSTOM", "LogCategory");
// Clean up types
g.FindClass("CXString").IsOpaque = true;
g.FindClass("CXSourceLocation").IsOpaque = true;
g.FindClass("CXSourceRange").IsOpaque = true;
g.FindClass("CXCursor").IsOpaque = true;
g.FindClass("CXType").IsOpaque = true;
g.FindClass("CXToken").IsOpaque = true;
g.FindClass("CXIdxLoc").IsOpaque = true;
g.FindClass("CXTranslationUnitImpl").IsOpaque = true;
}
public void Postprocess(LibraryHelpers g)
{
g.FindEnum("CompletionContext").SetFlags();
g.FindClass("String").Name = "CXString";
//gen.SetNameOfEnumWithName("LOG_CATEGORY", "LogCategory");
}
public void Postprocess(Generators.Generator generator)
{
}
public void SetupPasses(PassBuilder p)
{
p.RemovePrefix("CX");
p.RemovePrefix("clang_");
p.RenameWithPattern("^_", string.Empty, RenameTargets.Any);
// Clean up enums
p.RemovePrefixEnumItem("ChildVisit_");
p.RemovePrefixEnumItem("Comment_");
p.RemovePrefixEnumItem("Availability_");
p.RemovePrefixEnumItem("GlobalOpt_");
p.RemovePrefixEnumItem("Diagnostic_");
p.RemovePrefixEnumItem("LoadDiag_");
p.RemovePrefixEnumItem("TranslationUnit_");
p.RemovePrefixEnumItem("SaveTranslationUnit_");
p.RemovePrefixEnumItem("SaveError_");
p.RemovePrefixEnumItem("TranslationUnit_");
p.RemovePrefixEnumItem("Reparse_");
p.RemovePrefixEnumItem("TUResourceUsage_");
p.RemovePrefixEnumItem("Cursor_");
p.RemovePrefixEnumItem("Linkage_");
p.RemovePrefixEnumItem("Language_");
p.RemovePrefixEnumItem("Type_");
p.RemovePrefixEnumItem("CallingConv_");
p.RemovePrefixEnumItem("CommentInlineCommandRenderKind_");
p.RemovePrefixEnumItem("CommentParamPassDirection_");
p.RemovePrefixEnumItem("NameRange_");
p.RemovePrefixEnumItem("Token_");
p.RemovePrefixEnumItem("CompletionChunk_");
p.RemovePrefixEnumItem("CodeComplete_");
p.RemovePrefixEnumItem("CompletionContext_");
p.RemovePrefixEnumItem("Visit_");
p.RemovePrefixEnumItem("IdxEntity_");
p.RemovePrefixEnumItem("IdxEntityLang_");
p.RemovePrefixEnumItem("IdxAttr_");
p.RemovePrefixEnumItem("IdxObjCContainer_");
p.RemovePrefixEnumItem("IdxEntityRef_");
p.RemovePrefixEnumItem("IndexOpt_");
p.RemovePrefixEnumItem("IdxObjCContainer_");
}
public void GenerateStart(TextTemplate template)
{
throw new System.NotImplementedException();
}
public void GenerateAfterNamespaces(TextTemplate template)
{
throw new System.NotImplementedException();
}
}
}

36
examples/Clang/Properties/AssemblyInfo.cs

@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Clang")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Clang")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e7c52cd3-e09e-43ba-91e4-82bc31315f7c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

5
examples/SDL/SDL.cs

@ -9,13 +9,14 @@ namespace CppSharp @@ -9,13 +9,14 @@ namespace CppSharp
{
public void Setup(Driver driver)
{
var parserOptions = driver.ParserOptions;
var options = driver.Options;
options.LibraryName = "SDL";
options.Headers.Add("SDL.h");
options.OutputDir = "SDL";
var parserOptions = driver.ParserOptions;
var sdlPath = Path.Combine(GetExamplesDirectory("SDL"), "SDL-2.0/include");
parserOptions.AddIncludeDirs(sdlPath);
options.OutputDir = "SDL";
}
public void SetupPasses(Driver driver)

12
src/AST/CppTypePrinter.cs

@ -151,7 +151,7 @@ namespace CppSharp.AST @@ -151,7 +151,7 @@ namespace CppSharp.AST
FunctionType func;
return decl.Type.IsPointerTo(out func) ? VisitDeclaration(decl) : decl.Type.Visit(this);
}
return GetDeclName(typedef.Declaration);
return GetDeclName(typedef.Declaration, PrintScopeKind);
}
public virtual string VisitAttributedType(AttributedType attributed, TypeQualifiers quals)
@ -290,9 +290,9 @@ namespace CppSharp.AST @@ -290,9 +290,9 @@ namespace CppSharp.AST
throw new System.NotImplementedException();
}
public virtual string GetDeclName(Declaration declaration)
public virtual string GetDeclName(Declaration declaration, CppTypePrintScopeKind scope)
{
switch (PrintScopeKind)
switch (scope)
{
case CppTypePrintScopeKind.Local:
return PrintLogicalNames ? declaration.LogicalOriginalName
@ -301,8 +301,8 @@ namespace CppSharp.AST @@ -301,8 +301,8 @@ namespace CppSharp.AST
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName;
case CppTypePrintScopeKind.GlobalQualified:
return "::" + (PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName);
var qualifier = PrintFlavorKind == CppTypePrintFlavorKind.Cpp ? "::" : string.Empty;
return qualifier + GetDeclName(declaration, CppTypePrintScopeKind.Qualified);
}
throw new NotSupportedException();
@ -310,7 +310,7 @@ namespace CppSharp.AST @@ -310,7 +310,7 @@ namespace CppSharp.AST
public virtual string VisitDeclaration(Declaration decl)
{
return GetDeclName(decl);
return GetDeclName(decl, PrintScopeKind);
}
public virtual string VisitClassDecl(Class @class)

2
src/Generator/BindingContext.cs

@ -24,8 +24,6 @@ namespace CppSharp.Generators @@ -24,8 +24,6 @@ namespace CppSharp.Generators
public Dictionary<Function, DelegatesPass.DelegateDefinition> Delegates { get; private set; }
private static readonly Dictionary<string, string> libraryMappings = new Dictionary<string, string>();
public BindingContext(IDiagnostics diagnostics, DriverOptions options,
ParserOptions parserOptions = null)
{

11
src/Generator/Driver.cs

@ -383,13 +383,14 @@ namespace CppSharp @@ -383,13 +383,14 @@ namespace CppSharp
public void CompileCode(AST.Module module)
{
var assemblyFile = string.IsNullOrEmpty(module.LibraryName) ?
"out.dll" : module.LibraryName + ".dll";
var assemblyFile = Path.Combine(Options.OutputDir,
string.IsNullOrEmpty(module.LibraryName) ?
"out.dll" : module.LibraryName + ".dll");
var docFile = Path.ChangeExtension(Path.GetFileName(assemblyFile), ".xml");
var docFile = Path.ChangeExtension(assemblyFile, ".xml");
var compilerOptions = new StringBuilder();
compilerOptions.Append(" /doc:" + docFile);
compilerOptions.Append($" /doc:\"{docFile}\"");
compilerOptions.Append(" /debug:pdbonly");
compilerOptions.Append(" /unsafe");
@ -404,7 +405,7 @@ namespace CppSharp @@ -404,7 +405,7 @@ namespace CppSharp
if (module != Options.SystemModule)
compilerParameters.ReferencedAssemblies.Add(
string.Format("{0}.dll", Options.SystemModule.LibraryName));
Path.Combine(Options.OutputDir, $"{Options.SystemModule.LibraryName}.dll"));
// add a reference to System.Core
compilerParameters.ReferencedAssemblies.Add(typeof(Enumerable).Assembly.Location);

36
src/Generator/Generators/CSharp/CSharpSources.cs

@ -802,26 +802,6 @@ namespace CppSharp.Generators.CSharp @@ -802,26 +802,6 @@ namespace CppSharp.Generators.CSharp
}
PopBlock(NewLineKind.BeforeNextBlock);
// Workaround a bug in Mono when handling fixed arrays in P/Invoke declarations.
// https://bugzilla.xamarin.com/show_bug.cgi?id=33571
if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant &&
arrayType.Size > 0)
{
for (var i = 1; i < arrayType.Size; ++i)
{
var dummy = new LayoutField
{
Offset = (uint) (field.Offset + i * arrayType.ElementSize / 8),
QualifiedType = new QualifiedType(arrayType.Type),
Name = string.Format("{0}_{1}_{2}", Helpers.DummyIdentifier,
safeIdentifier, i),
FieldPtr = field.FieldPtr
};
GenerateClassInternalsField(dummy);
}
}
}
private void GenerateClassField(Field field, bool @public = false)
@ -1499,19 +1479,20 @@ namespace CppSharp.Generators.CSharp @@ -1499,19 +1479,20 @@ namespace CppSharp.Generators.CSharp
AllocateNewVTablesItanium(@class, wrappedEntries, destructorOnly);
}
private void SaveOriginalVTablePointers(Class @class)
private void SaveOriginalVTablePointers(Class @class, bool cast = false)
{
var suffix = Helpers.GetSuffixForInternal(@class);
var pointer = cast ? $@"(({Helpers.InternalStruct}{
Helpers.GetSuffixForInternal(@class)}*) native)" : "native";
if (Context.ParserOptions.IsMicrosoftAbi)
WriteLine("__OriginalVTables = new void*[] {{ {0} }};",
string.Join(", ",
@class.Layout.VTablePointers.Select(v => string.Format(
"(({0}{1}*) native)->{2}.ToPointer()",
Helpers.InternalStruct, suffix, v.Name))));
@class.Layout.VTablePointers.Select(v =>
$"{pointer}->{v.Name}.ToPointer()")));
else
WriteLine(
"__OriginalVTables = new void*[] {{ (({0}{1}*) native)->{2}.ToPointer() }};",
Helpers.InternalStruct, suffix, @class.Layout.VTablePointers[0].Name);
$@"__OriginalVTables = new void*[] {{ {pointer}->{
@class.Layout.VTablePointers[0].Name}.ToPointer() }};");
}
private void AllocateNewVTablesMS(Class @class, IList<VTableComponent> wrappedEntries,
@ -2071,7 +2052,7 @@ namespace CppSharp.Generators.CSharp @@ -2071,7 +2052,7 @@ namespace CppSharp.Generators.CSharp
}
if (@class.IsAbstractImpl || hasVTables)
SaveOriginalVTablePointers(@class);
SaveOriginalVTablePointers(@class, true);
if (setupVTables)
{
@ -2675,7 +2656,6 @@ namespace CppSharp.Generators.CSharp @@ -2675,7 +2656,6 @@ namespace CppSharp.Generators.CSharp
if (construct == null)
{
var @class = retClass.OriginalClass ?? retClass;
var specialization = @class as ClassTemplateSpecialization;
WriteLine("var {0} = new {1}.{2}{3}();", Helpers.ReturnIdentifier,
@class.Visit(TypePrinter), Helpers.InternalStruct,
Helpers.GetSuffixForInternal(@class));

27
src/Generator/Passes/CheckIgnoredDecls.cs

@ -403,17 +403,22 @@ namespace CppSharp.Passes @@ -403,17 +403,22 @@ namespace CppSharp.Passes
private bool IsTypeExternal(Module module, Type type)
{
Declaration declaration;
if ((type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration))
{
declaration = declaration.CompleteDeclaration ?? declaration;
if (declaration.TranslationUnit.Module.Libraries.Any(l =>
Context.Symbols.Libraries.First(
lib => lib.FileName == l).Dependencies.Any(
module.Libraries.Contains)))
{
return true;
}
}
if (!(type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration))
return false;
declaration = declaration.CompleteDeclaration ?? declaration;
if (declaration.Namespace == null || declaration.TranslationUnit.Module == null)
return false;
// Check if there’s another module which wraps libraries with dependencies on
// the ones in the current module.
if (declaration.TranslationUnit.Module.Libraries.Any(l =>
Context.Symbols.Libraries.First(
lib => lib.FileName == l).Dependencies.Any(
d => module != declaration.TranslationUnit.Module &&
module.Libraries.Contains(d))))
return true;
return false;
}

3
src/Generator/Passes/FieldToPropertyPass.cs

@ -51,8 +51,7 @@ namespace CppSharp.Passes @@ -51,8 +51,7 @@ namespace CppSharp.Passes
@class.Properties.Add(prop);
Diagnostics.Debug("Property created from field: {0}::{1}", @class.Name,
field.Name);
Diagnostics.Debug($"Property created from field: {field.QualifiedName}");
return false;
}

52
src/Generator/Utils/FileHashes.cs

@ -1,52 +0,0 @@ @@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable]
class FileHashes
{
private string serializedFile;
private Dictionary<string, int> fileHashes = new Dictionary<string, int>();
public bool UpdateHash(string file, int hash)
{
if(!fileHashes.ContainsKey(file))
{
fileHashes.Add(file, hash);
Save(this, serializedFile);
return true;
}
var oldHash = fileHashes[file];
fileHashes[file] = hash;
Save(this, serializedFile);
return oldHash != hash;
}
public static FileHashes Load(string file)
{
var stream = File.Open(file, FileMode.OpenOrCreate);
var bformatter = new BinaryFormatter();
FileHashes obj;
if(stream.Length>0)
obj = (FileHashes)bformatter.Deserialize(stream);
else
obj = new FileHashes();
obj.serializedFile = file;
stream.Close();
return obj;
}
public static void Save(FileHashes obj, string file)
{
Stream stream = File.Open(file, FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, obj);
stream.Close();
}
}

34
src/Generator/Utils/Glob.cs

@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
public static class Glob
{
static public string[] GetFiles(string[] patterns)
{
List<string> filelist = new List<string>();
foreach (string pattern in patterns)
filelist.AddRange(GetFiles(pattern));
string[] files = new string[filelist.Count];
filelist.CopyTo(files, 0);
return files;
}
static public string[] GetFiles(string patternlist)
{
List<string> filelist = new List<string>();
foreach (string pattern in
patternlist.Split(Path.GetInvalidPathChars()))
{
string dir = Path.GetDirectoryName(pattern);
if (String.IsNullOrEmpty(dir)) dir =
Directory.GetCurrentDirectory();
filelist.AddRange(Directory.GetFiles(
Path.GetFullPath(dir),
Path.GetFileName(pattern)));
}
string[] files = new string[filelist.Count];
filelist.CopyTo(files, 0);
return files;
}
}
Loading…
Cancel
Save