Update libClangSharp to 10.0.2-beta and improve some codegen handling (#162)

* Exposing additional information about types

* Don't pack as tool for local builds

* Handle Enum as the backing bitfield type

* Handle CXXUuidofExpr

* Handle arrays with a size of 0

* Adding support for alignof UnaryExprOrTypeTraitExpr

* Adding support for GotoStmt and LabelStmt

* Ensure the number of template arguments is correctly returned

* Escape string literals

* Cleaning up how semicolons are emitted and statement bodies are visited

* Upgrading libClangSharp to 10.0.2-beta2

* Adding Microsoft.SourceLink.GitHub

* Fixing the handling of while statement bodies
This commit is contained in:
Tanner Gooding 2020-07-23 11:19:06 -07:00 коммит произвёл GitHub
Родитель 7a873c847c
Коммит 28dd07399a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
78 изменённых файлов: 2720 добавлений и 481 удалений

Просмотреть файл

@ -65,4 +65,12 @@
<UseSharedCompilation>true</UseSharedCompilation> <UseSharedCompilation>true</UseSharedCompilation>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" IsImplicitlyDefined="true" PrivateAssets="all" />
</ItemGroup>
</Project> </Project>

Просмотреть файл

@ -28,9 +28,10 @@
<!-- Package versions for package references across all projects --> <!-- Package versions for package references across all projects -->
<ItemGroup> <ItemGroup>
<PackageReference Update="libClang" Version="10.0.0" /> <PackageReference Update="libClang" Version="10.0.0" />
<PackageReference Update="libClangSharp" Version="10.0.1-beta2" /> <PackageReference Update="libClangSharp" Version="10.0.2-beta2" />
<PackageReference Update="Microsoft.Bcl.HashCode" Version="1.1.0" /> <PackageReference Update="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.6.1" /> <PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0" />
<PackageReference Update="System.CommandLine" Version="2.0.0-beta1.20253.1" /> <PackageReference Update="System.CommandLine" Version="2.0.0-beta1.20253.1" />
<PackageReference Update="System.Memory" Version="4.5.4" /> <PackageReference Update="System.Memory" Version="4.5.4" />
<PackageReference Update="xunit" Version="2.4.1" /> <PackageReference Update="xunit" Version="2.4.1" />

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.freebsd.11-x64</id> <id>libClangSharp.runtime.freebsd.11-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.freebsd.11-x86</id> <id>libClangSharp.runtime.freebsd.11-x86</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.linux-arm</id> <id>libClangSharp.runtime.linux-arm</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.linux-arm64</id> <id>libClangSharp.runtime.linux-arm64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.osx-x64</id> <id>libClangSharp.runtime.osx-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.sles-x64</id> <id>libClangSharp.runtime.sles-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.16.04-x64</id> <id>libClangSharp.runtime.ubuntu.16.04-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.18.04-x64</id> <id>libClangSharp.runtime.ubuntu.18.04-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.20.04-x64</id> <id>libClangSharp.runtime.ubuntu.20.04-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.win-x64</id> <id>libClangSharp.runtime.win-x64</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp.runtime.win-x86</id> <id>libClangSharp.runtime.win-x86</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12"> <metadata minClientVersion="2.12">
<id>libClangSharp</id> <id>libClangSharp</id>
<version>10.0.1-beta2</version> <version>10.0.2-beta2</version>
<authors>Microsoft and Contributors</authors> <authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners> <owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance> <requireLicenseAcceptance>true</requireLicenseAcceptance>

Просмотреть файл

@ -2,57 +2,57 @@
"runtimes": { "runtimes": {
"freebsd.11-x64": { "freebsd.11-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.freebsd.11-x64": "10.0.1-beta2" "libClangSharp.runtime.freebsd.11-x64": "10.0.2-beta2"
} }
}, },
"freebsd.11-x86": { "freebsd.11-x86": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.freebsd.11-x86": "10.0.1-beta2" "libClangSharp.runtime.freebsd.11-x86": "10.0.2-beta2"
} }
}, },
"linux-arm": { "linux-arm": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.linux-arm": "10.0.1-beta2" "libClangSharp.runtime.linux-arm": "10.0.2-beta2"
} }
}, },
"linux-arm64": { "linux-arm64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.linux-arm64": "10.0.1-beta2" "libClangSharp.runtime.linux-arm64": "10.0.2-beta2"
} }
}, },
"osx-x64": { "osx-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.osx-x64": "10.0.1-beta2" "libClangSharp.runtime.osx-x64": "10.0.2-beta2"
} }
}, },
"sles-x64": { "sles-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.sles-x64": "10.0.1-beta2" "libClangSharp.runtime.sles-x64": "10.0.2-beta2"
} }
}, },
"ubuntu.16.04-x64": { "ubuntu.16.04-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.ubuntu.16.04-x64": "10.0.1-beta2" "libClangSharp.runtime.ubuntu.16.04-x64": "10.0.2-beta2"
} }
}, },
"ubuntu.18.04-x64": { "ubuntu.18.04-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.ubuntu.18.04-x64": "10.0.1-beta2" "libClangSharp.runtime.ubuntu.18.04-x64": "10.0.2-beta2"
} }
}, },
"ubuntu.20.04-x64": { "ubuntu.20.04-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.ubuntu.20.04-x64": "10.0.1-beta2" "libClangSharp.runtime.ubuntu.20.04-x64": "10.0.2-beta2"
} }
}, },
"win-x64": { "win-x64": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.win-x64": "10.0.1-beta2" "libClangSharp.runtime.win-x64": "10.0.2-beta2"
} }
}, },
"win-x86": { "win-x86": {
"libClangSharp": { "libClangSharp": {
"libClangSharp.runtime.win-x86": "10.0.1-beta2" "libClangSharp.runtime.win-x86": "10.0.2-beta2"
} }
} }
} }

Просмотреть файл

@ -119,34 +119,40 @@ namespace ClangSharp
WriteLine(value); WriteLine(value);
} }
public void WriteLine()
{
_contents.Add(_currentLine.ToString());
_currentLine.Clear();
}
public void WriteLine<T>(T value) public void WriteLine<T>(T value)
{ {
Write(value); Write(value);
WriteLine(); WriteNewline();
}
public void WriteNewline()
{
_contents.Add(_currentLine.ToString());
_currentLine.Clear();
NeedsNewline = false;
} }
public void WriteNewlineIfNeeded() public void WriteNewlineIfNeeded()
{ {
if (NeedsNewline) if (NeedsNewline)
{ {
WriteLine(); WriteNewline();
} }
NeedsNewline = false; }
public void WriteSemicolon()
{
Write(';');
NeedsSemicolon = false;
NeedsNewline = true;
} }
public void WriteSemicolonIfNeeded() public void WriteSemicolonIfNeeded()
{ {
if (NeedsSemicolon) if (NeedsSemicolon)
{ {
WriteLine(';'); WriteSemicolon();
} }
NeedsSemicolon = true;
} }
} }
} }

Просмотреть файл

