Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding various extensions to expose APIs in a object oriented manner. #31

Merged
merged 2 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ClangSharp/ClangSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
36 changes: 0 additions & 36 deletions ClangSharp/Extensions.cs

This file was deleted.

49 changes: 49 additions & 0 deletions ClangSharp/Extensions/CXCursor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;

namespace ClangSharp
{
public partial struct CXCursor : IEquatable<CXCursor>
{
public static CXCursor Null => clang.getNullCursor();

public CXSourceRange CommentRange => clang.Cursor_getCommentRange(this);

public CXType EnumDeclIntegerType => clang.getEnumDeclIntegerType(this);

public CXSourceRange Extent => clang.getCursorExtent(this);

public CXType IBOutletCollectionType => clang.getIBOutletCollectionType(this);

public bool IsNull => clang.Cursor_isNull(this) != 0;

public CXCursorKind Kind => clang.getCursorKind(this);

public CXSourceLocation Location => clang.getCursorLocation(this);

public CXType TypedefDeclUnderlyingType => clang.getTypedefDeclUnderlyingType(this);

public CXType RecieverType => clang.Cursor_getReceiverType(this);

public CXType ResultType => clang.getCursorResultType(this);

public CXString Spelling => clang.getCursorSpelling(this);

public CXTranslationUnit TranslationUnit => clang.Cursor_getTranslationUnit(this);

public CXType Type => clang.getCursorType(this);

public override bool Equals(object obj) => (obj is CXCursor other) && Equals(other);

public bool Equals(CXCursor other) => clang.equalCursors(this, other) != 0;

public override int GetHashCode() => (int)clang.hashCursor(this);

public CXSourceRange GetReferenceNameRange(CXNameRefFlags nameFlags, uint pieceIndex) => clang.getCursorReferenceNameRange(this, (uint)nameFlags, pieceIndex);

public CXType GetTemplateArgumentType(uint i) => clang.Cursor_getTemplateArgumentType(this, i);

public CXSourceRange GetSpellingNameRange(uint pieceIndex, uint options) => clang.Cursor_getSpellingNameRange(this, pieceIndex, options);

public override string ToString() => Spelling.ToString();
}
}
15 changes: 15 additions & 0 deletions ClangSharp/Extensions/CXCursorSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace ClangSharp
{
public partial struct CXCursorSet : IDisposable
{
public static CXCursorSet Create() => clang.createCXCursorSet();

public bool Contains(CXCursor cursor) => clang.CXCursorSet_contains(this, cursor) != 0;

public void Dispose() => clang.disposeCXCursorSet(this);

public bool Insert(CXCursor cursor) => clang.CXCursorSet_insert(this, cursor) != 0;
}
}
40 changes: 40 additions & 0 deletions ClangSharp/Extensions/CXDiagnostic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace ClangSharp
{
public partial struct CXDiagnostic : IDisposable
{
public static CXDiagnosticDisplayOptions DefaultDisplayOptions => (CXDiagnosticDisplayOptions)clang.defaultDiagnosticDisplayOptions();

public uint Category => clang.getDiagnosticCategory(this);

public CXString CategoryText => clang.getDiagnosticCategoryText(this);

public CXDiagnosticSet ChildDiagnostics => clang.getChildDiagnostics(this);

public CXSourceLocation Location => clang.getDiagnosticLocation(this);

public uint NumFixIts => clang.getDiagnosticNumFixIts(this);

public uint NumRanges => clang.getDiagnosticNumRanges(this);

public CXDiagnosticSeverity Severity => clang.getDiagnosticSeverity(this);

public CXString Spelling => clang.getDiagnosticSpelling(this);

public void Dispose() => clang.disposeDiagnostic(this);

public CXString Format(CXDiagnosticDisplayOptions options) => clang.formatDiagnostic(this, (uint)options);

[Obsolete("Use " + nameof(CategoryText) + " instead.")]
public static CXString GetCategoryName(uint category) => clang.getDiagnosticCategoryName(category);

public CXString GetFixIt(uint fixIt, out CXSourceRange replacementRange) => clang.getDiagnosticFixIt(this, fixIt, out replacementRange);

public CXString GetOption(out CXString disable) => clang.getDiagnosticOption(this, out disable);

public CXSourceRange GetRange(uint range) => clang.getDiagnosticRange(this, range);

public override string ToString() => Spelling.ToString();
}
}
29 changes: 29 additions & 0 deletions ClangSharp/Extensions/CXDiagnosticSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace ClangSharp
{
public partial struct CXDiagnosticSet : IDisposable, IReadOnlyCollection<CXDiagnostic>
{
public CXDiagnostic this[uint index] => GetDiagnostic(index);

public int Count => (int)clang.getNumDiagnosticsInSet(this);

public void Dispose() => clang.disposeDiagnosticSet(this);

public CXDiagnostic GetDiagnostic(uint index) => clang.getDiagnosticInSet(this, index);

public IEnumerator<CXDiagnostic> GetEnumerator()
{
var count = (uint)Count;

for (var index = 0u; index < count; index++)
{
yield return GetDiagnostic(index);
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
27 changes: 27 additions & 0 deletions ClangSharp/Extensions/CXFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace ClangSharp
{
public partial struct CXFile : IEquatable<CXFile>
{
public CXString Name => clang.getFileName(this);

public long Time => clang.getFileTime(this);

public override bool Equals(object obj) => (obj is CXFile other) && Equals(other);

public bool Equals(CXFile other) => clang.File_isEqual(this, other) != 0;

public string GetContents(CXTranslationUnit translationUnit, out ulong size) => clang.getFileContents(translationUnit, this, out size);

public CXSourceLocation GetLocation(CXTranslationUnit translationUnit, uint line, uint column) => clang.getLocation(translationUnit, this, line, column);

public CXSourceLocation GetLocationForOffset(CXTranslationUnit translationUnit, uint offset) => clang.getLocationForOffset(translationUnit, this, offset);

public bool IsMultipleIncludeGuarded(CXTranslationUnit translationUnit) => clang.isFileMultipleIncludeGuarded(translationUnit, this) != 0;

public override string ToString() => Name.ToString();

public CXString TryGetRealPathName() => clang.File_tryGetRealPathName(this);
}
}
17 changes: 17 additions & 0 deletions ClangSharp/Extensions/CXIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace ClangSharp
{
public partial struct CXIndex : IDisposable
{
public CXIndex Create(bool excludeDeclarationsFromPch = false, bool displayDiagnostics = false) => clang.createIndex(excludeDeclarationsFromPch ? 1 : 0, displayDiagnostics ? 1 : 0);

public CXGlobalOptFlags GlobalOptions
{
get => (CXGlobalOptFlags)clang.CXIndex_getGlobalOptions(this);
set => clang.CXIndex_setGlobalOptions(this, (uint)value);
}

public void Dispose() => clang.disposeIndex(this);
}
}
27 changes: 27 additions & 0 deletions ClangSharp/Extensions/CXSourceLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace ClangSharp
{
public partial struct CXSourceLocation : IEquatable<CXSourceLocation>
{
public static CXSourceLocation Null => clang.getNullLocation();

public bool IsFromMainFile => clang.Location_isFromMainFile(this) != 0;

public bool IsInSystemHeader => clang.Location_isInSystemHeader(this) != 0;

public override bool Equals(object obj) => (obj is CXSourceLocation other) && Equals(other);

public bool Equals(CXSourceLocation other) => clang.equalLocations(this, other) != 0;

public void GetExpansionLocation(out CXFile file, out uint line, out uint column, out uint offset) => clang.getExpansionLocation(this, out file, out line, out column, out offset);

public void GetFileLocation(out CXFile file, out uint line, out uint column, out uint offset) => clang.getFileLocation(this, out file, out line, out column, out offset);

public void GetInstantiationLocation(out CXFile file, out uint line, out uint column, out uint offset) => clang.getInstantiationLocation(this, out file, out line, out column, out offset);

public void GetPresumedLocation(out CXString fileName, out uint line, out uint column) => clang.getPresumedLocation(this, out fileName, out line, out column);

public void GetSpellingLocation(out CXFile file, out uint line, out uint column, out uint offset) => clang.getSpellingLocation(this, out file, out line, out column, out offset);
}
}
19 changes: 19 additions & 0 deletions ClangSharp/Extensions/CXSourceRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ClangSharp
{
public partial struct CXSourceRange : IEquatable<CXSourceRange>
{
public CXSourceRange Create(CXSourceLocation begin, CXSourceLocation end) => clang.getRange(begin, end);

public static CXSourceRange Null => clang.getNullRange();

public CXSourceLocation End => clang.getRangeEnd(this);

public CXSourceLocation Start => clang.getRangeStart(this);

public override bool Equals(object obj) => (obj is CXSourceRange other) && Equals(other);

public bool Equals(CXSourceRange other) => clang.equalRanges(this, other) != 0;
}
}
13 changes: 13 additions & 0 deletions ClangSharp/Extensions/CXString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace ClangSharp
{
public partial struct CXString : IDisposable
{
public string CString => clang.getCString(this);

public void Dispose() => clang.disposeString(this);

public override string ToString() => CString;
}
}
47 changes: 47 additions & 0 deletions ClangSharp/Extensions/CXTranslationUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

namespace ClangSharp
{
public partial struct CXTranslationUnit : IDisposable
{
public static CXTranslationUnit Create(CXIndex index, string astFileName) => clang.createTranslationUnit(index, astFileName);

public static CXErrorCode Create(CXIndex index, string astFileName, out CXTranslationUnit translationUnit) => clang.createTranslationUnit2(index, astFileName, out translationUnit);

public static CXTranslationUnit CreateFromSourceFile(CXIndex index, string sourceFileName, string[] commandLineArgs, CXUnsavedFile[] unsavedFiles) => clang.createTranslationUnitFromSourceFile(index, sourceFileName, commandLineArgs.Length, commandLineArgs, (uint)unsavedFiles.Length, unsavedFiles);

public static CXTranslationUnit Parse(CXIndex index, string sourceFileName, string[] commandLineArgs, CXUnsavedFile[] unsavedFiles, CXTranslationUnit_Flags options) => clang.parseTranslationUnit(index, sourceFileName, commandLineArgs, commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, (uint)options);

public static CXErrorCode Parse(CXIndex index, string sourceFileName, string[] commandLineArgs, CXUnsavedFile[] unsavedFiles, CXTranslationUnit_Flags options, out CXTranslationUnit translationUnit) => clang.parseTranslationUnit2(index, sourceFileName, commandLineArgs, commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, (uint)options, out translationUnit);

public static CXErrorCode ParseFullArgv(CXIndex index, string sourceFileName, string[] commandLineArgs, CXUnsavedFile[] unsavedFiles, CXTranslationUnit_Flags options, out CXTranslationUnit translationUnit) => clang.parseTranslationUnit2FullArgv(index, sourceFileName, commandLineArgs, commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, (uint)options, out translationUnit);

public CXCursor Cursor => clang.getTranslationUnitCursor(this);

public CXReparse_Flags DefaultReparseOptions => (CXReparse_Flags)clang.defaultReparseOptions(this);

public CXSaveTranslationUnit_Flags DefaultSaveOptions => (CXSaveTranslationUnit_Flags)clang.defaultSaveOptions(this);

public CXDiagnosticSet DiagnosticSet => clang.getDiagnosticSetFromTU(this);

public uint NumDiagnostics => clang.getNumDiagnostics(this);

public CXString Spelling => clang.getTranslationUnitSpelling(this);

public void Dispose() => clang.disposeTranslationUnit(this);

public CXCursor GetCursor(CXSourceLocation location) => clang.getCursor(this, location);

public CXDiagnostic GetDiagnostic(uint index) => clang.getDiagnostic(this, index);

public CXFile GetFile(string fileName) => clang.getFile(this, fileName);

public CXErrorCode Reparse(CXUnsavedFile[] unsavedFiles, CXReparse_Flags options) => (CXErrorCode)clang.reparseTranslationUnit(this, (uint)unsavedFiles.Length, unsavedFiles, (uint)options);

public CXSaveError Save(string fileName, CXSaveTranslationUnit_Flags options) => (CXSaveError)clang.saveTranslationUnit(this, fileName, (uint)options);

public bool Suspend() => clang.suspendTranslationUnit(this) != 0;

public override string ToString() => Spelling.ToString();
}
}
Loading