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 more extensions to expose APIs in an object oriented manner. #32

Merged
merged 2 commits into from
Apr 24, 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
30 changes: 30 additions & 0 deletions ClangSharp.Test/TranslationUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,35 @@ public void Basic(string name)
Directory.Delete(dir, true);
}
}

[Theory]
[InlineData("basic")]
[InlineData("example with spaces")]
[InlineData("♫")]
public void BasicWrapper(string name)
{
// Create a unique directory
var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(dir);

try
{
// Create a file with the right name
var file = new FileInfo(Path.Combine(dir, name + ".c"));
File.WriteAllText(file.FullName, "int main() { return 0; }");

var index = CXIndex.Create();
var translationUnit = CXTranslationUnit.Parse(index, file.FullName, Array.Empty<string>(), Array.Empty<CXUnsavedFile>(), CXTranslationUnit_Flags.CXTranslationUnit_None);
var clangFile = translationUnit.GetFile(file.FullName);
var clangFileName = clangFile.Name;
var clangFileNameString = clangFileName.CString;

Assert.Equal(file.FullName, clangFileNameString);
}
finally
{
Directory.Delete(dir, true);
}
}
}
}
1 change: 1 addition & 0 deletions ClangSharp/ClangSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

Expand Down
73 changes: 73 additions & 0 deletions ClangSharp/Extensions/CXComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace ClangSharp
{
public partial struct CXComment
{
public CXString BlockCommandComment_CommandName => clang.BlockCommandComment_getCommandName(this);

public uint BlockCommandComment_NumArgs => clang.BlockCommandComment_getNumArgs(this);

public CXComment BlockCommandComment_Paragraph => clang.BlockCommandComment_getParagraph(this);

public CXString FullComment_AsHtml => clang.FullComment_getAsHTML(this);

public CXString FullComment_AsXml => clang.FullComment_getAsXML(this);

public uint HtmlStartTag_NumAttrs => clang.HTMLStartTag_getNumAttrs(this);

public bool HtmlStartTagComment_IsSelfClosing => clang.HTMLStartTagComment_isSelfClosing(this) != 0;

public CXString HtmlTagComment_AsString => clang.HTMLTagComment_getAsString(this);

public CXString HtmlTagComment_TagName => clang.HTMLTagComment_getTagName(this);

public CXString InlineCommandComment_CommandName => clang.InlineCommandComment_getCommandName(this);

public uint InlineCommandComment_NumArgs => clang.InlineCommandComment_getNumArgs(this);

public CXCommentInlineCommandRenderKind InlineCommandComment_RenderKind => clang.InlineCommandComment_getRenderKind(this);

public bool InlineContentComment_HasTrailingNewline => clang.InlineContentComment_hasTrailingNewline(this) != 0;

public bool IsWhitesapce => clang.Comment_isWhitespace(this) != 0;

public CXCommentKind Kind => clang.Comment_getKind(this);

public uint NumChildren => clang.Comment_getNumChildren(this);

public CXCommentParamPassDirection ParamCommandComment_Direction => clang.ParamCommandComment_getDirection(this);

public bool ParamCommandComment_IsDirectionExplicit => clang.ParamCommandComment_isDirectionExplicit(this) != 0;

public bool ParamCommandComment_IsParamIndexValid => clang.ParamCommandComment_isParamIndexValid(this) != 0;

public uint ParamCommandComment_ParamIndex => clang.ParamCommandComment_getParamIndex(this);

public CXString ParamCommandComment_ParamName => clang.ParamCommandComment_getParamName(this);

public CXString TextComment_Text => clang.TextComment_getText(this);

public uint TParamCommandComment_Depth => clang.TParamCommandComment_getDepth(this);

public CXString TParamCommandComment_ParamName => clang.TParamCommandComment_getParamName(this);

public bool TParamCommandComment_IsParamPositionValid => clang.TParamCommandComment_isParamPositionValid(this) != 0;

public CXString VerbatimBlockLineComment_Text => clang.VerbatimBlockLineComment_getText(this);

public CXString VerbatimLineComment_Text => clang.VerbatimLineComment_getText(this);

public CXString BlockCommandComment_GetArgText(uint index) => clang.BlockCommandComment_getArgText(this, index);

public CXComment GetChild(uint index) => clang.Comment_getChild(this, index);

public CXTranslationUnit GetTranslationUnit() => new CXTranslationUnit(TranslationUnit);

public CXString HtmlStartTag_GetAttrName(uint index) => clang.HTMLStartTag_getAttrName(this, index);

public CXString HtmlStartTag_GetAttrValue(uint index) => clang.HTMLStartTag_getAttrValue(this, index);

public CXString InlineCommandComment_GetArgText(uint index) => clang.InlineCommandComment_getArgText(this, index);

public uint TParamCommandComment_GetIndex(uint depth) => clang.TParamCommandComment_getIndex(this, depth);
}
}
25 changes: 25 additions & 0 deletions ClangSharp/Extensions/CXCompletionString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ClangSharp
{
public partial struct CXCompletionString
{
public CXAvailabilityKind Availability => clang.getCompletionAvailability(this);

public CXString BriefComment => clang.getCompletionBriefComment(this);

public uint NumAnnotations => clang.getCompletionNumAnnotations(this);

public uint NumChunks => clang.getNumCompletionChunks(this);

public uint Priority => clang.getCompletionPriority(this);

public CXString GetAnnotation(uint index) => clang.getCompletionAnnotation(this, index);

public CXCompletionString GetChunkCompletionString(uint index) => clang.getCompletionChunkCompletionString(this, index);

public CXCompletionChunkKind GetChunkKind(uint index) => clang.getCompletionChunkKind(this, index);

public CXString GetChunkText(uint index) => clang.getCompletionChunkText(this, index);

public CXString GetParent(ref CXCursorKind kind) => clang.getCompletionParent(this, ref kind);
}
}
177 changes: 174 additions & 3 deletions ClangSharp/Extensions/CXCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,215 @@ public partial struct CXCursor : IEquatable<CXCursor>
{
public static CXCursor Null => clang.getNullCursor();

public CXAvailabilityKind Availability => clang.getCursorAvailability(this);

public CXString BriefCommentText => clang.Cursor_getBriefCommentText(this);

public CXCursor CanonicalCursor => clang.getCanonicalCursor(this);

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

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

public CX_CXXAccessSpecifier CXXAccessSpecifier => clang.getCXXAccessSpecifier(this);

public bool CXXConstructor_IsConvertingConstructor => clang.CXXConstructor_isConvertingConstructor(this) != 0;

public bool CXXConstructor_IsCopyConstructor => clang.CXXConstructor_isCopyConstructor(this) != 0;

public bool CXXConstructor_IsDefaultConstructor => clang.CXXConstructor_isDefaultConstructor(this) != 0;

public bool CXXConstructor_IsMoveConstructor => clang.CXXConstructor_isMoveConstructor(this) != 0;

public bool CXXField_IsMutable => clang.CXXField_isMutable(this) != 0;

public unsafe ref CXStringSet CXXManglings => ref *(CXStringSet*)clang.Cursor_getCXXManglings(this);

public bool CXXMethod_IsConst => clang.CXXMethod_isConst(this) != 0;

public bool CXXMethod_IsDefaulted => clang.CXXMethod_isDefaulted(this) != 0;

public bool CXXMethod_IsPureVirtual => clang.CXXMethod_isPureVirtual(this) != 0;

public bool CXXMethod_IsStatic => clang.CXXMethod_isStatic(this) != 0;

public bool CXXMethod_IsVirtual => clang.CXXMethod_isVirtual(this) != 0;

public bool CXXRecord_IsAbstract => clang.CXXRecord_isAbstract(this) != 0;

public CXString DeclObjCTypeEncoding => clang.getDeclObjCTypeEncoding(this);

public CXCursor Definition => clang.getCursorDefinition(this);

public CXString DisplayName => clang.getCursorDisplayName(this);

public ulong EnumConstantDeclUnsignedValue => clang.getEnumConstantDeclUnsignedValue(this);

public long EnumConstantDeclValue => clang.getEnumConstantDeclValue(this);

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

public bool EnumDecl_IsScoped => clang.EnumDecl_isScoped(this) != 0;

public CXEvalResult Evaluate => clang.Cursor_Evaluate(this);

public int ExceptionSpecificationType => clang.getCursorExceptionSpecificationType(this);

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

public int FieldDeclBitWidth => clang.getFieldDeclBitWidth(this);

public bool HasAttrs => clang.Cursor_hasAttrs(this) != 0;

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

public CXFile IncludedFile => clang.getIncludedFile(this);

public bool IsAnonymous => clang.Cursor_isAnonymous(this) != 0;

public bool IsAttribute => clang.isAttribute(Kind) != 0;

public bool IsBitField => clang.Cursor_isBitField(this) != 0;

public bool IsDeclaration => clang.isDeclaration(Kind) != 0;

public bool IsDefinition => clang.isCursorDefinition(this) != 0;

public bool IsDynamicCall => clang.Cursor_isDynamicCall(this) != 0;

public bool IsExpression => clang.isExpression(Kind) != 0;

public bool IsFunctionInlined => clang.Cursor_isFunctionInlined(this) != 0;

public bool IsInvalid => clang.isInvalid(Kind) != 0;

public bool IsInvalidDeclaration => clang.isInvalidDeclaration(this) != 0;

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

public bool IsMacroBuiltIn => clang.Cursor_isMacroBuiltin(this) != 0;

public bool IsMacroFunctionLike => clang.Cursor_isMacroFunctionLike(this) != 0;

public bool IsObjCOptional => clang.Cursor_isObjCOptional(this) != 0;

public bool IsPreProcessing => clang.isPreprocessing(Kind) != 0;

public bool IsReference => clang.isReference(Kind) != 0;

public bool IsStatement => clang.isStatement(Kind) != 0;

public bool IsTranslationUnit => clang.isTranslationUnit(Kind) != 0;

public bool IsUnexposed => clang.isUnexposed(Kind) != 0;

public bool IsVariadic => clang.Cursor_isVariadic(this) != 0;

public bool IsVirtualBase => clang.isVirtualBase(this) != 0;

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

public CXString KindSpelling => clang.getCursorKindSpelling(Kind);

public CXLanguageKind Language => clang.getCursorLanguage(this);

public CXCursor LexicalParent => clang.getCursorLexicalParent(this);

public CXLinkageKind Linkage => clang.getCursorLinkage(this);

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

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

public CXModule Module => clang.Cursor_getModule(this);

public int NumArguments => clang.Cursor_getNumArguments(this);

public uint NumOverloadedDecls => clang.getNumOverloadedDecls(this);

public int NumTemplateArguments => clang.Cursor_getNumTemplateArguments(this);

public CXObjCDeclQualifierKind ObjCDeclQualifiers => (CXObjCDeclQualifierKind)clang.Cursor_getObjCDeclQualifiers(this);

public unsafe ref CXStringSet ObjCManglings => ref *(CXStringSet*)clang.Cursor_getObjCManglings(this);

public CXString ObjCPropertyGetterName => clang.Cursor_getObjCPropertyGetterName(this);

public CXString ObjCPropertySetterName => clang.Cursor_getObjCPropertySetterName(this);

public int ObjCSelectorIndex => clang.Cursor_getObjCSelectorIndex(this);

public long OffsetOfField => clang.Cursor_getOffsetOfField(this);

public CXComment ParsedComment => clang.Cursor_getParsedComment(this);

public CXString RawCommentText => clang.Cursor_getRawCommentText(this);

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

public CXCursor Referenced => clang.getCursorReferenced(this);

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

public CXCursor SemanticParent => clang.getCursorSemanticParent(this);

public CXCursor SpecializedCursorTemplate => clang.getSpecializedCursorTemplate(this);

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

public CX_StorageClass StorageClass => clang.Cursor_getStorageClass(this);

public CXCursorKind TemplateCursorKind => clang.getTemplateCursorKind(this);

public CXTLSKind TlsKind => clang.getCursorTLSKind(this);

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

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

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

public CXString UnifiedSymbolResolution => clang.getCursorUSR(this);

public CXVisibilityKind Visibility => clang.getCursorVisibility(this);

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

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

public CXResult FindReferenceInFile(CXFile file, CXCursorAndRangeVisitor visitor) => clang.findReferencesInFile(this, file, visitor);

public CXCursor GetArgument(uint index) => clang.Cursor_getArgument(this, index);

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

public bool GetIsExternalSymbol(out CXString language, out CXString definedIn, out bool isGenerated)
{
var result = clang.Cursor_isExternalSymbol(this, out language, out definedIn, out uint isGeneratedOut);
isGenerated = isGeneratedOut != 0;
return result != 0;
}

public CXObjCPropertyAttrKind GetObjCPropertyAttributes(uint reserved) => (CXObjCPropertyAttrKind)clang.Cursor_getObjCPropertyAttributes(this, reserved);

public CXCursor GetOverloadedDecl(uint index) => clang.getOverloadedDecl(this, index);

public int GetPlatformAvailability(out bool alwaysDeprecated, out CXString deprecatedMessage, out bool alwaysUnavailable, out CXString unavailableMessage, CXPlatformAvailability[] availability) => clang.getCursorPlatformAvailability(this, out alwaysDeprecated, out deprecatedMessage, out alwaysUnavailable, out unavailableMessage, availability, availability.Length);

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

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

public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clang.Cursor_getTemplateArgumentKind(this, i);

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

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

public long GetTemplateArgumentValue(uint i) => clang.Cursor_getTemplateArgumentValue(this, i);

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

public CXChildVisitResult VisitChildren(CXCursorVisitor visitor, CXClientData clientData) => (CXChildVisitResult)clang.visitChildren(this, visitor, clientData);
}
}
23 changes: 23 additions & 0 deletions ClangSharp/Extensions/CXEvalResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace ClangSharp
{
public partial struct CXEvalResult : IDisposable
{
public double AsDouble => clang.EvalResult_getAsDouble(this);

public int AsInt => clang.EvalResult_getAsInt(this);

public long AsLongLong => clang.EvalResult_getAsLongLong(this);

public string AsStr => clang.EvalResult_getAsStr(this);

public ulong AsUnsigned => clang.EvalResult_getAsUnsigned(this);

public bool IsUnsignedInt => clang.EvalResult_isUnsignedInt(this) != 0;

public CXEvalResultKind Kind => clang.EvalResult_getKind(this);

public void Dispose() => clang.EvalResult_dispose(this);
}
}
Loading