@ -351,7 +351,7 @@ namespace ClangSharp
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
_outputBuilder.Write(escapedName); _outputBuilder.Write(escapedName);
_outputBuilder.Write('['); _outputBuilder.Write('[');
_outputBuilder.Write(constantArrayType.Size); _outputBuilder.Write(Math.Max(constantArrayType.Size, 1));
var elementType = constantArrayType.ElementType; var elementType = constantArrayType.ElementType;
@ -381,7 +381,8 @@ namespace ClangSharp
_outputBuilder.Write(escapedName); _outputBuilder.Write(escapedName);
} }
_outputBuilder.WriteLine(';'); _outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
} }
private void VisitFunctionDecl(FunctionDecl functionDecl) private void VisitFunctionDecl(FunctionDecl functionDecl)
@ -605,7 +606,8 @@ namespace ClangSharp
if ((body is null) || isVirtual) if ((body is null) || isVirtual)
{ {
_outputBuilder.WriteLine(';'); _outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
} }
else else
{ {
@ -614,35 +616,26 @@ namespace ClangSharp
int firstCtorInitializer = functionDecl.Parameters.Any() ? (functionDecl.CursorChildren.IndexOf(functionDecl.Parameters.Last()) + 1) : 0; int firstCtorInitializer = functionDecl.Parameters.Any() ? (functionDecl.CursorChildren.IndexOf(functionDecl.Parameters.Last()) + 1) : 0;
int lastCtorInitializer = (functionDecl.Body != null) ? functionDecl.CursorChildren.IndexOf(functionDecl.Body) : functionDecl.CursorChildren.Count; int lastCtorInitializer = (functionDecl.Body != null) ? functionDecl.CursorChildren.IndexOf(functionDecl.Body) : functionDecl.CursorChildren.Count;
_outputBuilder.WriteBlockStart();
if (functionDecl is CXXConstructorDecl cxxConstructorDecl)
{
VisitCtorInitializers(this, cxxConstructorDecl, firstCtorInitializer, lastCtorInitializer);
}
if (body is CompoundStmt compoundStmt) if (body is CompoundStmt compoundStmt)
{ {
_outputBuilder.WriteBlockStart();
_outputBuilder.NeedsSemicolon = true;
if (functionDecl is CXXConstructorDecl cxxConstructorDecl)
{
VisitCtorInitializers(this, cxxConstructorDecl, firstCtorInitializer, lastCtorInitializer);
}
VisitStmts(compoundStmt.Body); VisitStmts(compoundStmt.Body);
_outputBuilder.WriteBlockEnd();
} }
else else
{ {
_outputBuilder.WriteBlockStart();
_outputBuilder.WriteIndentation(); _outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
if (functionDecl is CXXConstructorDecl cxxConstructorDecl)
{
VisitCtorInitializers(this, cxxConstructorDecl, firstCtorInitializer, lastCtorInitializer);
}
Visit(body); Visit(body);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteBlockEnd();
} }
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteNewlineIfNeeded();
_outputBuilder.WriteBlockEnd();
} }
_outputBuilder.NeedsNewline = true; _outputBuilder.NeedsNewline = true;
@ -657,47 +650,43 @@ namespace ClangSharp
{ {
var outputBuilder = pinvokeGenerator._outputBuilder; var outputBuilder = pinvokeGenerator._outputBuilder;
if (firstCtorInitializer < lastCtorInitializer) for (int i = firstCtorInitializer; i < lastCtorInitializer; i++)
{ {
for (int i = firstCtorInitializer; i < lastCtorInitializer; i++) if (cxxConstructorDecl.CursorChildren[i] is Attr)
{ {
if (cxxConstructorDecl.CursorChildren[i] is Attr) continue;
{
continue;
}
var memberRef = (Ref)cxxConstructorDecl.CursorChildren[i];
var memberInit = (Stmt)cxxConstructorDecl.CursorChildren[++i];
if (memberInit is ImplicitValueInitExpr)
{
continue;
}
var memberRefName = pinvokeGenerator.GetRemappedCursorName(memberRef.Referenced);
var memberInitName = memberInit.Spelling;
if ((memberInit is ImplicitCastExpr implicitCastExpr) && (implicitCastExpr.SubExpr is DeclRefExpr declRefExpr))
{
memberInitName = pinvokeGenerator.GetRemappedCursorName(declRefExpr.Decl);
}
outputBuilder.WriteIndentation();
if (memberRefName.Equals(memberInitName))
{
outputBuilder.Write("this");
outputBuilder.Write('.');
}
pinvokeGenerator.Visit(memberRef);
outputBuilder.Write(' ');
outputBuilder.Write('=');
outputBuilder.Write(' ');
pinvokeGenerator.Visit(memberInit);
outputBuilder.WriteSemicolonIfNeeded();
} }
outputBuilder.NeedsSemicolon = false; var memberRef = (Ref)cxxConstructorDecl.CursorChildren[i];
var memberInit = (Stmt)cxxConstructorDecl.CursorChildren[++i];
if (memberInit is ImplicitValueInitExpr)
{
continue;
}
var memberRefName = pinvokeGenerator.GetRemappedCursorName(memberRef.Referenced);
var memberInitName = memberInit.Spelling;
if ((memberInit is ImplicitCastExpr implicitCastExpr) && (implicitCastExpr.SubExpr is DeclRefExpr declRefExpr))
{
memberInitName = pinvokeGenerator.GetRemappedCursorName(declRefExpr.Decl);
}
outputBuilder.WriteIndentation();
if (memberRefName.Equals(memberInitName))
{
outputBuilder.Write("this");
outputBuilder.Write('.');
}
pinvokeGenerator.Visit(memberRef);
outputBuilder.Write(' ');
outputBuilder.Write('=');
outputBuilder.Write(' ');
pinvokeGenerator.Visit(memberInit);
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
} }
} }
} }
@ -918,11 +907,26 @@ namespace ClangSharp
{ {
if (_config.GenerateExplicitVtbls) if (_config.GenerateExplicitVtbls)
{ {
_outputBuilder.WriteIndentedLine("public Vtbl* lpVtbl;"); _outputBuilder.WriteIndented("public");
_outputBuilder.Write(' ');
_outputBuilder.Write("Vtbl");
_outputBuilder.Write('*');
_outputBuilder.Write(' ');
_outputBuilder.Write("lpVtbl");
_outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
} }
else else
{ {
_outputBuilder.WriteIndentedLine("public void** lpVtbl;"); _outputBuilder.WriteIndented("public");
_outputBuilder.Write(' ');
_outputBuilder.Write("void");
_outputBuilder.Write('*');
_outputBuilder.Write('*');
_outputBuilder.Write(' ');
_outputBuilder.Write("lpVtbl");
_outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
} }
_outputBuilder.NeedsNewline = true; _outputBuilder.NeedsNewline = true;
@ -982,7 +986,8 @@ namespace ClangSharp
} }
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.WriteLine(';'); _testOutputBuilder.WriteSemicolon();
_testOutputBuilder.WriteNewline();
_testOutputBuilder.WriteBlockEnd(); _testOutputBuilder.WriteBlockEnd();
_testOutputBuilder.NeedsNewline = true; _testOutputBuilder.NeedsNewline = true;
} }
@ -1001,7 +1006,8 @@ namespace ClangSharp
_outputBuilder.Write(GetRemappedCursorName(baseCxxRecordDecl)); _outputBuilder.Write(GetRemappedCursorName(baseCxxRecordDecl));
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
_outputBuilder.Write(GetRemappedAnonymousName(cxxBaseSpecifier, "Base")); _outputBuilder.Write(GetRemappedAnonymousName(cxxBaseSpecifier, "Base"));
_outputBuilder.WriteLine(';'); _outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
_outputBuilder.NeedsNewline = true; _outputBuilder.NeedsNewline = true;
} }
@ -1355,7 +1361,8 @@ namespace ClangSharp
outputBuilder.Write(escapedName); outputBuilder.Write(escapedName);
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
} }
static void OutputVtblHelperMethod(PInvokeGenerator pinvokeGenerator, OutputBuilder outputBuilder, CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl, ref int vtblIndex, Dictionary<string, int> hitsPerName) static void OutputVtblHelperMethod(PInvokeGenerator pinvokeGenerator, OutputBuilder outputBuilder, CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl, ref int vtblIndex, Dictionary<string, int> hitsPerName)
@ -1432,7 +1439,8 @@ namespace ClangSharp
outputBuilder.Write(returnTypeName); outputBuilder.Write(returnTypeName);
outputBuilder.Write(' '); outputBuilder.Write(' ');
outputBuilder.Write("result"); outputBuilder.Write("result");
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.WriteIndentation(); outputBuilder.WriteIndentation();
} }
@ -1537,7 +1545,8 @@ namespace ClangSharp
outputBuilder.Write('0'); outputBuilder.Write('0');
} }
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
if (pinvokeGenerator._config.GenerateCompatibleCode) if (pinvokeGenerator._config.GenerateCompatibleCode)
{ {
@ -1630,7 +1639,8 @@ namespace ClangSharp
outputBuilder.Write(nestedRecordDeclName); outputBuilder.Write(nestedRecordDeclName);
outputBuilder.Write(' '); outputBuilder.Write(' ');
outputBuilder.Write(nestedRecordDeclFieldName); outputBuilder.Write(nestedRecordDeclFieldName);
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.NeedsNewline = true; outputBuilder.NeedsNewline = true;
if (!recordDecl.IsAnonymousStructOrUnion) if (!recordDecl.IsAnonymousStructOrUnion)
@ -1739,7 +1749,8 @@ namespace ClangSharp
outputBuilder.Write('-'); outputBuilder.Write('-');
outputBuilder.Write('>'); outputBuilder.Write('>');
outputBuilder.Write(fieldName); outputBuilder.Write(fieldName);
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
@ -1753,7 +1764,13 @@ namespace ClangSharp
outputBuilder.Write(contextName); outputBuilder.Write(contextName);
outputBuilder.Write('.'); outputBuilder.Write('.');
outputBuilder.Write(fieldName); outputBuilder.Write(fieldName);
outputBuilder.WriteLine(", 1));"); outputBuilder.Write(',');
outputBuilder.Write(' ');
outputBuilder.Write('1');
outputBuilder.Write(')');
outputBuilder.Write(')');
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
} }
} }
@ -1835,7 +1852,8 @@ namespace ClangSharp
outputBuilder.Write(typeName); outputBuilder.Write(typeName);
outputBuilder.Write(' '); outputBuilder.Write(' ');
outputBuilder.Write(bitfieldName); outputBuilder.Write(bitfieldName);
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.NeedsNewline = true; outputBuilder.NeedsNewline = true;
} }
} }
@ -1863,6 +1881,12 @@ namespace ClangSharp
var bitwidthHexStringBacking = ((1 << fieldDecl.BitWidthValue) - 1).ToString("X"); var bitwidthHexStringBacking = ((1 << fieldDecl.BitWidthValue) - 1).ToString("X");
var typeBacking = (index > 0) ? types[index - 1] : types[0]; var typeBacking = (index > 0) ? types[index - 1] : types[0];
var canonicalTypeBacking = typeBacking.CanonicalType; var canonicalTypeBacking = typeBacking.CanonicalType;
if (canonicalTypeBacking.Kind == CXTypeKind.CXType_Enum)
{
canonicalTypeBacking = ((EnumType)canonicalTypeBacking).Decl.IntegerType.CanonicalType;
}
var typeNameBacking = pinvokeGenerator.GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _); var typeNameBacking = pinvokeGenerator.GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _);
switch (canonicalTypeBacking.Kind) switch (canonicalTypeBacking.Kind)
@ -1924,6 +1948,11 @@ namespace ClangSharp
var bitwidthHexString = ((1 << fieldDecl.BitWidthValue) - 1).ToString("X"); var bitwidthHexString = ((1 << fieldDecl.BitWidthValue) - 1).ToString("X");
var canonicalType = fieldDecl.Type.CanonicalType; var canonicalType = fieldDecl.Type.CanonicalType;
if (canonicalType.Kind == CXTypeKind.CXType_Enum)
{
canonicalType = ((EnumType)canonicalType).Decl.IntegerType.CanonicalType;
}
switch (canonicalType.Kind) switch (canonicalType.Kind)
{ {
case CXTypeKind.CXType_Char_U: case CXTypeKind.CXType_Char_U:
@ -2034,7 +2063,8 @@ namespace ClangSharp
outputBuilder.Write(')'); outputBuilder.Write(')');
} }
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.NeedsNewline = true; outputBuilder.NeedsNewline = true;
@ -2135,7 +2165,8 @@ namespace ClangSharp
outputBuilder.Write(')'); outputBuilder.Write(')');
} }
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
} }
@ -2237,7 +2268,17 @@ namespace ClangSharp
sizePerDimension[d] = dimension; sizePerDimension[d] = dimension;
} }
outputBuilder.WriteLine(';'); if (outputBuilder.NeedsNewline)
{
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.NeedsNewline = true;
}
else
{
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
}
} }
outputBuilder.NeedsNewline = true; outputBuilder.NeedsNewline = true;
@ -2266,11 +2307,30 @@ namespace ClangSharp
outputBuilder.WriteBlockStart(); outputBuilder.WriteBlockStart();
outputBuilder.WriteIndentedLine("get"); outputBuilder.WriteIndentedLine("get");
outputBuilder.WriteBlockStart(); outputBuilder.WriteBlockStart();
outputBuilder.WriteIndented("fixed ("); outputBuilder.WriteIndented("fixed");
outputBuilder.Write(' ');
outputBuilder.Write('(');
outputBuilder.Write(typeName); outputBuilder.Write(typeName);
outputBuilder.WriteLine("* pThis = &e0)"); outputBuilder.Write('*');
outputBuilder.Write(' ');
outputBuilder.Write("pThis");
outputBuilder.Write(' ');
outputBuilder.Write('=');
outputBuilder.Write(' ');
outputBuilder.Write('&');
outputBuilder.Write("e0");
outputBuilder.WriteLine(')');
outputBuilder.WriteBlockStart(); outputBuilder.WriteBlockStart();
outputBuilder.WriteIndentedLine("return ref pThis[index];"); outputBuilder.WriteIndented("return");
outputBuilder.Write(' ');
outputBuilder.Write("ref");
outputBuilder.Write(' ');
outputBuilder.Write("pThis");
outputBuilder.Write('[');
outputBuilder.Write("index");
outputBuilder.Write(']');
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
@ -2284,7 +2344,12 @@ namespace ClangSharp
outputBuilder.Write("int.MaxValue"); outputBuilder.Write("int.MaxValue");
} }
outputBuilder.WriteLine(")[index];"); outputBuilder.Write(')');
outputBuilder.Write('[');
outputBuilder.Write("index");
outputBuilder.Write(']');
outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
outputBuilder.NeedsNewline = true; outputBuilder.NeedsNewline = true;
outputBuilder.WriteIndented("public"); outputBuilder.WriteIndented("public");
outputBuilder.Write(' '); outputBuilder.Write(' ');
@ -2314,7 +2379,8 @@ namespace ClangSharp
} }
outputBuilder.Write(')'); outputBuilder.Write(')');
outputBuilder.WriteLine(';'); outputBuilder.WriteSemicolon();
outputBuilder.WriteNewline();
} }
outputBuilder.WriteBlockEnd(); outputBuilder.WriteBlockEnd();
@ -2381,7 +2447,8 @@ namespace ClangSharp
Visit(typedefDecl.CursorChildren.OfType<ParmVarDecl>()); Visit(typedefDecl.CursorChildren.OfType<ParmVarDecl>());
_outputBuilder.Write(')'); _outputBuilder.Write(')');
_outputBuilder.WriteLine(";"); _outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
} }
StopUsingOutputBuilder(); StopUsingOutputBuilder();
} }
@ -2561,7 +2628,7 @@ namespace ClangSharp
} }
} }
} }
else if (type.IsLocalConstQualified && CanBeConstant(type)) else if (type.IsLocalConstQualified && CanBeConstant(type, varDecl.Init))
{ {
_outputBuilder.Write("const"); _outputBuilder.Write("const");
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
@ -2605,7 +2672,8 @@ namespace ClangSharp
Visit(varDecl.Init); Visit(varDecl.Init);
} }
_outputBuilder.WriteLine(";"); _outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
if (openedOutputBuilder) if (openedOutputBuilder)
{ {
@ -2653,15 +2721,15 @@ namespace ClangSharp
} }
} }
bool CanBeConstant(Type type) bool CanBeConstant(Type type, Expr initExpr)
{ {
if (type is AttributedType attributedType) if (type is AttributedType attributedType)
{ {
return CanBeConstant(attributedType.ModifiedType); return CanBeConstant(attributedType.ModifiedType, initExpr);
} }
else if (type is AutoType autoType) else if (type is AutoType autoType)
{ {
return CanBeConstant(autoType.CanonicalType); return CanBeConstant(autoType.CanonicalType, initExpr);
} }
else if (type is BuiltinType builtinType) else if (type is BuiltinType builtinType)
{ {
@ -2685,25 +2753,263 @@ namespace ClangSharp
case CXTypeKind.CXType_Float: case CXTypeKind.CXType_Float:
case CXTypeKind.CXType_Double: case CXTypeKind.CXType_Double:
{ {
return true; return IsConstant(initExpr);
} }
} }
} }
else if (type is ElaboratedType elaboratedType) else if (type is ElaboratedType elaboratedType)
{ {
return CanBeConstant(elaboratedType.NamedType); return CanBeConstant(elaboratedType.NamedType, initExpr);
} }
else if (type is EnumType enumType) else if (type is EnumType enumType)
{ {
return CanBeConstant(enumType.Decl.IntegerType); return CanBeConstant(enumType.Decl.IntegerType, initExpr);
} }
else if (type is TypedefType typedefType) else if (type is TypedefType typedefType)
{ {
return CanBeConstant(typedefType.Decl.UnderlyingType); return CanBeConstant(typedefType.Decl.UnderlyingType, initExpr);
} }
return false; return false;
} }
} }
bool IsConstant(Expr initExpr)
{
switch (initExpr.StmtClass)
{
// case CX_StmtClass.CX_StmtClass_BinaryConditionalOperator:
// case CX_StmtClass.CX_StmtClass_ConditionalOperator:
// case CX_StmtClass.CX_StmtClass_AddrLabelExpr:
// case CX_StmtClass.CX_StmtClass_ArrayInitIndexExpr:
// case CX_StmtClass.CX_StmtClass_ArrayInitLoopExpr:
// case CX_StmtClass.CX_StmtClass_ArraySubscriptExpr:
// case CX_StmtClass.CX_StmtClass_ArrayTypeTraitExpr:
// case CX_StmtClass.CX_StmtClass_AsTypeExpr:
// case CX_StmtClass.CX_StmtClass_AtomicExpr:
case CX_StmtClass.CX_StmtClass_BinaryOperator:
{
var binaryOperator = (BinaryOperator)initExpr;
return IsConstant(binaryOperator.LHS) && IsConstant(binaryOperator.RHS);
}
// case CX_StmtClass.CX_StmtClass_CompoundAssignOperator:
// case CX_StmtClass.CX_StmtClass_BlockExpr:
// case CX_StmtClass.CX_StmtClass_CXXBindTemporaryExpr:
case CX_StmtClass.CX_StmtClass_CXXBoolLiteralExpr:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_CXXConstructExpr:
// case CX_StmtClass.CX_StmtClass_CXXTemporaryObjectExpr:
// case CX_StmtClass.CX_StmtClass_CXXDefaultArgExpr:
// case CX_StmtClass.CX_StmtClass_CXXDefaultInitExpr:
// case CX_StmtClass.CX_StmtClass_CXXDeleteExpr:
// case CX_StmtClass.CX_StmtClass_CXXDependentScopeMemberExpr:
// case CX_StmtClass.CX_StmtClass_CXXFoldExpr:
// case CX_StmtClass.CX_StmtClass_CXXInheritedCtorInitExpr:
// case CX_StmtClass.CX_StmtClass_CXXNewExpr:
// case CX_StmtClass.CX_StmtClass_CXXNoexceptExpr:
case CX_StmtClass.CX_StmtClass_CXXNullPtrLiteralExpr:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_CXXPseudoDestructorExpr:
// case CX_StmtClass.CX_StmtClass_CXXRewrittenBinaryOperator:
// case CX_StmtClass.CX_StmtClass_CXXScalarValueInitExpr:
// case CX_StmtClass.CX_StmtClass_CXXStdInitializerListExpr:
// case CX_StmtClass.CX_StmtClass_CXXThisExpr:
// case CX_StmtClass.CX_StmtClass_CXXThrowExpr:
// case CX_StmtClass.CX_StmtClass_CXXTypeidExpr:
// case CX_StmtClass.CX_StmtClass_CXXUnresolvedConstructExpr:
// case CX_StmtClass.CX_StmtClass_CXXUuidofExpr:
case CX_StmtClass.CX_StmtClass_CallExpr:
{
return false;
}
// case CX_StmtClass.CX_StmtClass_CUDAKernelCallExpr:
// case CX_StmtClass.CX_StmtClass_CXXMemberCallExpr:
// case CX_StmtClass.CX_StmtClass_CXXOperatorCallExpr:
// case CX_StmtClass.CX_StmtClass_UserDefinedLiteral:
// case CX_StmtClass.CX_StmtClass_BuiltinBitCastExpr:
case CX_StmtClass.CX_StmtClass_CStyleCastExpr:
{
var cStyleCastExpr = (CStyleCastExpr)initExpr;
return IsConstant(cStyleCastExpr.SubExpr);
}
// case CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr:
// case CX_StmtClass.CX_StmtClass_CXXConstCastExpr:
// case CX_StmtClass.CX_StmtClass_CXXDynamicCastExpr:
// case CX_StmtClass.CX_StmtClass_CXXReinterpretCastExpr:
// case CX_StmtClass.CX_StmtClass_CXXStaticCastExpr:
// case CX_StmtClass.CX_StmtClass_ObjCBridgedCastExpr:
case CX_StmtClass.CX_StmtClass_ImplicitCastExpr:
{
var implicitCastExpr = (ImplicitCastExpr)initExpr;
return IsConstant(implicitCastExpr.SubExpr);
}
case CX_StmtClass.CX_StmtClass_CharacterLiteral:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_ChooseExpr:
// case CX_StmtClass.CX_StmtClass_CompoundLiteralExpr:
// case CX_StmtClass.CX_StmtClass_ConceptSpecializationExpr:
// case CX_StmtClass.CX_StmtClass_ConvertVectorExpr:
// case CX_StmtClass.CX_StmtClass_CoawaitExpr:
// case CX_StmtClass.CX_StmtClass_CoyieldExpr:
case CX_StmtClass.CX_StmtClass_DeclRefExpr:
{
var declRefExpr = (DeclRefExpr)initExpr;
return (declRefExpr.Decl is EnumConstantDecl) ||
((declRefExpr.Decl is VarDecl varDecl) && IsConstant(varDecl.Init));
}
// case CX_StmtClass.CX_StmtClass_DependentCoawaitExpr:
// case CX_StmtClass.CX_StmtClass_DependentScopeDeclRefExpr:
// case CX_StmtClass.CX_StmtClass_DesignatedInitExpr:
// case CX_StmtClass.CX_StmtClass_DesignatedInitUpdateExpr:
// case CX_StmtClass.CX_StmtClass_ExpressionTraitExpr:
// case CX_StmtClass.CX_StmtClass_ExtVectorElementExpr:
// case CX_StmtClass.CX_StmtClass_FixedPointLiteral:
case CX_StmtClass.CX_StmtClass_FloatingLiteral:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_ConstantExpr:
// case CX_StmtClass.CX_StmtClass_ExprWithCleanups:
// case CX_StmtClass.CX_StmtClass_FunctionParmPackExpr:
// case CX_StmtClass.CX_StmtClass_GNUNullExpr:
// case CX_StmtClass.CX_StmtClass_GenericSelectionExpr:
// case CX_StmtClass.CX_StmtClass_ImaginaryLiteral:
// case CX_StmtClass.CX_StmtClass_ImplicitValueInitExpr:
// case CX_StmtClass.CX_StmtClass_InitListExpr:
case CX_StmtClass.CX_StmtClass_IntegerLiteral:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_LambdaExpr:
// case CX_StmtClass.CX_StmtClass_MSPropertyRefExpr:
// case CX_StmtClass.CX_StmtClass_MSPropertySubscriptExpr:
// case CX_StmtClass.CX_StmtClass_MaterializeTemporaryExpr:
case CX_StmtClass.CX_StmtClass_MemberExpr:
{
return false;
}
// case CX_StmtClass.CX_StmtClass_NoInitExpr:
// case CX_StmtClass.CX_StmtClass_OMPArraySectionExpr:
// case CX_StmtClass.CX_StmtClass_ObjCArrayLiteral:
// case CX_StmtClass.CX_StmtClass_ObjCAvailabilityCheckExpr:
// case CX_StmtClass.CX_StmtClass_ObjCBoolLiteralExpr:
// case CX_StmtClass.CX_StmtClass_ObjCBoxedExpr:
// case CX_StmtClass.CX_StmtClass_ObjCDictionaryLiteral:
// case CX_StmtClass.CX_StmtClass_ObjCEncodeExpr:
// case CX_StmtClass.CX_StmtClass_ObjCIndirectCopyRestoreExpr:
// case CX_StmtClass.CX_StmtClass_ObjCIsaExpr:
// case CX_StmtClass.CX_StmtClass_ObjCIvarRefExpr:
// case CX_StmtClass.CX_StmtClass_ObjCMessageExpr:
// case CX_StmtClass.CX_StmtClass_ObjCPropertyRefExpr:
// case CX_StmtClass.CX_StmtClass_ObjCProtocolExpr:
// case CX_StmtClass.CX_StmtClass_ObjCSelectorExpr:
// case CX_StmtClass.CX_StmtClass_ObjCStringLiteral:
// case CX_StmtClass.CX_StmtClass_ObjCSubscriptRefExpr:
// case CX_StmtClass.CX_StmtClass_OffsetOfExpr:
// case CX_StmtClass.CX_StmtClass_OpaqueValueExpr:
// case CX_StmtClass.CX_StmtClass_UnresolvedLookupExpr:
// case CX_StmtClass.CX_StmtClass_UnresolvedMemberExpr:
// case CX_StmtClass.CX_StmtClass_PackExpansionExpr:
case CX_StmtClass.CX_StmtClass_ParenExpr:
{
var parenExpr = (ParenExpr)initExpr;
return IsConstant(parenExpr.SubExpr);
}
// case CX_StmtClass.CX_StmtClass_ParenListExpr:
// case CX_StmtClass.CX_StmtClass_PredefinedExpr:
// case CX_StmtClass.CX_StmtClass_PseudoObjectExpr:
// case CX_StmtClass.CX_StmtClass_RequiresExpr:
// case CX_StmtClass.CX_StmtClass_ShuffleVectorExpr:
// case CX_StmtClass.CX_StmtClass_SizeOfPackExpr:
// case CX_StmtClass.CX_StmtClass_SourceLocExpr:
// case CX_StmtClass.CX_StmtClass_StmtExpr:
case CX_StmtClass.CX_StmtClass_StringLiteral:
{
return true;
}
// case CX_StmtClass.CX_StmtClass_SubstNonTypeTemplateParmExpr:
// case CX_StmtClass.CX_StmtClass_SubstNonTypeTemplateParmPackExpr:
// case CX_StmtClass.CX_StmtClass_TypeTraitExpr:
// case CX_StmtClass.CX_StmtClass_TypoExpr:
case CX_StmtClass.CX_StmtClass_UnaryExprOrTypeTraitExpr:
{
var unaryExprOrTypeTraitExpr = (UnaryExprOrTypeTraitExpr)initExpr;
var argumentType = unaryExprOrTypeTraitExpr.TypeOfArgument;
long size32;
long size64;
long alignment32 = -1;
long alignment64 = -1;
GetTypeSize(unaryExprOrTypeTraitExpr, argumentType, ref alignment32, ref alignment64, out size32, out size64);
switch (unaryExprOrTypeTraitExpr.Kind)
{
case CX_UnaryExprOrTypeTrait.CX_UETT_SizeOf:
{
return (size32 == size64);
}
case CX_UnaryExprOrTypeTrait.CX_UETT_AlignOf:
case CX_UnaryExprOrTypeTrait.CX_UETT_PreferredAlignOf:
{
return (alignment32 == alignment64);
}
default:
{
return false;
}
}
}
case CX_StmtClass.CX_StmtClass_UnaryOperator:
{
var unaryOperator = (UnaryOperator)initExpr;
return IsConstant(unaryOperator.SubExpr);
}
// case CX_StmtClass.CX_StmtClass_VAArgExpr:
default:
{
AddDiagnostic(DiagnosticLevel.Warning, $"Unsupported VarDecl.InitExpr: '{initExpr.StmtClassName}'. Generated bindings may not be constant.", initExpr);
return false;
}
}
}
} }
} }

