Browse Source

Fixed the generated #includes when renaming output files. (#887)

Fixes #868
pull/888/head
Kimon Topouzidis 8 years ago committed by Dimitar Dobrev
parent
commit
01677b0cb1
  1. 34
      build/Tests.lua
  2. 43
      src/Generator/Generators/CLI/CLITypeReferences.cs
  3. 3
      tests/Common/Common.cs
  4. 2
      tests/Common/premake4.lua

34
build/Tests.lua

@ -18,11 +18,11 @@ function SetupExampleProject() @@ -18,11 +18,11 @@ function SetupExampleProject()
SetupParser()
end
function SetupTestProject(name, extraFiles)
function SetupTestProject(name, extraFiles, suffix)
SetupTestGeneratorProject(name)
SetupTestNativeProject(name)
SetupTestProjectsCSharp(name, nil, extraFiles)
SetupTestProjectsCLI(name, extraFiles)
SetupTestProjectsCSharp(name, nil, extraFiles, suffix)
SetupTestProjectsCLI(name, extraFiles, suffix)
end
function SetupTestCSharp(name)
@ -127,7 +127,14 @@ function LinkNUnit() @@ -127,7 +127,14 @@ function LinkNUnit()
}
end
function SetupTestProjectsCSharp(name, depends)
function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
if suffix ~= nil then
nm = name .. suffix
str = "Std" .. suffix
else
nm = name
str = "Std"
end
project(name .. ".CSharp")
SetupManagedTestProject()
@ -136,8 +143,8 @@ function SetupTestProjectsCSharp(name, depends) @@ -136,8 +143,8 @@ function SetupTestProjectsCSharp(name, depends)
files
{
path.join(gendir, name, name .. ".cs"),
path.join(gendir, name, "Std.cs")
path.join(gendir, name, nm .. ".cs"),
path.join(gendir, name, str .. ".cs")
}
vpaths { ["*"] = "*" }
@ -162,7 +169,7 @@ function SetupTestProjectsCSharp(name, depends) @@ -162,7 +169,7 @@ function SetupTestProjectsCSharp(name, depends)
links { "CppSharp.Runtime" }
end
function SetupTestProjectsCLI(name, extraFiles)
function SetupTestProjectsCLI(name, extraFiles, suffix)
if not os.ishost("windows") then
return
end
@ -177,13 +184,22 @@ function SetupTestProjectsCLI(name, extraFiles) @@ -177,13 +184,22 @@ function SetupTestProjectsCLI(name, extraFiles)
dependson { name .. ".Gen", name .. ".Native" }
SetupTestGeneratorBuildEvent(name)
if (suffix ~= nil) then
nm = name .. suffix
else
nm = name
end
files
{
path.join(gendir, name, name .. ".cpp"),
path.join(gendir, name, name .. ".h")
path.join(gendir, name, nm .. ".cpp"),
path.join(gendir, name, nm .. ".h")
}
if extraFiles ~= nil then
for _, file in pairs(extraFiles) do
if suffix ~= nil then
file = file .. suffix
end
files { path.join(gendir, name, file .. ".cpp") }
files { path.join(gendir, name, file .. ".h") }
end

43
src/Generator/Generators/CLI/CLITypeReferences.cs