Просмотреть файл

@ -32,6 +32,27 @@ namespace ClangSharp
_outputBuilder.Write("break"); _outputBuilder.Write("break");
} }
private void VisitBody(Stmt stmt)
{
if (stmt is CompoundStmt)
{
Visit(stmt);
}
else
{
_outputBuilder.WriteBlockStart();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
_outputBuilder.NeedsNewline = true;
Visit(stmt);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteNewlineIfNeeded();
_outputBuilder.WriteBlockEnd();
}
}
private void VisitCallExpr(CallExpr callExpr) private void VisitCallExpr(CallExpr callExpr)
{ {
var calleeDecl = callExpr.CalleeDecl; var calleeDecl = callExpr.CalleeDecl;
@ -87,42 +108,95 @@ namespace ClangSharp
Visit(caseStmt.LHS); Visit(caseStmt.LHS);
_outputBuilder.WriteLine(':'); _outputBuilder.WriteLine(':');
if (caseStmt.SubStmt is CompoundStmt) if (caseStmt.SubStmt is SwitchCase)
{
Visit(caseStmt.SubStmt);
}
else if (caseStmt.SubStmt is SwitchCase)
{ {
_outputBuilder.WriteIndentation(); _outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(caseStmt.SubStmt); Visit(caseStmt.SubStmt);
} }
else else
{ {
_outputBuilder.IncreaseIndentation(); VisitBody(caseStmt.SubStmt);
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(caseStmt.SubStmt);
_outputBuilder.DecreaseIndentation();
} }
_outputBuilder.NeedsNewline = true;
} }
private void VisitCharacterLiteral(CharacterLiteral characterLiteral) private void VisitCharacterLiteral(CharacterLiteral characterLiteral)
{ {
_outputBuilder.Write(characterLiteral.ValueString); switch (characterLiteral.Kind)
{
case CX_CharacterKind.CX_CLK_Ascii:
case CX_CharacterKind.CX_CLK_UTF8:
{
if (characterLiteral.Value > ushort.MaxValue)
{
_outputBuilder.Write("0x");
_outputBuilder.Write(characterLiteral.Value.ToString("X8"));
}
else if (characterLiteral.Value > byte.MaxValue)
{
_outputBuilder.Write("0x");
_outputBuilder.Write(characterLiteral.Value.ToString("X4"));
}
else
{
_outputBuilder.Write('(');
_outputBuilder.Write("byte");
_outputBuilder.Write(')');
_outputBuilder.Write('\'');
_outputBuilder.Write(EscapeCharacter((char)characterLiteral.Value));
_outputBuilder.Write('\'');
}
break;
}
case CX_CharacterKind.CX_CLK_Wide:
{
if (_config.GenerateUnixTypes)
{
goto default;
}
goto case CX_CharacterKind.CX_CLK_UTF16;
}
case CX_CharacterKind.CX_CLK_UTF16:
{
if (characterLiteral.Value > ushort.MaxValue)
{
_outputBuilder.Write("0x");
_outputBuilder.Write(characterLiteral.Value.ToString("X8"));
}
else
{
_outputBuilder.Write('\'');
_outputBuilder.Write(EscapeCharacter((char)characterLiteral.Value));
_outputBuilder.Write('\'');
}
break;
}
case CX_CharacterKind.CX_CLK_UTF32:
{
_outputBuilder.Write("0x");
_outputBuilder.Write(characterLiteral.Value.ToString("X8"));
break;
}
default:
{
AddDiagnostic(DiagnosticLevel.Error, $"Unsupported character literal kind: '{characterLiteral.Kind}'. Generated bindings may be incomplete.", characterLiteral);
break;
}
}
} }
private void VisitCompoundStmt(CompoundStmt compoundStmt) private void VisitCompoundStmt(CompoundStmt compoundStmt)
{ {
_outputBuilder.WriteBlockStart(); _outputBuilder.WriteBlockStart();
_outputBuilder.NeedsSemicolon = true;
VisitStmts(compoundStmt.Body); VisitStmts(compoundStmt.Body);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteNewlineIfNeeded();
_outputBuilder.WriteBlockEnd(); _outputBuilder.WriteBlockEnd();
} }
@ -159,6 +233,19 @@ namespace ClangSharp
private void VisitCXXConstructExpr(CXXConstructExpr cxxConstructExpr) private void VisitCXXConstructExpr(CXXConstructExpr cxxConstructExpr)
{ {
var isCopyConstructor = cxxConstructExpr.Constructor.IsCopyConstructor;
if (!isCopyConstructor)
{
_outputBuilder.Write("new");
_outputBuilder.Write(' ');
var constructorName = GetRemappedCursorName(cxxConstructExpr.Constructor);
_outputBuilder.Write(constructorName);
_outputBuilder.Write('(');
}
var args = cxxConstructExpr.Args; var args = cxxConstructExpr.Args;
if (args.Count != 0) if (args.Count != 0)
@ -172,22 +259,18 @@ namespace ClangSharp
Visit(args[i]); Visit(args[i]);
} }
} }
if (!isCopyConstructor)
{
_outputBuilder.Write(')');
}
} }
private void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr cxxFunctionalCastExpr) private void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr cxxFunctionalCastExpr)
{ {
if (cxxFunctionalCastExpr.SubExpr is CXXConstructExpr) if (cxxFunctionalCastExpr.SubExpr is CXXConstructExpr)
{ {
_outputBuilder.Write("new");
_outputBuilder.Write(' ');
var type = cxxFunctionalCastExpr.Type;
var typeName = GetRemappedTypeName(cxxFunctionalCastExpr, context: null, type, out var nativeTypeName);
_outputBuilder.Write(typeName);
_outputBuilder.Write('(');
Visit(cxxFunctionalCastExpr.SubExpr); Visit(cxxFunctionalCastExpr.SubExpr);
_outputBuilder.Write(')');
} }
else else
{ {
@ -245,8 +328,28 @@ namespace ClangSharp
_outputBuilder.Write("this"); _outputBuilder.Write("this");
} }
private void VisitCXXUuidofExpr(CXXUuidofExpr cxxUuidofExpr)
{
_outputBuilder.Write("typeof");
_outputBuilder.Write('(');
var type = cxxUuidofExpr.IsTypeOperand ? cxxUuidofExpr.TypeOperand : cxxUuidofExpr.ExprOperand.Type;
var typeName = GetRemappedTypeName(cxxUuidofExpr, context: null, type, out _);
_outputBuilder.Write(typeName);
_outputBuilder.Write(')');
_outputBuilder.Write('.');
_outputBuilder.Write("GUID");
}
private void VisitDeclRefExpr(DeclRefExpr declRefExpr) private void VisitDeclRefExpr(DeclRefExpr declRefExpr)
{ {
if ((declRefExpr.Decl is EnumConstantDecl enumConstantDecl) && (declRefExpr.DeclContext != enumConstantDecl.DeclContext) && (enumConstantDecl.DeclContext is NamedDecl namedDecl))
{
var enumName = GetRemappedCursorName(namedDecl);
_outputBuilder.AddUsingDirective($"static {_config.Namespace}.{enumName}");
}
var name = GetRemappedCursorName(declRefExpr.Decl); var name = GetRemappedCursorName(declRefExpr.Decl);
_outputBuilder.Write(EscapeAndStripName(name)); _outputBuilder.Write(EscapeAndStripName(name));
} }
@ -268,8 +371,6 @@ namespace ClangSharp
Visit(decl); Visit(decl);
} }
} }
_outputBuilder.NeedsNewline = true;
} }
private void VisitDefaultStmt(DefaultStmt defaultStmt) private void VisitDefaultStmt(DefaultStmt defaultStmt)
@ -277,31 +378,14 @@ namespace ClangSharp
_outputBuilder.Write("default"); _outputBuilder.Write("default");
_outputBuilder.WriteLine(':'); _outputBuilder.WriteLine(':');
if (defaultStmt.SubStmt != null) if (defaultStmt.SubStmt is SwitchCase)
{ {
if (defaultStmt.SubStmt is CompoundStmt) _outputBuilder.WriteIndentation();
{ Visit(defaultStmt.SubStmt);
Visit(defaultStmt.SubStmt); }
} else
{
else if (defaultStmt.SubStmt is SwitchCase) VisitBody(defaultStmt.SubStmt);
{
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(defaultStmt.SubStmt);
}
else
{
_outputBuilder.IncreaseIndentation();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(defaultStmt.SubStmt);
_outputBuilder.DecreaseIndentation();
}
_outputBuilder.NeedsNewline = true;
} }
} }
@ -309,30 +393,18 @@ namespace ClangSharp
{ {
_outputBuilder.WriteLine("do"); _outputBuilder.WriteLine("do");
if (doStmt.Body is CompoundStmt) VisitBody(doStmt.Body);
{
Visit(doStmt.Body);
}
else
{
_outputBuilder.IncreaseIndentation();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(doStmt.Body);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.DecreaseIndentation();
}
_outputBuilder.WriteIndented("while"); _outputBuilder.WriteIndented("while");
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
_outputBuilder.Write('('); _outputBuilder.Write('(');
Visit(doStmt.Cond); Visit(doStmt.Cond);
_outputBuilder.Write(')');
_outputBuilder.NeedsSemicolon = true; _outputBuilder.Write(')');
_outputBuilder.WriteSemicolon();
_outputBuilder.WriteNewline();
_outputBuilder.NeedsNewline = true; _outputBuilder.NeedsNewline = true;
} }
@ -406,39 +478,30 @@ namespace ClangSharp
{ {
Visit(forStmt.Init); Visit(forStmt.Init);
} }
_outputBuilder.Write(';'); _outputBuilder.WriteSemicolon();
if (forStmt.Cond != null) if (forStmt.Cond != null)
{ {
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
Visit(forStmt.Cond); Visit(forStmt.Cond);
} }
_outputBuilder.Write(';'); _outputBuilder.WriteSemicolon();
if (forStmt.Inc != null) if (forStmt.Inc != null)
{ {
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
Visit(forStmt.Inc); Visit(forStmt.Inc);
} }
_outputBuilder.Write(')'); _outputBuilder.WriteLine(')');
_outputBuilder.NeedsNewline = true;
if (forStmt.Body is CompoundStmt) VisitBody(forStmt.Body);
{ }
Visit(forStmt.Body);
}
else
{
_outputBuilder.IncreaseIndentation();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true; private void VisitGotoStmt(GotoStmt gotoStmt)
Visit(forStmt.Body); {
_outputBuilder.Write("goto");
_outputBuilder.DecreaseIndentation(); _outputBuilder.Write(' ');
} _outputBuilder.Write(gotoStmt.Label.Name);
_outputBuilder.NeedsNewline = true;
} }
private void VisitIfStmt(IfStmt ifStmt) private void VisitIfStmt(IfStmt ifStmt)
@ -451,58 +514,36 @@ namespace ClangSharp
_outputBuilder.WriteLine(')'); _outputBuilder.WriteLine(')');
if (ifStmt.Then is CompoundStmt) VisitBody(ifStmt.Then);
{
Visit(ifStmt.Then);
}
else
{
_outputBuilder.IncreaseIndentation();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(ifStmt.Then);
if (ifStmt.Else != null)
{
_outputBuilder.WriteSemicolonIfNeeded();
}
_outputBuilder.DecreaseIndentation();
}
if (ifStmt.Else != null) if (ifStmt.Else != null)
{ {
_outputBuilder.WriteIndented("else"); _outputBuilder.WriteIndented("else");
_outputBuilder.NeedsNewline = true;
if (ifStmt.Else is CompoundStmt) if (ifStmt.Else is IfStmt)
{
Visit(ifStmt.Else);
}
else if (ifStmt.Else is IfStmt)
{ {
_outputBuilder.Write(' '); _outputBuilder.Write(' ');
_outputBuilder.NeedsNewline = false;
Visit(ifStmt.Else); Visit(ifStmt.Else);
} }
else else
{ {
_outputBuilder.IncreaseIndentation(); _outputBuilder.WriteNewline();
_outputBuilder.WriteIndentation(); VisitBody(ifStmt.Else);
_outputBuilder.NeedsSemicolon = true;
Visit(ifStmt.Else);
_outputBuilder.DecreaseIndentation();
} }
} }
_outputBuilder.NeedsNewline = true;
} }
private void VisitImplicitCastExpr(ImplicitCastExpr implicitCastExpr) private void VisitImplicitCastExpr(ImplicitCastExpr implicitCastExpr)
{ {
if (implicitCastExpr.SubExpr is IntegerLiteral integerLiteral) if (implicitCastExpr.CastKind == CX_CastKind.CX_CK_NullToPointer)
{
_outputBuilder.Write("null");
}
else if ((implicitCastExpr.SubExpr is DeclRefExpr declRefExpr) && (declRefExpr.Decl is EnumConstantDecl enumConstantDecl))
{
ForEnumConstantDecl(implicitCastExpr, enumConstantDecl);
}
else if (implicitCastExpr.SubExpr is IntegerLiteral integerLiteral)
{ {
ForIntegerLiteral(implicitCastExpr, integerLiteral); ForIntegerLiteral(implicitCastExpr, integerLiteral);
} }
@ -511,48 +552,57 @@ namespace ClangSharp
Visit(implicitCastExpr.SubExpr); Visit(implicitCastExpr.SubExpr);
} }
void ForIntegerLiteral(ImplicitCastExpr implicitCastExpr, IntegerLiteral integerLiteral) void ForEnumConstantDecl(ImplicitCastExpr implicitCastExpr, EnumConstantDecl enumConstantDecl)
{ {
if ((implicitCastExpr.Type is PointerType) && integerLiteral.ValueString.Equals("0")) if ((implicitCastExpr.DeclContext is EnumDecl enumDecl) || (PreviousContext is BinaryOperator binaryOperator))
{ {
// C# doesn't have implicit conversion from zero to a pointer Visit(implicitCastExpr.SubExpr);
// so we will manually check and handle the most common case
_outputBuilder.Write("null");
} }
else else
{ {
var type = implicitCastExpr.Type; var type = implicitCastExpr.Type;
var typeName = GetRemappedTypeName(implicitCastExpr, context: null, type, out var nativeTypeName); var typeName = GetRemappedTypeName(implicitCastExpr, context: null, type, out var nativeTypeName);
if (implicitCastExpr.DeclContext is EnumDecl enumDecl) _outputBuilder.Write('(');
{ _outputBuilder.Write(typeName);
var enumDeclName = GetRemappedCursorName(enumDecl); _outputBuilder.Write(')');
var enumDeclIntegerTypeName = GetRemappedTypeName(enumDecl, context: null, enumDecl.IntegerType, out var enumDeclNativeTypeName);
WithType("*", ref enumDeclIntegerTypeName, ref enumDeclNativeTypeName);
WithType(enumDeclName, ref enumDeclIntegerTypeName, ref enumDeclNativeTypeName);
typeName = enumDeclIntegerTypeName;
}
var isUncheckedCast = GetIsUncheckedCastNeeded(typeName, implicitCastExpr.SubExpr);
if (isUncheckedCast)
{
_outputBuilder.Write("unchecked");
_outputBuilder.Write('(');
_outputBuilder.Write('(');
_outputBuilder.Write(typeName);
_outputBuilder.Write(')');
}
Visit(implicitCastExpr.SubExpr); Visit(implicitCastExpr.SubExpr);
}
}
if (isUncheckedCast) void ForIntegerLiteral(ImplicitCastExpr implicitCastExpr, IntegerLiteral integerLiteral)
{ {
_outputBuilder.Write(')'); var type = implicitCastExpr.Type;
} var typeName = GetRemappedTypeName(implicitCastExpr, context: null, type, out var nativeTypeName);
if (implicitCastExpr.DeclContext is EnumDecl enumDecl)
{
var enumDeclName = GetRemappedCursorName(enumDecl);
var enumDeclIntegerTypeName = GetRemappedTypeName(enumDecl, context: null, enumDecl.IntegerType, out var enumDeclNativeTypeName);
WithType("*", ref enumDeclIntegerTypeName, ref enumDeclNativeTypeName);
WithType(enumDeclName, ref enumDeclIntegerTypeName, ref enumDeclNativeTypeName);
typeName = enumDeclIntegerTypeName;
}
var isUncheckedCast = GetIsUncheckedCastNeeded(typeName, implicitCastExpr.SubExpr);
if (isUncheckedCast)
{
_outputBuilder.Write("unchecked");
_outputBuilder.Write('(');
_outputBuilder.Write('(');
_outputBuilder.Write(typeName);
_outputBuilder.Write(')');
}
Visit(implicitCastExpr.SubExpr);
if (isUncheckedCast)
{
_outputBuilder.Write(')');
} }
} }
} }
@ -609,11 +659,9 @@ namespace ClangSharp
_outputBuilder.WriteLine(','); _outputBuilder.WriteLine(',');
} }
_outputBuilder.NeedsNewline = false;
_outputBuilder.NeedsSemicolon = false;
_outputBuilder.DecreaseIndentation(); _outputBuilder.DecreaseIndentation();
_outputBuilder.WriteIndented('}'); _outputBuilder.WriteIndented('}');
_outputBuilder.WriteLine(';'); _outputBuilder.NeedsSemicolon = true;
} }
void ForRecordType(InitListExpr initListExpr, RecordType recordType) void ForRecordType(InitListExpr initListExpr, RecordType recordType)
@ -655,7 +703,7 @@ namespace ClangSharp
} }
else else
{ {
_outputBuilder.WriteLine(); _outputBuilder.WriteNewline();
_outputBuilder.WriteBlockStart(); _outputBuilder.WriteBlockStart();
var decl = recordType.Decl; var decl = recordType.Decl;
@ -679,11 +727,9 @@ namespace ClangSharp
_outputBuilder.WriteLine(','); _outputBuilder.WriteLine(',');
} }
_outputBuilder.NeedsNewline = false;
_outputBuilder.NeedsSemicolon = false;
_outputBuilder.DecreaseIndentation(); _outputBuilder.DecreaseIndentation();
_outputBuilder.WriteIndented('}'); _outputBuilder.WriteIndented('}');
_outputBuilder.WriteLine(';'); _outputBuilder.NeedsSemicolon = true;
} }
} }
@ -716,7 +762,7 @@ namespace ClangSharp
{ {
var valueString = integerLiteral.ValueString; var valueString = integerLiteral.ValueString;
if (valueString.EndsWith("L", StringComparison.OrdinalIgnoreCase)) if (valueString.EndsWith("l", StringComparison.OrdinalIgnoreCase))
{ {
valueString = valueString.Substring(0, valueString.Length - 1); valueString = valueString.Substring(0, valueString.Length - 1);
} }
@ -742,12 +788,34 @@ namespace ClangSharp
} }
else if (valueString.EndsWith("i64", StringComparison.OrdinalIgnoreCase)) else if (valueString.EndsWith("i64", StringComparison.OrdinalIgnoreCase))
{ {
valueString = valueString.Substring(0, valueString.Length - 3); valueString = valueString.Substring(0, valueString.Length - 3) + "L";
}
if (valueString.EndsWith("ul", StringComparison.OrdinalIgnoreCase))
{
valueString = valueString.Substring(0, valueString.Length - 2) + "UL";
}
else if (valueString.EndsWith("l", StringComparison.OrdinalIgnoreCase))
{
valueString = valueString.Substring(0, valueString.Length - 1) + "L";
}
else if (valueString.EndsWith("u", StringComparison.OrdinalIgnoreCase))
{
valueString = valueString.Substring(0, valueString.Length - 1) + "U";
} }
_outputBuilder.Write(valueString); _outputBuilder.Write(valueString);
} }
private void VisitLabelStmt(LabelStmt labelStmt)
{
_outputBuilder.Write(labelStmt.Decl.Name);
_outputBuilder.WriteLine(':');
_outputBuilder.WriteIndentation();
Visit(labelStmt.SubStmt);
}
private void VisitMemberExpr(MemberExpr memberExpr) private void VisitMemberExpr(MemberExpr memberExpr)
{ {
if (!memberExpr.IsImplicitAccess) if (!memberExpr.IsImplicitAccess)
@ -791,20 +859,11 @@ namespace ClangSharp
private void VisitReturnStmt(ReturnStmt returnStmt) private void VisitReturnStmt(ReturnStmt returnStmt)
{ {
var retValue = returnStmt.RetValue; _outputBuilder.Write("return");
if ((retValue is null) || (retValue.Type.Kind != CXTypeKind.CXType_Void)) if (returnStmt.RetValue != null)
{
_outputBuilder.Write("return");
if (retValue != null)
{
_outputBuilder.Write(' ');
}
}
if (retValue != null)
{ {
_outputBuilder.Write(' ');
Visit(returnStmt.RetValue); Visit(returnStmt.RetValue);
} }
} }
@ -860,7 +919,11 @@ namespace ClangSharp
break; break;
} }
// case CX_StmtClass.CX_StmtClass_GotoStmt: case CX_StmtClass.CX_StmtClass_GotoStmt:
{
VisitGotoStmt((GotoStmt)stmt);
break;
}
case CX_StmtClass.CX_StmtClass_IfStmt: case CX_StmtClass.CX_StmtClass_IfStmt:
{ {
@ -1029,7 +1092,12 @@ namespace ClangSharp
// case CX_StmtClass.CX_StmtClass_CXXThrowExpr: // case CX_StmtClass.CX_StmtClass_CXXThrowExpr:
// case CX_StmtClass.CX_StmtClass_CXXTypeidExpr: // case CX_StmtClass.CX_StmtClass_CXXTypeidExpr:
// case CX_StmtClass.CX_StmtClass_CXXUnresolvedConstructExpr: // case CX_StmtClass.CX_StmtClass_CXXUnresolvedConstructExpr:
// case CX_StmtClass.CX_StmtClass_CXXUuidofExpr:
case CX_StmtClass.CX_StmtClass_CXXUuidofExpr:
{
VisitCXXUuidofExpr((CXXUuidofExpr)stmt);
break;
}
case CX_StmtClass.CX_StmtClass_CallExpr: case CX_StmtClass.CX_StmtClass_CallExpr:
case CX_StmtClass.CX_StmtClass_CXXMemberCallExpr: case CX_StmtClass.CX_StmtClass_CXXMemberCallExpr:
@ -1207,7 +1275,12 @@ namespace ClangSharp
} }
// case CX_StmtClass.CX_StmtClass_VAArgExpr: // case CX_StmtClass.CX_StmtClass_VAArgExpr:
// case CX_StmtClass.CX_StmtClass_LabelStmt:
case CX_StmtClass.CX_StmtClass_LabelStmt:
{
VisitLabelStmt((LabelStmt)stmt);
break;
}
case CX_StmtClass.CX_StmtClass_WhileStmt: case CX_StmtClass.CX_StmtClass_WhileStmt:
{ {
@ -1230,23 +1303,50 @@ namespace ClangSharp
} }
} }
private void VisitStmts(IEnumerable<Stmt> stmts) private void VisitStmts(IReadOnlyList<Stmt> stmts)
{ {
Stmt previousStmt = null; var lastIndex = stmts.Count - 1;
var previousStmt = null as Stmt;
foreach (var stmt in stmts) for (int i = 0; i < lastIndex; i++)
{ {
if ((previousStmt is DeclStmt declStmt) && (stmt is DeclStmt)) var stmt = stmts[i];
if ((previousStmt is DeclStmt) && !(stmt is DeclStmt))
{ {
_outputBuilder.NeedsNewline = false; _outputBuilder.NeedsNewline = true;
} }
_outputBuilder.WriteIndentation(); _outputBuilder.WriteIndentation();
Visit(stmt); _outputBuilder.NeedsSemicolon = true;
_outputBuilder.NeedsNewline = true;
Visit(stmts[i]);
_outputBuilder.WriteSemicolonIfNeeded(); _outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteNewline();
previousStmt = stmt; previousStmt = stmt;
} }
if (lastIndex != -1)
{
var stmt = stmts[lastIndex];
if ((previousStmt is DeclStmt) && !(stmt is DeclStmt))
{
_outputBuilder.NeedsNewline = true;
}
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
_outputBuilder.NeedsNewline = true;
Visit(stmt);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteNewlineIfNeeded();
}
} }
private void VisitStringLiteral(StringLiteral stringLiteral) private void VisitStringLiteral(StringLiteral stringLiteral)
@ -1294,7 +1394,7 @@ namespace ClangSharp
case CX_CharacterKind.CX_CLK_UTF16: case CX_CharacterKind.CX_CLK_UTF16:
{ {
_outputBuilder.Write('"'); _outputBuilder.Write('"');
_outputBuilder.Write(stringLiteral.String); _outputBuilder.Write(EscapeString(stringLiteral.String));
_outputBuilder.Write('"'); _outputBuilder.Write('"');
break; break;
} }
@ -1317,40 +1417,64 @@ namespace ClangSharp
_outputBuilder.WriteLine(')'); _outputBuilder.WriteLine(')');
if (switchStmt.Body is CompoundStmt) VisitBody(switchStmt.Body);
{
Visit(switchStmt.Body);
}
else
{
_outputBuilder.WriteBlockStart();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(switchStmt.Body);
_outputBuilder.WriteSemicolonIfNeeded();
_outputBuilder.WriteBlockEnd();
}
_outputBuilder.NeedsNewline = true;
} }
private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrTypeTraitExpr) private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrTypeTraitExpr)
{ {
var argumentType = unaryExprOrTypeTraitExpr.TypeOfArgument; var argumentType = unaryExprOrTypeTraitExpr.TypeOfArgument;
long size32;
long size64;
long alignment32 = -1;
long alignment64 = -1;
GetTypeSize(unaryExprOrTypeTraitExpr, argumentType, ref alignment32, ref alignment64, out size32, out size64);
switch (unaryExprOrTypeTraitExpr.Kind) switch (unaryExprOrTypeTraitExpr.Kind)
{ {
case CX_UnaryExprOrTypeTrait.CX_UETT_SizeOf: case CX_UnaryExprOrTypeTrait.CX_UETT_SizeOf:
{ {
_outputBuilder.Write("sizeof"); if ((size32 == size64) && (unaryExprOrTypeTraitExpr.DeclContext is VarDecl))
_outputBuilder.Write('('); {
_outputBuilder.Write(size32);
}
else
{
_outputBuilder.Write("sizeof");
_outputBuilder.Write('(');
var typeName = GetRemappedTypeName(unaryExprOrTypeTraitExpr, context: null, argumentType, out _); var typeName = GetRemappedTypeName(unaryExprOrTypeTraitExpr, context: null, argumentType, out _);
_outputBuilder.Write(typeName); _outputBuilder.Write(typeName);
_outputBuilder.Write(')');
}
break;
}
case CX_UnaryExprOrTypeTrait.CX_UETT_AlignOf:
case CX_UnaryExprOrTypeTrait.CX_UETT_PreferredAlignOf:
{
if (alignment32 == alignment64)
{
_outputBuilder.Write(alignment32);
}
else
{
_outputBuilder.Write("Environment");
_outputBuilder.Write('.');
_outputBuilder.Write("Is64BitProcess");
_outputBuilder.Write(' ');
_outputBuilder.Write('?');
_outputBuilder.Write(' ');
_outputBuilder.Write(alignment64);
_outputBuilder.Write(' ');
_outputBuilder.Write(':');
_outputBuilder.Write(' ');
_outputBuilder.Write(alignment32);
}
_outputBuilder.Write(')');
break; break;
} }
@ -1419,22 +1543,7 @@ namespace ClangSharp
_outputBuilder.WriteLine(')'); _outputBuilder.WriteLine(')');
if (whileStmt.Body is CompoundStmt) VisitBody(whileStmt.Body);
{
Visit(whileStmt.Body);
}
else
{
_outputBuilder.IncreaseIndentation();
_outputBuilder.WriteIndentation();
_outputBuilder.NeedsSemicolon = true;
Visit(whileStmt.Body);
_outputBuilder.DecreaseIndentation();
}
_outputBuilder.NeedsNewline = true;
} }
} }
} }

Просмотреть файл

@ -286,12 +286,7 @@ namespace ClangSharp
_outputBuilder.Write("NativeTypeName("); _outputBuilder.Write("NativeTypeName(");
_outputBuilder.Write('"'); _outputBuilder.Write('"');
_outputBuilder.Write(nativeTypeName.Replace("\\", "\\\\") _outputBuilder.Write(EscapeString(nativeTypeName));
.Replace("\r", "\\r")
.Replace("\n", "\\n")
.Replace("\t", "\\t")
.Replace("\"", "\\\"")
.Replace("\'", "\\\'"));
_outputBuilder.Write('"'); _outputBuilder.Write('"');
_outputBuilder.Write(")]"); _outputBuilder.Write(")]");
@ -531,6 +526,15 @@ namespace ClangSharp
return EscapeName(name); return EscapeName(name);
} }
private string EscapeCharacter(char value) => EscapeString(value.ToString());
private string EscapeString(string value) => value.Replace("\\", "\\\\")
.Replace("\r", "\\r")
.Replace("\n", "\\n")
.Replace("\t", "\\t")
.Replace("\"", "\\\"")
.Replace("\'", "\\\'");
private string GetAccessSpecifierName(NamedDecl namedDecl) private string GetAccessSpecifierName(NamedDecl namedDecl)
{ {
string name; string name;
@ -1344,8 +1348,8 @@ namespace ClangSharp
{ {
GetTypeSize(cursor, arrayType.ElementType, ref alignment32, ref alignment64, out var elementSize32, out var elementSize64); GetTypeSize(cursor, arrayType.ElementType, ref alignment32, ref alignment64, out var elementSize32, out var elementSize64);
size32 = elementSize32 * constantArrayType.Size; size32 = elementSize32 * Math.Max(constantArrayType.Size, 1);
size64 = elementSize64 * constantArrayType.Size; size64 = elementSize64 * Math.Max(constantArrayType.Size, 1);
if (alignment32 == -1) if (alignment32 == -1)
{ {
@ -1987,9 +1991,13 @@ namespace ClangSharp
private bool IsUnsafe(RecordDecl recordDecl) private bool IsUnsafe(RecordDecl recordDecl)
{ {
foreach (var fieldDecl in recordDecl.Fields) foreach (var decl in recordDecl.Decls)
{ {
if (IsUnsafe(fieldDecl)) if ((decl is FieldDecl fieldDecl) && IsUnsafe(fieldDecl))
{
return true;
}
else if ((decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && IsUnsafe(nestedRecordDecl))
{ {
return true; return true;
} }
@ -2429,7 +2437,8 @@ namespace ClangSharp
_testOutputBuilder.Write(expected); _testOutputBuilder.Write(expected);
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.WriteLine(';'); _testOutputBuilder.WriteSemicolon();
_testOutputBuilder.WriteNewline();
} }
else if (_config.GenerateTestsXUnit) else if (_config.GenerateTestsXUnit)
{ {
@ -2440,7 +2449,8 @@ namespace ClangSharp
_testOutputBuilder.Write(' '); _testOutputBuilder.Write(' ');
_testOutputBuilder.Write(actual); _testOutputBuilder.Write(actual);
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.WriteLine(';'); _testOutputBuilder.WriteSemicolon();
_testOutputBuilder.WriteNewline();
} }
} }
@ -2455,7 +2465,8 @@ namespace ClangSharp
_testOutputBuilder.Write(' '); _testOutputBuilder.Write(' ');
_testOutputBuilder.Write("Is.True"); _testOutputBuilder.Write("Is.True");
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.WriteLine(';'); _testOutputBuilder.WriteSemicolon();
_testOutputBuilder.WriteNewline();
} }
else if (_config.GenerateTestsXUnit) else if (_config.GenerateTestsXUnit)
{ {
@ -2463,7 +2474,8 @@ namespace ClangSharp
_testOutputBuilder.Write('('); _testOutputBuilder.Write('(');
_testOutputBuilder.Write(actual); _testOutputBuilder.Write(actual);
_testOutputBuilder.Write(')'); _testOutputBuilder.Write(')');
_testOutputBuilder.WriteLine(';'); _testOutputBuilder.WriteSemicolon();
_testOutputBuilder.WriteNewline();
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class CXXUuidofExpr : Expr public sealed class CXXUuidofExpr : Expr
{ {
private readonly Lazy<Expr> _exprOperand;
private readonly Lazy<Type> _typeOperand;
internal CXXUuidofExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXUuidofExpr) internal CXXUuidofExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXUuidofExpr)
{ {
_exprOperand = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(handle.SubExpr));
_typeOperand = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(handle.TypeOperand));
} }
public Expr ExprOperand => _exprOperand.Value;
public bool IsTypeOperand => Handle.IsTypeOperand;
public Type TypeOperand => _typeOperand.Value;
} }
} }

Просмотреть файл

@ -12,33 +12,15 @@ namespace ClangSharp
internal UnaryExprOrTypeTraitExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnaryExpr, CX_StmtClass.CX_StmtClass_UnaryExprOrTypeTraitExpr) internal UnaryExprOrTypeTraitExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnaryExpr, CX_StmtClass.CX_StmtClass_UnaryExprOrTypeTraitExpr)
{ {
_argumentExpr = new Lazy<Expr>(() => { _argumentExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.SubExpr));
try _argumentType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ArgumentType));
{
return TranslationUnit.GetOrCreate<Expr>(Handle.SubExpr);
}
catch
{
return null;
}
});
_argumentType = new Lazy<Type>(() => {
try
{
return TranslationUnit.GetOrCreate<Type>(Handle.ArgumentType);
}
catch
{
return null;
}
});
} }
public Expr ArgumentExpr => _argumentExpr.Value; public Expr ArgumentExpr => _argumentExpr.Value;
public Type ArgumentType => _argumentType.Value; public Type ArgumentType => _argumentType.Value;
public bool IsArgumentType => ArgumentExpr is null; public bool IsArgumentType => Handle.IsArgumentType;
public CX_UnaryExprOrTypeTrait Kind => Handle.UnaryExprOrTypeTraitKind; public CX_UnaryExprOrTypeTrait Kind => Handle.UnaryExprOrTypeTraitKind;