@ -13,7 +13,7 @@ namespace CppSharp.Generators.CLI @@ -13,7 +13,7 @@ namespace CppSharp.Generators.CLI
public override string ToString()
{
if(Include.InHeader)
if (Include.InHeader)
return Include.ToString();
if (!string.IsNullOrWhiteSpace(FowardReference))
@ -39,12 +39,12 @@ namespace CppSharp.Generators.CLI @@ -39,12 +39,12 @@ namespace CppSharp.Generators.CLI
{
TypeMapDatabase = typeMapDatabase;
DriverOptions = driverOptions;
typeReferences = new Dictionary<Declaration,CLITypeReference>();
typeReferences = new Dictionary<Declaration, CLITypeReference>();
}
public CLITypeReference GetTypeReference(Declaration decl)
{
if(typeReferences.ContainsKey(decl))
if (typeReferences.ContainsKey(decl))
return typeReferences[decl];
var @ref = new CLITypeReference { Declaration = decl };
@ -100,7 +100,7 @@ namespace CppSharp.Generators.CLI @@ -100,7 +100,7 @@ namespace CppSharp.Generators.CLI
private void GenerateInclude(ASTRecord<Declaration> record)
{
var decl = record.Value;
if(decl.Namespace == null)
if (decl.Namespace == null)
return;
// Find a type map for the declaration and use it if it exists.
@ -120,20 +120,20 @@ namespace CppSharp.Generators.CLI @@ -120,20 +120,20 @@ namespace CppSharp.Generators.CLI
if (!decl.IsGenerated)
return;
if(IsBuiltinTypedef(decl))
if (IsBuiltinTypedef(decl))
return;
var typeRef = GetTypeReference(decl);
if (typeRef.Include.TranslationUnit == null)
{
typeRef.Include = new Include
{
File = GetIncludePath(translationUnit),
TranslationUnit = translationUnit,
Kind = translationUnit.IsGenerated
{
File = GetIncludePath(translationUnit),
TranslationUnit = translationUnit,
Kind = translationUnit.IsGenerated
? Include.IncludeKind.Quoted
: Include.IncludeKind.Angled,
};
};
}
typeRef.Include.InHeader |= IsIncludeInHeader(record);
@ -141,8 +141,13 @@ namespace CppSharp.Generators.CLI @@ -141,8 +141,13 @@ namespace CppSharp.Generators.CLI
private string GetIncludePath(TranslationUnit translationUnit)
{
if (!DriverOptions.UseHeaderDirectories)
return translationUnit.FileName;
if (!DriverOptions.UseHeaderDirectories && DriverOptions.GenerateName != null)
{
var extension = Path.GetExtension(TranslationUnit.FileName);
return $"{DriverOptions.GenerateName(translationUnit)}{extension}";
}
return translationUnit.FileName;
var rel = PathHelpers.GetRelativePath(
TranslationUnit.FileRelativeDirectory,
@ -157,12 +162,12 @@ namespace CppSharp.Generators.CLI @@ -157,12 +162,12 @@ namespace CppSharp.Generators.CLI
private bool IsBuiltinTypedef(Declaration decl)
{
var typedefDecl = decl as TypedefDecl;
if(typedefDecl == null) return false;
if(typedefDecl.Type is BuiltinType) return true;
if (typedefDecl == null) return false;
if (typedefDecl.Type is BuiltinType) return true;
var typedefType = typedefDecl.Type as TypedefType;
if(typedefType == null) return false;
if(typedefType.Declaration == null) return false;
if (typedefType == null) return false;
if (typedefType.Declaration == null) return false;
return typedefType.Declaration.Type is BuiltinType;
}
@ -189,9 +194,9 @@ namespace CppSharp.Generators.CLI @@ -189,9 +194,9 @@ namespace CppSharp.Generators.CLI
if (@class.IsIncomplete && @class.CompleteDeclaration != null)
@class = (Class) @class.CompleteDeclaration;
var keywords = @class.IsValueType? "value struct" : "ref class";
var keywords = @class.IsValueType ? "value struct" : "ref class";
var @ref = string.Format("{0} {1};", keywords, @class.Name);
GetTypeReference(@class).FowardReference = @ref;
return false;
@ -203,7 +208,7 @@ namespace CppSharp.Generators.CLI @@ -203,7 +208,7 @@ namespace CppSharp.Generators.CLI
return false;
var @base = "";
if(!@enum.Type.IsPrimitiveType(PrimitiveType.Int))
if (!@enum.Type.IsPrimitiveType(PrimitiveType.Int))
@base = string.Format(" : {0}", @enum.Type);
var @ref = string.Format("enum struct {0}{1};", @enum.Name, @base);

3
tests/Common/Common.cs

@ -54,6 +54,9 @@ namespace CppSharp.Tests @@ -54,6 +54,9 @@ namespace CppSharp.Tests
{
base.Setup(driver);
driver.Options.GenerateName = file =>
file.FileNameWithoutExtension + "_GenerateName";
driver.Options.Modules[1].OutputNamespace = "CommonTest";
driver.Options.UnityBuild = true;
}

2
tests/Common/premake4.lua

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
group "Tests/Common"
SetupTestProject("Common", { "AnotherUnit" })
SetupTestProject("Common", { "AnotherUnit" } , "_GenerateName")
Loading…
Cancel
Save