Просмотреть файл

@ -13,5 +13,7 @@ namespace ClangSharp
{ {
_label = new Lazy<LabelDecl>(() => TranslationUnit.GetOrCreate<LabelDecl>(Handle.Referenced)); _label = new Lazy<LabelDecl>(() => TranslationUnit.GetOrCreate<LabelDecl>(Handle.Referenced));
} }
public LabelDecl Label => _label.Value;
} }
} }

Просмотреть файл

@ -753,6 +753,8 @@ namespace ClangSharp.Interop
public bool IsAnonymousStructOrUnion => clangsharp.Cursor_getIsAnonymousStructOrUnion(this) != 0; public bool IsAnonymousStructOrUnion => clangsharp.Cursor_getIsAnonymousStructOrUnion(this) != 0;
public bool IsArgumentType => clangsharp.Cursor_getIsArgumentType(this) != 0;
public bool IsAttribute => clang.isAttribute(Kind) != 0; public bool IsAttribute => clang.isAttribute(Kind) != 0;
public bool IsBitField => clang.Cursor_isBitField(this) != 0; public bool IsBitField => clang.Cursor_isBitField(this) != 0;
@ -843,6 +845,8 @@ namespace ClangSharp.Interop
public bool IsTypeConcept => clangsharp.Cursor_getIsTypeConcept(this) != 0; public bool IsTypeConcept => clangsharp.Cursor_getIsTypeConcept(this) != 0;
public bool IsTypeOperand => clangsharp.Cursor_getIsTypeOperand(this) != 0;
public bool IsUnavailable => clangsharp.Cursor_getIsUnavailable(this) != 0; public bool IsUnavailable => clangsharp.Cursor_getIsUnavailable(this) != 0;
public bool IsUnexposed => clang.isUnexposed(Kind) != 0; public bool IsUnexposed => clang.isUnexposed(Kind) != 0;
@ -1264,6 +1268,8 @@ namespace ClangSharp.Interop
public CXType Type => clang.getCursorType(this); public CXType Type => clang.getCursorType(this);
public CXType TypeOperand => clangsharp.Cursor_getTypeOperand(this);
public CXType TypedefDeclUnderlyingType => clang.getTypedefDeclUnderlyingType(this); public CXType TypedefDeclUnderlyingType => clang.getTypedefDeclUnderlyingType(this);
public CXCursor TypedefNameForAnonDecl => clangsharp.Cursor_getTypedefNameForAnonDecl(this); public CXCursor TypedefNameForAnonDecl => clangsharp.Cursor_getTypedefNameForAnonDecl(this);
@ -1419,7 +1425,17 @@ namespace ClangSharp.Interop
public CXCursor GetTemplateArgument(uint index) => clangsharp.Cursor_getTemplateArgument(this, index); public CXCursor GetTemplateArgument(uint index) => clangsharp.Cursor_getTemplateArgument(this, index);
public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clang.Cursor_getTemplateArgumentKind(this, i); public CXCursor GetTemplateArgumentAsDecl(uint i) => clangsharp.Cursor_getTemplateArgumentAsDecl(this, i);
public CXCursor GetTemplateArgumentAsExpr(uint i) => clangsharp.Cursor_getTemplateArgumentAsExpr(this, i);
public long GetTemplateArgumentAsIntegral(uint i) => clangsharp.Cursor_getTemplateArgumentAsIntegral(this, i);
public CXType GetTemplateArgumentAsType(uint i) => clangsharp.Cursor_getTemplateArgumentAsType(this, i);
public CXType GetTemplateArgumentIntegralType(uint i) => clangsharp.Cursor_getTemplateArgumentIntegralType(this, i);
public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clangsharp.Cursor_getTemplateArgumentKind(this, i);
public CXSourceLocation GetTemplateArgumentLocLocation(uint i) => clangsharp.Cursor_getTemplateArgumentLocLocation(this, i); public CXSourceLocation GetTemplateArgumentLocLocation(uint i) => clangsharp.Cursor_getTemplateArgumentLocLocation(this, i);
@ -1431,6 +1447,8 @@ namespace ClangSharp.Interop
public CXCursor GetTemplateArgumentLocSourceNullPtrExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceNullPtrExpression(this, i); public CXCursor GetTemplateArgumentLocSourceNullPtrExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceNullPtrExpression(this, i);
public CXType GetTemplateArgumentNullPtrType(uint i) => clangsharp.Cursor_getTemplateArgumentNullPtrType(this, i);
public CXType GetTemplateArgumentType(uint i) => clang.Cursor_getTemplateArgumentType(this, i); public CXType GetTemplateArgumentType(uint i) => clang.Cursor_getTemplateArgumentType(this, i);
public ulong GetTemplateArgumentUnsignedValue(uint i) => clang.Cursor_getTemplateArgumentUnsignedValue(this, i); public ulong GetTemplateArgumentUnsignedValue(uint i) => clang.Cursor_getTemplateArgumentUnsignedValue(this, i);

Просмотреть файл

@ -11,26 +11,48 @@ namespace ClangSharp.Interop
{ {
public uint AddressSpace => (kind != CXTypeKind.CXType_Invalid) ? clang.getAddressSpace(this) : default; public uint AddressSpace => (kind != CXTypeKind.CXType_Invalid) ? clang.getAddressSpace(this) : default;
public CXCursor AddrSpaceExpr => clangsharp.Type_getAddrSpaceExpr(this);
public CXType AdjustedType => clangsharp.Type_getAdjustedType(this);
public long AlignOf => clang.Type_getAlignOf(this); public long AlignOf => clang.Type_getAlignOf(this);
public CXType ArrayElementType => clang.getArrayElementType(this); public CXType ArrayElementType => clang.getArrayElementType(this);
public long ArraySize => clang.getArraySize(this); public long ArraySize => clang.getArraySize(this);
public CX_AttrKind AttrKind => clangsharp.Type_getAttrKind(this);
public CXType BaseType => clangsharp.Type_getBaseType(this);
public CXType CanonicalType => clang.getCanonicalType(this); public CXType CanonicalType => clang.getCanonicalType(this);
public CXType ClassType => clang.Type_getClassType(this); public CXType ClassType => clang.Type_getClassType(this);
public CXRefQualifierKind CXXRefQualifier => clang.Type_getCXXRefQualifier(this); public CXRefQualifierKind CXXRefQualifier => clang.Type_getCXXRefQualifier(this);
public CXCursor Declaration => clang.getTypeDeclaration(this); public CXType DecayedType => clangsharp.Type_getDecayedType(this);
public CXType ElementType => clang.getElementType(this); public CXCursor Declaration => clangsharp.Type_getDeclaration(this);
public CXType DeducedType => clangsharp.Type_getDeducedType(this);
public int Depth => clangsharp.Type_getDepth(this);
public CXType ElementType => clangsharp.Type_getElementType(this);
public CXType EquivalentType => clangsharp.Type_getEquivalentType(this);
public CXCursor_ExceptionSpecificationKind ExceptionSpecificationType => (CXCursor_ExceptionSpecificationKind)clang.getExceptionSpecificationType(this); public CXCursor_ExceptionSpecificationKind ExceptionSpecificationType => (CXCursor_ExceptionSpecificationKind)clang.getExceptionSpecificationType(this);
public CXCallingConv FunctionTypeCallingConv => clang.getFunctionTypeCallingConv(this); public CXCallingConv FunctionTypeCallingConv => clang.getFunctionTypeCallingConv(this);
public int Index => clangsharp.Type_getIndex(this);
public CXType InjectedSpecializationType => clangsharp.Type_getInjectedSpecializationType(this);
public CXType InjectedTST => clangsharp.Type_getInjectedTST(this);
public bool IsCanonical => Equals(CanonicalType); public bool IsCanonical => Equals(CanonicalType);
public bool IsConstQualified => clang.isConstQualifiedType(this) != 0; public bool IsConstQualified => clang.isConstQualifiedType(this) != 0;
@ -41,13 +63,17 @@ namespace ClangSharp.Interop
public bool IsRestrictQualified => clang.isRestrictQualifiedType(this) != 0; public bool IsRestrictQualified => clang.isRestrictQualifiedType(this) != 0;
public bool IsSugared => clangsharp.Type_getIsSugared(this) != 0;
public bool IsTransparentTagTypedef => clang.Type_isTransparentTagTypedef(this) != 0; public bool IsTransparentTagTypedef => clang.Type_isTransparentTagTypedef(this) != 0;
public bool IsTypeAlias => clangsharp.Type_getIsTypeAlias(this) != 0;
public bool IsVolatileQualified => clang.isVolatileQualifiedType(this) != 0; public bool IsVolatileQualified => clang.isVolatileQualifiedType(this) != 0;
public CXString KindSpelling => clang.getTypeKindSpelling(kind); public CXString KindSpelling => clang.getTypeKindSpelling(kind);
public CXType ModifiedType => clang.Type_getModifiedType(this); public CXType ModifiedType => clangsharp.Type_getModifiedType(this);
public CXType NamedType => clang.Type_getNamedType(this); public CXType NamedType => clang.Type_getNamedType(this);
@ -65,10 +91,16 @@ namespace ClangSharp.Interop
public CXType ObjCObjectBaseType => clang.Type_getObjCObjectBaseType(this); public CXType ObjCObjectBaseType => clang.Type_getObjCObjectBaseType(this);
public CXType PointeeType => clang.getPointeeType(this); public CXType OriginalType => clangsharp.Type_getOriginalType(this);
public CXCursor OwnedTagDecl => clangsharp.Type_getOwnedTagDecl(this);
public CXType PointeeType => clangsharp.Type_getPointeeType(this);
public CXType ResultType => clang.getResultType(this); public CXType ResultType => clang.getResultType(this);
public CXCursor SizeExpr => clangsharp.Type_getSizeExpr(this);
public long SizeOf => clang.Type_getSizeOf(this); public long SizeOf => clang.Type_getSizeOf(this);
public CXString Spelling => clang.getTypeSpelling(this); public CXString Spelling => clang.getTypeSpelling(this);
@ -141,6 +173,12 @@ namespace ClangSharp.Interop
public CXString TypedefName => clang.getTypedefName(this); public CXString TypedefName => clang.getTypedefName(this);
public CXCursor UnderlyingExpr => clangsharp.Type_getUnderlyingExpr(this);
public CXType UnderlyingType => clangsharp.Type_getUnderlyingType(this);
public CXType ValueType => clangsharp.Type_getValueType(this);
internal string DebuggerDisplayString internal string DebuggerDisplayString
{ {
get get
@ -153,6 +191,8 @@ namespace ClangSharp.Interop
public static bool operator !=(CXType left, CXType right) => clang.equalTypes(left, right) == 0; public static bool operator !=(CXType left, CXType right) => clang.equalTypes(left, right) == 0;
public CXType Desugar() => clangsharp.Type_desugar(this);
public override bool Equals(object obj) => (obj is CXType other) && Equals(other); public override bool Equals(object obj) => (obj is CXType other) && Equals(other);
public bool Equals(CXType other) => this == other; public bool Equals(CXType other) => this == other;
@ -173,7 +213,19 @@ namespace ClangSharp.Interop
return clang.Type_getOffsetOf(this, marshaledS); return clang.Type_getOffsetOf(this, marshaledS);
} }
public CXType GetTemplateArgumentAsType(uint i) => clang.Type_getTemplateArgumentAsType(this, i); public CXCursor GetTemplateArgumentAsDecl(uint i) => clangsharp.Type_getTemplateArgumentAsDecl(this, i);
public CXCursor GetTemplateArgumentAsExpr(uint i) => clangsharp.Type_getTemplateArgumentAsExpr(this, i);
public long GetTemplateArgumentAsIntegral(uint i) => clangsharp.Type_getTemplateArgumentAsIntegral(this, i);
public CXType GetTemplateArgumentAsType(uint i) => clangsharp.Type_getTemplateArgumentAsType(this, i);
public CXType GetTemplateArgumentIntegralType(uint i) => clangsharp.Type_getTemplateArgumentIntegralType(this, i);
public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clangsharp.Type_getTemplateArgumentKind(this, i);
public CXType GetTemplateArgumentNullPtrType(uint i) => clangsharp.Type_getTemplateArgumentNullPtrType(this, i);
public override string ToString() => Spelling.ToString(); public override string ToString() => Spelling.ToString();

Просмотреть файл

@ -279,6 +279,10 @@ namespace ClangSharp.Interop
[return: NativeTypeName("unsigned int")] [return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsAnonymousStructOrUnion(CXCursor C); public static extern uint Cursor_getIsAnonymousStructOrUnion(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsArgumentType", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsArgumentType(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsConversionFromLambda", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsConversionFromLambda", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")] [return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsConversionFromLambda(CXCursor C); public static extern uint Cursor_getIsConversionFromLambda(CXCursor C);
@ -383,6 +387,10 @@ namespace ClangSharp.Interop
[return: NativeTypeName("unsigned int")] [return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsTypeConcept(CXCursor C); public static extern uint Cursor_getIsTypeConcept(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTypeOperand", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsTypeOperand(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUnavailable", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUnavailable", ExactSpelling = true)]
[return: NativeTypeName("unsigned int")] [return: NativeTypeName("unsigned int")]
public static extern uint Cursor_getIsUnavailable(CXCursor C); public static extern uint Cursor_getIsUnavailable(CXCursor C);
@ -512,6 +520,24 @@ namespace ClangSharp.Interop
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgument", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgument", ExactSpelling = true)]
public static extern CXCursor Cursor_getTemplateArgument(CXCursor C, [NativeTypeName("unsigned int")] uint i); public static extern CXCursor Cursor_getTemplateArgument(CXCursor C, [NativeTypeName("unsigned int")] uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsDecl", ExactSpelling = true)]
public static extern CXCursor Cursor_getTemplateArgumentAsDecl(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsExpr", ExactSpelling = true)]
public static extern CXCursor Cursor_getTemplateArgumentAsExpr(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsIntegral", ExactSpelling = true)]
public static extern long Cursor_getTemplateArgumentAsIntegral(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsType", ExactSpelling = true)]
public static extern CXType Cursor_getTemplateArgumentAsType(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentIntegralType", ExactSpelling = true)]
public static extern CXType Cursor_getTemplateArgumentIntegralType(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentKind", ExactSpelling = true)]
public static extern CXTemplateArgumentKind Cursor_getTemplateArgumentKind(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocLocation", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocLocation", ExactSpelling = true)]
public static extern CXSourceLocation Cursor_getTemplateArgumentLocLocation(CXCursor C, [NativeTypeName("unsigned int")] uint i); public static extern CXSourceLocation Cursor_getTemplateArgumentLocLocation(CXCursor C, [NativeTypeName("unsigned int")] uint i);
@ -527,6 +553,9 @@ namespace ClangSharp.Interop
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression", ExactSpelling = true)]
public static extern CXCursor Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i); public static extern CXCursor Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentNullPtrType", ExactSpelling = true)]
public static extern CXType Cursor_getTemplateArgumentNullPtrType(CXCursor C, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplatedDecl", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplatedDecl", ExactSpelling = true)]
public static extern CXCursor Cursor_getTemplatedDecl(CXCursor C); public static extern CXCursor Cursor_getTemplatedDecl(CXCursor C);
@ -557,6 +586,9 @@ namespace ClangSharp.Interop
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTypedefNameForAnonDecl", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTypedefNameForAnonDecl", ExactSpelling = true)]
public static extern CXCursor Cursor_getTypedefNameForAnonDecl(CXCursor C); public static extern CXCursor Cursor_getTypedefNameForAnonDecl(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTypeOperand", ExactSpelling = true)]
public static extern CXType Cursor_getTypeOperand(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getUnaryExprOrTypeTraitKind", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getUnaryExprOrTypeTraitKind", ExactSpelling = true)]
public static extern CX_UnaryExprOrTypeTrait Cursor_getUnaryExprOrTypeTraitKind(CXCursor C); public static extern CX_UnaryExprOrTypeTrait Cursor_getUnaryExprOrTypeTraitKind(CXCursor C);
@ -575,7 +607,100 @@ namespace ClangSharp.Interop
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getUsedContext", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getUsedContext", ExactSpelling = true)]
public static extern CXCursor Cursor_getUsedContext(CXCursor C); public static extern CXCursor Cursor_getUsedContext(CXCursor C);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_desugar", ExactSpelling = true)]
public static extern CXType Type_desugar(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getAddrSpaceExpr", ExactSpelling = true)]
public static extern CXCursor Type_getAddrSpaceExpr(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getAdjustedType", ExactSpelling = true)]
public static extern CXType Type_getAdjustedType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getAdjustedType", ExactSpelling = true)]
public static extern CX_AttrKind Type_getAttrKind(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getBaseType", ExactSpelling = true)]
public static extern CXType Type_getBaseType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getDecayedType", ExactSpelling = true)]
public static extern CXType Type_getDecayedType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getDeclaration", ExactSpelling = true)]
public static extern CXCursor Type_getDeclaration(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getDeducedType", ExactSpelling = true)]
public static extern CXType Type_getDeducedType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getDepth", ExactSpelling = true)]
public static extern int Type_getDepth(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getElementType", ExactSpelling = true)]
public static extern CXType Type_getElementType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getEquivalentType", ExactSpelling = true)]
public static extern CXType Type_getEquivalentType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getIndex", ExactSpelling = true)]
public static extern int Type_getIndex(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getInjectedSpecializationType", ExactSpelling = true)]
public static extern CXType Type_getInjectedSpecializationType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getInjectedTST", ExactSpelling = true)]
public static extern CXType Type_getInjectedTST(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getIsSugared", ExactSpelling = true)]
public static extern uint Type_getIsSugared(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getIsTypeAlias", ExactSpelling = true)]
public static extern uint Type_getIsTypeAlias(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getModifiedType", ExactSpelling = true)]
public static extern CXType Type_getModifiedType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOriginalType", ExactSpelling = true)]
public static extern CXType Type_getOriginalType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOwnedTagDecl", ExactSpelling = true)]
public static extern CXCursor Type_getOwnedTagDecl(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getPointeeType", ExactSpelling = true)]
public static extern CXType Type_getPointeeType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSizeExpr", ExactSpelling = true)]
public static extern CXCursor Type_getSizeExpr(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsDecl", ExactSpelling = true)]
public static extern CXCursor Type_getTemplateArgumentAsDecl(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsExpr", ExactSpelling = true)]
public static extern CXCursor Type_getTemplateArgumentAsExpr(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsIntegral", ExactSpelling = true)]
public static extern long Type_getTemplateArgumentAsIntegral(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsType", ExactSpelling = true)]
public static extern CXType Type_getTemplateArgumentAsType(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentIntegralType", ExactSpelling = true)]
public static extern CXType Type_getTemplateArgumentIntegralType(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentKind", ExactSpelling = true)]
public static extern CXTemplateArgumentKind Type_getTemplateArgumentKind(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentNullPtrType", ExactSpelling = true)]
public static extern CXType Type_getTemplateArgumentNullPtrType(CXType CT, uint i);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTypeClass", ExactSpelling = true)] [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTypeClass", ExactSpelling = true)]
public static extern CX_TypeClass Type_getTypeClass(CXType CT); public static extern CX_TypeClass Type_getTypeClass(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getUnderlyingExpr", ExactSpelling = true)]
public static extern CXCursor Type_getUnderlyingExpr(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getUnderlyingType", ExactSpelling = true)]
public static extern CXType Type_getUnderlyingType(CXType CT);
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getValueType", ExactSpelling = true)]
public static extern CXType Type_getValueType(CXType CT);
} }
} }

Просмотреть файл

@ -8,22 +8,50 @@ namespace ClangSharp
public sealed class TemplateArgument public sealed class TemplateArgument
{ {
private readonly Decl _parentDecl; private readonly Decl _parentDecl;
private readonly Type _parentType;
private readonly uint _index; private readonly uint _index;
private readonly Lazy<ValueDecl> _asDecl;
private readonly Lazy<Expr> _asExpr;
private readonly Lazy<Type> _asType; private readonly Lazy<Type> _asType;
private readonly Lazy<Type> _integralType;
private readonly Lazy<Type> _nullPtrType;
internal TemplateArgument(Decl parentDecl, uint index) internal TemplateArgument(Decl parentDecl, uint index)
{ {
_parentDecl = parentDecl; _parentDecl = parentDecl;
_index = index; _index = index;
_asType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentDecl.Handle.GetTemplateArgumentType(_index))); _asDecl = new Lazy<ValueDecl>(() => _parentDecl.TranslationUnit.GetOrCreate<ValueDecl>(_parentDecl.Handle.GetTemplateArgumentAsDecl(_index)));
_asExpr = new Lazy<Expr>(() => _parentDecl.TranslationUnit.GetOrCreate<Expr>(_parentDecl.Handle.GetTemplateArgumentAsExpr(_index)));
_asType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentDecl.Handle.GetTemplateArgumentAsType(_index)));
_integralType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentDecl.Handle.GetTemplateArgumentIntegralType(_index)));
_nullPtrType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentDecl.Handle.GetTemplateArgumentNullPtrType(_index)));
} }
public long AsIntegral => _parentDecl.Handle.GetTemplateArgumentValue(_index); internal TemplateArgument(Type parentType, uint index)
{
_parentType = parentType;
_index = index;
_asDecl = new Lazy<ValueDecl>(() => _parentDecl.TranslationUnit.GetOrCreate<ValueDecl>(_parentType.Handle.GetTemplateArgumentAsDecl(_index)));
_asExpr = new Lazy<Expr>(() => _parentDecl.TranslationUnit.GetOrCreate<Expr>(_parentType.Handle.GetTemplateArgumentAsExpr(_index)));
_asType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentType.Handle.GetTemplateArgumentAsType(_index)));
_integralType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentType.Handle.GetTemplateArgumentIntegralType(_index)));
_nullPtrType = new Lazy<Type>(() => _parentDecl.TranslationUnit.GetOrCreate<Type>(_parentType.Handle.GetTemplateArgumentNullPtrType(_index)));
}
public ValueDecl AsDecl => _asDecl.Value;
public Expr AsExpr => _asExpr.Value;
public long AsIntegral => (_parentDecl != null) ? _parentDecl.Handle.GetTemplateArgumentAsIntegral(_index) : _parentType.Handle.GetTemplateArgumentAsIntegral(_index);
public Type AsType => _asType.Value; public Type AsType => _asType.Value;
public Type IntegralType => _integralType.Value;
public bool IsNull => Kind == CXTemplateArgumentKind.CXTemplateArgumentKind_Null; public bool IsNull => Kind == CXTemplateArgumentKind.CXTemplateArgumentKind_Null;
public CXTemplateArgumentKind Kind => _parentDecl.Handle.GetTemplateArgumentKind(_index); public CXTemplateArgumentKind Kind => (_parentDecl != null) ? _parentDecl.Handle.GetTemplateArgumentKind(_index) : _parentType.Handle.GetTemplateArgumentKind(_index);
public Type NullPtrType => _nullPtrType.Value;
} }
} }

Просмотреть файл

@ -1,17 +1,33 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public class AdjustedType : Type public class AdjustedType : Type
{ {
private readonly Lazy<Type> _adjustedType;
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _originalType;
internal AdjustedType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Adjusted) internal AdjustedType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Adjusted)
{ {
} }
private protected AdjustedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) private protected AdjustedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
{ {
_adjustedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.AdjustedType));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_originalType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.OriginalType));
} }
public Type GetAdjustedType => _adjustedType.Value;
public bool IsSugared => Handle.IsSugared;
public Type OriginalType => _originalType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class AtomicType : Type public sealed class AtomicType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _valueType;
internal AtomicType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Atomic) internal AtomicType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Atomic)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_valueType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ValueType));
} }
public bool IsSugared => Handle.IsSugared;
public Type ValueType => _valueType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -7,13 +7,25 @@ namespace ClangSharp
{ {
public sealed class AttributedType : Type public sealed class AttributedType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _equivalentType;
private readonly Lazy<Type> _modifiedType; private readonly Lazy<Type> _modifiedType;
internal AttributedType(CXType handle) : base(handle, CXTypeKind.CXType_Attributed, CX_TypeClass.CX_TypeClass_Attributed) internal AttributedType(CXType handle) : base(handle, CXTypeKind.CXType_Attributed, CX_TypeClass.CX_TypeClass_Attributed)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_equivalentType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.EquivalentType));
_modifiedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ModifiedType)); _modifiedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ModifiedType));
} }
public CX_AttrKind AttrKind => Handle.AttrKind;
public Type EquivalentType => _equivalentType.Value;
public Type ModifiedType => _modifiedType.Value; public Type ModifiedType => _modifiedType.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,31 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using System.Collections.Generic;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class AutoType : DeducedType public sealed class AutoType : DeducedType
{ {
private readonly Lazy<IReadOnlyList<TemplateArgument>> _templateArgs;
internal AutoType(CXType handle) : base(handle, CXTypeKind.CXType_Auto, CX_TypeClass.CX_TypeClass_Auto) internal AutoType(CXType handle) : base(handle, CXTypeKind.CXType_Auto, CX_TypeClass.CX_TypeClass_Auto)
{ {
_templateArgs = new Lazy<IReadOnlyList<TemplateArgument>>(() => {
var templateArgCount = Handle.NumTemplateArguments;
var templateArgs = new List<TemplateArgument>(templateArgCount);
for (int i = 0; i < templateArgCount; i++)
{
var templateArg = new TemplateArgument(this, unchecked((uint)i));
templateArgs.Add(templateArg);
}
return templateArgs;
});
} }
public IReadOnlyList<TemplateArgument> Args => _templateArgs.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class BlockPointerType : Type public sealed class BlockPointerType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _pointeeType;
internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer) internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType));
} }
public bool IsSugared => Handle.IsSugared;
public Type PointeeType => _pointeeType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class BuiltinType : Type public sealed class BuiltinType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin) internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class ComplexType : Type public sealed class ComplexType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _elementType;
internal ComplexType(CXType handle) : base(handle, CXTypeKind.CXType_Complex, CX_TypeClass.CX_TypeClass_Complex) internal ComplexType(CXType handle) : base(handle, CXTypeKind.CXType_Complex, CX_TypeClass.CX_TypeClass_Complex)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_elementType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ElementType));
} }
public Type ElementType => _elementType.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,15 +1,27 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class ConstantArrayType : ArrayType public sealed class ConstantArrayType : ArrayType
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Expr> _sizeExpr;
internal ConstantArrayType(CXType handle) : base(handle, CXTypeKind.CXType_ConstantArray, CX_TypeClass.CX_TypeClass_ConstantArray) internal ConstantArrayType(CXType handle) : base(handle, CXTypeKind.CXType_ConstantArray, CX_TypeClass.CX_TypeClass_ConstantArray)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_sizeExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.SizeExpr));
} }
public bool IsSugared => Handle.IsSugared;
public long Size => Handle.ArraySize; public long Size => Handle.ArraySize;
public Expr SizeExpr => _sizeExpr.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,23 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DecayedType : AdjustedType public sealed class DecayedType : AdjustedType
{ {
private readonly Lazy<Type> _decayedType;
private readonly Lazy<Type> _pointeeType;
internal DecayedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decayed) internal DecayedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decayed)
{ {
_decayedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.DecayedType));
_pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType));
} }
public Type GetDecayedType => _decayedType.Value;
public Type PointeeType => _pointeeType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,29 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DecltypeType : Type public sealed class DecltypeType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Expr> _underlyingExpr;
private readonly Lazy<Type> _underlyingType;
internal DecltypeType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decltype) internal DecltypeType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decltype)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_underlyingExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.UnderlyingExpr));
_underlyingType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.UnderlyingType));
} }
public bool IsSugared => Handle.IsSugared;
public Expr UnderlyingExpr => _underlyingExpr.Value;
public Type UnderlyingType => _underlyingType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public class DeducedType : Type public class DeducedType : Type
{ {
private readonly Lazy<Type> _deducedType;
private readonly Lazy<Type> _desugaredType;
private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
{ {
_deducedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.DeducedType));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public Type GetDeducedType => _deducedType.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,29 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentAddressSpaceType : Type public sealed class DependentAddressSpaceType : Type
{ {
private readonly Lazy<Expr> _addrSpaceExpr;
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _pointeeType;
internal DependentAddressSpaceType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentAddressSpace) internal DependentAddressSpaceType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentAddressSpace)
{ {
_addrSpaceExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.AddrSpaceExpr));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType));
} }
public Expr AddrSpaceExpr => _addrSpaceExpr.Value;
public bool IsSugared => Handle.IsSugared;
public Type PointeeType => _pointeeType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentNameType : TypeWithKeyword public sealed class DependentNameType : TypeWithKeyword
{ {
private readonly Lazy<Type> _desugaredType;
internal DependentNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentName) internal DependentNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentName)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentSizedArrayType : ArrayType public sealed class DependentSizedArrayType : ArrayType
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Expr> _sizeExpr;
internal DependentSizedArrayType(CXType handle) : base(handle, CXTypeKind.CXType_DependentSizedArray, CX_TypeClass.CX_TypeClass_DependentSizedArray) internal DependentSizedArrayType(CXType handle) : base(handle, CXTypeKind.CXType_DependentSizedArray, CX_TypeClass.CX_TypeClass_DependentSizedArray)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_sizeExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.SizeExpr));
} }
public bool IsSugared => Handle.IsSugared;
public Expr SizeExpr => _sizeExpr.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,31 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentSizedExtVectorType : Type public sealed class DependentSizedExtVectorType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _elementType;
private readonly Lazy<Expr> _sizeExpr;
internal DependentSizedExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentSizedExtVector) internal DependentSizedExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentSizedExtVector)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_elementType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ElementType));
_sizeExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.SizeExpr));
} }
public Type ElementType => _elementType.Value;
public bool IsSugared => Handle.IsSugared;
public long Size => Handle.ArraySize;
public Expr SizeExpr => _sizeExpr.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,37 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using System.Collections.Generic;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentTemplateSpecializationType : TypeWithKeyword public sealed class DependentTemplateSpecializationType : TypeWithKeyword
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<IReadOnlyList<TemplateArgument>> _templateArgs;
internal DependentTemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentTemplateSpecialization) internal DependentTemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentTemplateSpecialization)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_templateArgs = new Lazy<IReadOnlyList<TemplateArgument>>(() => {
var templateArgCount = Handle.NumTemplateArguments;
var templateArgs = new List<TemplateArgument>(templateArgCount);
for (int i = 0; i < templateArgCount; i++)
{
var templateArg = new TemplateArgument(this, unchecked((uint)i));
templateArgs.Add(templateArg);
}
return templateArgs;
});
} }
public IReadOnlyList<TemplateArgument> Args => _templateArgs.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,31 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class DependentVectorType : Type public sealed class DependentVectorType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _elementType;
private readonly Lazy<Expr> _sizeExpr;
internal DependentVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentVector) internal DependentVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentVector)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_elementType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ElementType));
_sizeExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.SizeExpr));
} }
public Type ElementType => _elementType.Value;
public bool IsSugared => Handle.IsSugared;
public long Size => Handle.ArraySize;
public Expr SizeExpr => _sizeExpr.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -7,13 +7,23 @@ namespace ClangSharp
{ {
public sealed class ElaboratedType : TypeWithKeyword public sealed class ElaboratedType : TypeWithKeyword
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _namedType; private readonly Lazy<Type> _namedType;
private readonly Lazy<TagDecl> _ownedTagDecl;
internal ElaboratedType(CXType handle) : base(handle, CXTypeKind.CXType_Elaborated, CX_TypeClass.CX_TypeClass_Elaborated) internal ElaboratedType(CXType handle) : base(handle, CXTypeKind.CXType_Elaborated, CX_TypeClass.CX_TypeClass_Elaborated)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_namedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.NamedType)); _namedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.NamedType));
_ownedTagDecl = new Lazy<TagDecl>(() => TranslationUnit.GetOrCreate<TagDecl>(Handle.OwnedTagDecl));
} }
public bool IsSugared => Handle.IsSugared;
public Type NamedType => _namedType.Value; public Type NamedType => _namedType.Value;
public TagDecl OwnedTagDecl => _ownedTagDecl.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,15 +1,23 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class EnumType : TagType public sealed class EnumType : TagType
{ {
private readonly Lazy<Type> _desugaredType;
internal EnumType(CXType handle) : base(handle, CXTypeKind.CXType_Enum, CX_TypeClass.CX_TypeClass_Enum) internal EnumType(CXType handle) : base(handle, CXTypeKind.CXType_Enum, CX_TypeClass.CX_TypeClass_Enum)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public new EnumDecl Decl => (EnumDecl)base.Decl; public new EnumDecl Decl => (EnumDecl)base.Decl;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class ExtVectorType : Type public sealed class ExtVectorType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal ExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_ExtVector, CX_TypeClass.CX_TypeClass_ExtVector) internal ExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_ExtVector, CX_TypeClass.CX_TypeClass_ExtVector)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class FunctionNoProtoType : FunctionType public sealed class FunctionNoProtoType : FunctionType
{ {
private readonly Lazy<Type> _desugaredType;
internal FunctionNoProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionNoProto, CX_TypeClass.CX_TypeClass_FunctionNoProto) internal FunctionNoProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionNoProto, CX_TypeClass.CX_TypeClass_FunctionNoProto)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,5 +1,6 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using ClangSharp.Interop; using ClangSharp.Interop;
@ -7,37 +8,38 @@ namespace ClangSharp
{ {
public sealed class FunctionProtoType : FunctionType public sealed class FunctionProtoType : FunctionType
{ {
private Type[] _paramTypes; private readonly Lazy<Type> _desugaredType;
private readonly Lazy<IReadOnlyList<Type>> _paramTypes;
internal FunctionProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionProto, CX_TypeClass.CX_TypeClass_FunctionProto) internal FunctionProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionProto, CX_TypeClass.CX_TypeClass_FunctionProto)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_paramTypes = new Lazy<IReadOnlyList<Type>>(() => {
var paramTypeCount = Handle.NumArgTypes;
var paramTypes = new List<Type>(paramTypeCount);
for (int i = 0; i < paramTypeCount; i++)
{
var paramType = TranslationUnit.GetOrCreate<Type>(Handle.GetArgType(unchecked((uint)i)));
paramTypes.Add(paramType);
}
return paramTypes;
});
} }
public CXCursor_ExceptionSpecificationKind ExceptionSpecType => Handle.ExceptionSpecificationType; public CXCursor_ExceptionSpecificationKind ExceptionSpecType => Handle.ExceptionSpecificationType;
public bool IsSugared => Handle.IsSugared;
public bool IsVariadic => Handle.IsFunctionTypeVariadic; public bool IsVariadic => Handle.IsFunctionTypeVariadic;
public uint NumParams => (uint)Handle.NumArgTypes; public uint NumParams => (uint)Handle.NumArgTypes;
public IReadOnlyList<Type> ParamTypes public IReadOnlyList<Type> ParamTypes => _paramTypes.Value;
{
get
{
if (_paramTypes is null)
{
uint numParams = NumParams;
_paramTypes = new Type[numParams];
for (var index = 0u; index < numParams; index++)
{
var paramType = Handle.GetArgType(index);
_paramTypes[index] = TranslationUnit.GetOrCreate<Type>(paramType);
}
}
return _paramTypes;
}
}
public CXRefQualifierKind RefQualifier => Handle.CXXRefQualifier; public CXRefQualifierKind RefQualifier => Handle.CXXRefQualifier;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class IncompleteArrayType : ArrayType public sealed class IncompleteArrayType : ArrayType
{ {
private readonly Lazy<Type> _desugaredType;
internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray) internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,33 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class InjectedClassNameType : Type public sealed class InjectedClassNameType : Type
{ {
private readonly Lazy<CXXRecordDecl> _decl;
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _injectedSpecializationType;
private readonly Lazy<TemplateSpecializationType> _injectedTST;
internal InjectedClassNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_InjectedClassName) internal InjectedClassNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_InjectedClassName)
{ {
_decl = new Lazy<CXXRecordDecl>(() => TranslationUnit.GetOrCreate<CXXRecordDecl>(handle.Declaration));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_injectedSpecializationType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.InjectedSpecializationType));
_injectedTST = new Lazy<TemplateSpecializationType>(() => TranslationUnit.GetOrCreate<TemplateSpecializationType>(Handle.InjectedTST));
} }
public CXXRecordDecl Decl => _decl.Value;
public Type InjectedSpecializationType => _injectedSpecializationType.Value;
public TemplateSpecializationType InjectedTST => _injectedTST.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class LValueReferenceType : ReferenceType public sealed class LValueReferenceType : ReferenceType
{ {
private readonly Lazy<Type> _desugaredType;
internal LValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_LValueReference, CX_TypeClass.CX_TypeClass_LValueReference) internal LValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_LValueReference, CX_TypeClass.CX_TypeClass_LValueReference)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,29 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class MacroQualifiedType : Type public sealed class MacroQualifiedType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _modifiedType;
private readonly Lazy<Type> _underlyingType;
internal MacroQualifiedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_MacroQualified) internal MacroQualifiedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_MacroQualified)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_modifiedType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ModifiedType));
_underlyingType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.UnderlyingType));
} }
public bool IsSugared => Handle.IsSugared;
public Type ModifiedType => _modifiedType.Value;
public Type UnderlyingType => _underlyingType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class MemberPointerType : Type public sealed class MemberPointerType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _pointeeType;
internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer) internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(handle.PointeeType));
} }
public bool IsSugared => Handle.IsSugared;
public Type PointeeType => _pointeeType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,21 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class PackExpansionType : Type public sealed class PackExpansionType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal PackExpansionType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_PackExpansion) internal PackExpansionType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_PackExpansion)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,23 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class ParenType : Type public sealed class ParenType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal ParenType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Paren) internal ParenType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Paren)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public Type InnerType => _desugaredType.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class PipeType : Type public sealed class PipeType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _elementType;
internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe) internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_elementType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ElementType));
} }
public Type ElementType => _elementType.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -7,13 +7,19 @@ namespace ClangSharp
{ {
public sealed class PointerType : Type public sealed class PointerType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _pointeeType; private readonly Lazy<Type> _pointeeType;
internal PointerType(CXType handle) : base(handle, CXTypeKind.CXType_Pointer, CX_TypeClass.CX_TypeClass_Pointer) internal PointerType(CXType handle) : base(handle, CXTypeKind.CXType_Pointer, CX_TypeClass.CX_TypeClass_Pointer)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType)); _pointeeType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.PointeeType));
} }
public bool IsSugared => Handle.IsSugared;
public Type PointeeType => _pointeeType.Value; public Type PointeeType => _pointeeType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,20 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class RValueReferenceType : ReferenceType public sealed class RValueReferenceType : ReferenceType
{ {
private readonly Lazy<Type> _desugaredType;
internal RValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_RValueReference, CX_TypeClass.CX_TypeClass_RValueReference) internal RValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_RValueReference, CX_TypeClass.CX_TypeClass_RValueReference)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,15 +1,23 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class RecordType : TagType public sealed class RecordType : TagType
{ {
private readonly Lazy<Type> _desugaredType;
internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record, CX_TypeClass.CX_TypeClass_Record) internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record, CX_TypeClass.CX_TypeClass_Record)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public new RecordDecl Decl => (RecordDecl)base.Decl; public new RecordDecl Decl => (RecordDecl)base.Decl;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,20 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class SubstTemplateTypeParmPackType : Type public sealed class SubstTemplateTypeParmPackType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal SubstTemplateTypeParmPackType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParmPack) internal SubstTemplateTypeParmPackType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParmPack)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,23 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class SubstTemplateTypeParmType : Type public sealed class SubstTemplateTypeParmType : Type
{ {
private readonly Lazy<Type> _desugaredType;
internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParm) internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParm)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type ReplacementType => _desugaredType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,41 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using System.Collections.Generic;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class TemplateSpecializationType : Type public sealed class TemplateSpecializationType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<IReadOnlyList<TemplateArgument>> _templateArgs;
internal TemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateSpecialization) internal TemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateSpecialization)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_templateArgs = new Lazy<IReadOnlyList<TemplateArgument>>(() => {
var templateArgCount = Handle.NumTemplateArguments;
var templateArgs = new List<TemplateArgument>(templateArgCount);
for (int i = 0; i < templateArgCount; i++)
{
var templateArg = new TemplateArgument(this, unchecked((uint)i));
templateArgs.Add(templateArg);
}
return templateArgs;
});
} }
public Type AliasedType => IsTypeAlias ? _desugaredType.Value : null;
public IReadOnlyList<TemplateArgument> Args => _templateArgs.Value;
public bool IsSugared => Handle.IsSugared;
public bool IsTypeAlias => Handle.IsTypeAlias;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,29 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class TemplateTypeParmType : Type public sealed class TemplateTypeParmType : Type
{ {
private readonly Lazy<TemplateTypeParmDecl> _decl;
private readonly Lazy<Type> _desugaredType;
internal TemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateTypeParm) internal TemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateTypeParm)
{ {
_decl = new Lazy<TemplateTypeParmDecl>(() => TranslationUnit.GetOrCreate<TemplateTypeParmDecl>(Handle.Declaration));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public TemplateTypeParmDecl Decl => _decl.Value;
public uint Depth => unchecked((uint)Handle.Depth);
public uint Index => unchecked((uint)Handle.Index);
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class TypeOfExprType : Type public sealed class TypeOfExprType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Expr> _underlyingExpr;
internal TypeOfExprType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOfExpr) internal TypeOfExprType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOfExpr)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_underlyingExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(handle.UnderlyingExpr));
} }
public bool IsSugared => Handle.IsSugared;
public Expr UnderlyingExpr => _underlyingExpr.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class TypeOfType : Type public sealed class TypeOfType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _underlyingType;
internal TypeOfType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOf) internal TypeOfType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOf)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_underlyingType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.UnderlyingType));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
public Type UnderlyingType => _underlyingType.Value;
} }
} }

Просмотреть файл

@ -8,12 +8,18 @@ namespace ClangSharp
public sealed class TypedefType : Type public sealed class TypedefType : Type
{ {
private readonly Lazy<TypedefNameDecl> _decl; private readonly Lazy<TypedefNameDecl> _decl;
private readonly Lazy<Type> _desugaredType;
internal TypedefType(CXType handle) : base(handle, CXTypeKind.CXType_Typedef, CX_TypeClass.CX_TypeClass_Typedef) internal TypedefType(CXType handle) : base(handle, CXTypeKind.CXType_Typedef, CX_TypeClass.CX_TypeClass_Typedef)
{ {
_decl = new Lazy<TypedefNameDecl>(() => TranslationUnit.GetOrCreate<TypedefNameDecl>(Handle.Declaration)); _decl = new Lazy<TypedefNameDecl>(() => TranslationUnit.GetOrCreate<TypedefNameDecl>(Handle.Declaration));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
public TypedefNameDecl Decl => _decl.Value; public TypedefNameDecl Decl => _decl.Value;
} }
} }

Просмотреть файл

@ -1,17 +1,33 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public class UnaryTransformType : Type public class UnaryTransformType : Type
{ {
private readonly Lazy<Type> _baseType;
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _underlyingType;
internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform) internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform)
{ {
} }
private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
{ {
_baseType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.BaseType));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_underlyingType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.UnderlyingType));
} }
public Type BaseType => _baseType.Value;
public bool IsSugared => Handle.IsSugared;
public Type UnderlyingType => _underlyingType.Value;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class UnresolvedUsingType : Type public sealed class UnresolvedUsingType : Type
{ {
private readonly Lazy<UnresolvedUsingTypenameDecl> _decl;
private readonly Lazy<Type> _desugaredType;
internal UnresolvedUsingType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnresolvedUsing) internal UnresolvedUsingType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnresolvedUsing)
{ {
_decl = new Lazy<UnresolvedUsingTypenameDecl>(() => TranslationUnit.GetOrCreate<UnresolvedUsingTypenameDecl>(Handle.Declaration));
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
} }
public UnresolvedUsingTypenameDecl Decl => _decl.Value;
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -1,13 +1,25 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public sealed class VariableArrayType : ArrayType public sealed class VariableArrayType : ArrayType
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Expr> _sizeExpr;
internal VariableArrayType(CXType handle) : base(handle, CXTypeKind.CXType_VariableArray, CX_TypeClass.CX_TypeClass_VariableArray) internal VariableArrayType(CXType handle) : base(handle, CXTypeKind.CXType_VariableArray, CX_TypeClass.CX_TypeClass_VariableArray)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_sizeExpr = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(handle.SizeExpr));
} }
public bool IsSugared => Handle.IsSugared;
public Type Desugar() => _desugaredType.Value;
public Expr SizeExpr => _sizeExpr.Value;
} }
} }

Просмотреть файл

@ -1,17 +1,31 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.
using System;
using ClangSharp.Interop; using ClangSharp.Interop;
namespace ClangSharp namespace ClangSharp
{ {
public class VectorType : Type public class VectorType : Type
{ {
private readonly Lazy<Type> _desugaredType;
private readonly Lazy<Type> _elementType;
internal VectorType(CXType handle) : base(handle, CXTypeKind.CXType_Vector, CX_TypeClass.CX_TypeClass_Vector) internal VectorType(CXType handle) : base(handle, CXTypeKind.CXType_Vector, CX_TypeClass.CX_TypeClass_Vector)
{ {
} }
private protected VectorType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) private protected VectorType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass)
{ {
_desugaredType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.Desugar()));
_elementType = new Lazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.ElementType));
} }
public Type ElementType => _elementType.Value;
public bool IsSugared => Handle.IsSugared;
public long NumElements => Handle.NumElements;
public Type Desugar() => _desugaredType.Value;
} }
} }

Просмотреть файл

@ -3,9 +3,12 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<PackAsTool>true</PackAsTool> <PackAsTool>true</PackAsTool>
<RuntimeIdentifier></RuntimeIdentifier> <RuntimeIdentifier></RuntimeIdentifier>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

Просмотреть файл

@ -12,6 +12,11 @@
"GenerateLLVM": { "GenerateLLVM": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "\"@$(MSBuildProjectDirectory)/Properties/GenerateLLVM.rsp\" --file-directory \"$(LLVMIncludePath)\" --include-directory \"$(LLVMIncludePath)\" --libraryPath $(LibLLVMName)" "commandLineArgs": "\"@$(MSBuildProjectDirectory)/Properties/GenerateLLVM.rsp\" --file-directory \"$(LLVMIncludePath)\" --include-directory \"$(LLVMIncludePath)\" --libraryPath $(LibLLVMName)"
},
"GenerateTerraFX": {
"commandName": "Project",
"commandLineArgs": "@generate.rsp",
"workingDirectory": "C:\\Repos\\terrafx.interop.windows\\generation\\shared\\dxgi"
} }
} }
} }

Просмотреть файл

@ -13,6 +13,10 @@ QualType GetQualType(CXType CT) {
return QualType::getFromOpaquePtr(CT.data[0]); return QualType::getFromOpaquePtr(CT.data[0]);
} }
CXTranslationUnit GetTypeTU(CXType CT) {
return static_cast<CXTranslationUnit>(CT.data[1]);
}
namespace clang::cxtype { namespace clang::cxtype {
static CXTypeKind GetBuiltinTypeKind(const BuiltinType* BT) { static CXTypeKind GetBuiltinTypeKind(const BuiltinType* BT) {
#define BTCASE(K) case BuiltinType::K: return CXType_##K #define BTCASE(K) case BuiltinType::K: return CXType_##K

Просмотреть файл

@ -10,6 +10,7 @@
#include <clang/AST/Type.h> #include <clang/AST/Type.h>
clang::QualType GetQualType(CXType CT); clang::QualType GetQualType(CXType CT);
CXTranslationUnit GetTypeTU(CXType CT);
namespace clang::cxtype { namespace clang::cxtype {
CXType MakeCXType(QualType T, CXTranslationUnit TU); CXType MakeCXType(QualType T, CXTranslationUnit TU);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -275,6 +275,8 @@ CLANGSHARP_LINKAGE int64_t clangsharp_Cursor_getIntegerLiteralValue(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsAnonymousStructOrUnion(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsAnonymousStructOrUnion(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsArgumentType(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsConversionFromLambda(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsConversionFromLambda(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDefined(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDefined(CXCursor C);
@ -327,6 +329,8 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTransparentTag(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeOperand(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnavailable(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnavailable(CXCursor C);
CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C);
@ -409,6 +413,16 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTargetUnionField(CXCursor C);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentAsDecl(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentAsExpr(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentAsType(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentIntegralType(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXTemplateArgumentKind clangsharp_Cursor_getTemplateArgumentKind(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXSourceLocation clangsharp_Cursor_getTemplateArgumentLocLocation(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXSourceLocation clangsharp_Cursor_getTemplateArgumentLocLocation(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceDeclExpression(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceDeclExpression(CXCursor C, unsigned i);
@ -419,6 +433,8 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceIntegr
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentNullPtrType(CXCursor C, unsigned i);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplatedDecl(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplatedDecl(CXCursor C);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateInstantiationPattern(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateInstantiationPattern(CXCursor C);
@ -439,6 +455,8 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTrueExpr(CXCursor C);
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTypedefNameForAnonDecl(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTypedefNameForAnonDecl(CXCursor C);
CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTypeOperand(CXCursor C);
CLANGSHARP_LINKAGE CX_UnaryExprOrTypeTrait clangsharp_Cursor_getUnaryExprOrTypeTraitKind(CXCursor C); CLANGSHARP_LINKAGE CX_UnaryExprOrTypeTrait clangsharp_Cursor_getUnaryExprOrTypeTraitKind(CXCursor C);
CLANGSHARP_LINKAGE CX_UnaryOperatorKind clangsharp_Cursor_getUnaryOpcode(CXCursor C); CLANGSHARP_LINKAGE CX_UnaryOperatorKind clangsharp_Cursor_getUnaryOpcode(CXCursor C);
@ -451,6 +469,66 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getUninstantiatedDefaultArg(CXCurs
CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getUsedContext(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getUsedContext(CXCursor C);
CLANGSHARP_LINKAGE CXType clangsharp_Type_desugar(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getAddrSpaceExpr(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getAdjustedType(CXType CT);
CLANGSHARP_LINKAGE CX_AttrKind clangsharp_Type_getAttrKind(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getBaseType(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getDecayedType(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getDeclaration(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getDeducedType(CXType CT);
CLANGSHARP_LINKAGE int clangsharp_Type_getDepth(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getElementType(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getEquivalentType(CXType CT);
CLANGSHARP_LINKAGE int clangsharp_Type_getIndex(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getInjectedSpecializationType(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getInjectedTST(CXType CT);
CLANGSHARP_LINKAGE unsigned clangsharp_Type_getIsSugared(CXType CT);
CLANGSHARP_LINKAGE unsigned clangsharp_Type_getIsTypeAlias(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getModifiedType(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getOriginalType(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getPointeeType(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSizeExpr(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getTemplateArgumentAsDecl(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getTemplateArgumentAsExpr(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentAsType(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentIntegralType(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CXTemplateArgumentKind clangsharp_Type_getTemplateArgumentKind(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentNullPtrType(CXType CT, unsigned i);
CLANGSHARP_LINKAGE CX_TypeClass clangsharp_Type_getTypeClass(CXType CT); CLANGSHARP_LINKAGE CX_TypeClass clangsharp_Type_getTypeClass(CXType CT);
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getUnderlyingExpr(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getUnderlyingType(CXType CT);
CLANGSHARP_LINKAGE CXType clangsharp_Type_getValueType(CXType CT);
#endif #endif

Просмотреть файл

@ -334,11 +334,15 @@ void MyFunction()
switch (value) switch (value)
{ {
case 0: case 0:
{
return 0; return 0;
}
case 2: case 2:
case 3: case 3:
{
return 5; return 5;
}
} }
return -1; return -1;
@ -368,7 +372,9 @@ static inline int MyFunction(MyEnum x)
} }
"; ";
var expectedOutputContents = @"namespace ClangSharp.Test var expectedOutputContents = @"using static ClangSharp.Test.MyEnum;
namespace ClangSharp.Test
{ {
public enum MyEnum public enum MyEnum
{ {
@ -733,7 +739,9 @@ int MyFunction()
int i = 0; int i = 0;
while (i < count) while (i < count)
{
i++; i++;
}
return i; return i;
} }
@ -949,41 +957,63 @@ int MyFunction()
public static int MyFunction(int count) public static int MyFunction(int count)
{ {
for (int i = 0; i < count; i--) for (int i = 0; i < count; i--)
{
i += 2; i += 2;
}
int x; int x;
for (x = 0; x < count; x--) for (x = 0; x < count; x--)
{
x += 2; x += 2;
}
x = 0; x = 0;
for (; x < count; x--) for (; x < count; x--)
{
x += 2; x += 2;
}
for (int i = 0;; i--) for (int i = 0;; i--)
{
i += 2; i += 2;
}
for (x = 0;; x--) for (x = 0;; x--)
{
x += 2; x += 2;
}
for (int i = 0; i < count;) for (int i = 0; i < count;)
{
i++; i++;
}
for (x = 0; x < count;) for (x = 0; x < count;)
{
x++; x++;
}
x = 0; x = 0;
for (; x < count;) for (; x < count;)
{
x++; x++;
}
for (int i = 0;;) for (int i = 0;;)
{
i++; i++;
}
for (x = 0;;) for (x = 0;;)
{
x++; x++;
}
for (;;) for (;;)
{
return -1; return -1;
}
} }
} }
} }
@ -1125,9 +1155,13 @@ int MyFunction()
public static int MyFunction(bool condition, int lhs, int rhs) public static int MyFunction(bool condition, int lhs, int rhs)
{ {
if (condition) if (condition)
{
return lhs; return lhs;
}
else else
{
return rhs; return rhs;
}
} }
} }
} }
@ -1543,7 +1577,9 @@ bool MyFunction(const MyStruct& lhs, const MyStruct& rhs)
switch (value) switch (value)
{ {
default: default:
{
return 0; return 0;
}
} }
} }
} }
@ -1742,7 +1778,9 @@ bool MyFunction(const MyStruct& lhs, const MyStruct& rhs)
int i = 0; int i = 0;
while (i < count) while (i < count)
{
i++; i++;
}
return i; return i;
} }

Просмотреть файл

@ -148,7 +148,7 @@ namespace ClangSharp.Test
[InlineData("unsigned short value = 7", @"[NativeTypeName(""unsigned short"")] ushort value = 7")] [InlineData("unsigned short value = 7", @"[NativeTypeName(""unsigned short"")] ushort value = 7")]
[InlineData("unsigned int value = 8", @"[NativeTypeName(""unsigned int"")] uint value = 8")] [InlineData("unsigned int value = 8", @"[NativeTypeName(""unsigned int"")] uint value = 8")]
[InlineData("unsigned long long value = 9", @"[NativeTypeName(""unsigned long long"")] ulong value = 9")] [InlineData("unsigned long long value = 9", @"[NativeTypeName(""unsigned long long"")] ulong value = 9")]
[InlineData("unsigned short value = 'A'", @"[NativeTypeName(""unsigned short"")] ushort value = 'A'")] [InlineData("unsigned short value = 'A'", @"[NativeTypeName(""unsigned short"")] ushort value = (byte)'A'")]
public async Task OptionalParameterTest(string nativeParameters, string expectedManagedParameters) public async Task OptionalParameterTest(string nativeParameters, string expectedManagedParameters)
{ {
var inputContents = $@"void MyFunction({nativeParameters});"; var inputContents = $@"void MyFunction({nativeParameters});";