Skip to content

Commit

Permalink
rename to clang.*
Browse files Browse the repository at this point in the history
  • Loading branch information
mjsabby committed Feb 15, 2015
1 parent 83b4c24 commit 31239fd
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 362 deletions.
8 changes: 4 additions & 4 deletions ClangSharp/Extensions.cs
Expand Up @@ -7,7 +7,7 @@ public partial struct CXString
public override string ToString()
{
string retval = Marshal.PtrToStringAnsi(this.data);
Methods.clang_disposeString(this);
clang.disposeString(this);
return retval;
}
}
Expand All @@ -16,23 +16,23 @@ public partial struct CXType
{
public override string ToString()
{
return Methods.clang_getTypeSpelling(this).ToString();
return clang.getTypeSpelling(this).ToString();
}
}

public partial struct CXCursor
{
public override string ToString()
{
return Methods.clang_getCursorSpelling(this).ToString();
return clang.getCursorSpelling(this).ToString();
}
}

public partial struct CXDiagnostic
{
public override string ToString()
{
return Methods.clang_getDiagnosticSpelling(this).ToString();
return clang.getDiagnosticSpelling(this).ToString();
}
}
}
578 changes: 289 additions & 289 deletions ClangSharp/Generated.cs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions ClangSharpPInvokeGenerator/EnumVisitor.cs
Expand Up @@ -23,11 +23,11 @@ public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
return CXChildVisitResult.CXChildVisit_Continue;
}

CXCursorKind curKind = Methods.clang_getCursorKind(cursor);
CXCursorKind curKind = clang.getCursorKind(cursor);
if (curKind == CXCursorKind.CXCursor_EnumDecl)
{
string inheritedEnumType;
CXTypeKind kind = Methods.clang_getEnumDeclIntegerType(cursor).kind;
CXTypeKind kind = clang.getEnumDeclIntegerType(cursor).kind;

switch (kind)
{
Expand All @@ -54,16 +54,16 @@ public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
break;
}

var enumName = Methods.clang_getCursorSpelling(cursor).ToString();
var enumName = clang.getCursorSpelling(cursor).ToString();

// enumName can be empty because of typedef enum { .. } enumName;
// so we have to find the sibling, and this is the only way I've found
// to do with libclang, maybe there is a better way?
if (string.IsNullOrEmpty(enumName))
{
var forwardDeclaringVisitor = new ForwardDeclarationVisitor(cursor);
Methods.clang_visitChildren(Methods.clang_getCursorLexicalParent(cursor), forwardDeclaringVisitor.Visit, new CXClientData(IntPtr.Zero));
enumName = Methods.clang_getCursorSpelling(forwardDeclaringVisitor.ForwardDeclarationCursor).ToString();
clang.visitChildren(clang.getCursorLexicalParent(cursor), forwardDeclaringVisitor.Visit, new CXClientData(IntPtr.Zero));
enumName = clang.getCursorSpelling(forwardDeclaringVisitor.ForwardDeclarationCursor).ToString();

if (string.IsNullOrEmpty(enumName))
{
Expand All @@ -83,9 +83,9 @@ public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
this.tw.WriteLine(" {");

// visit all the enum values
Methods.clang_visitChildren(cursor, (cxCursor, _, __) =>
clang.visitChildren(cursor, (cxCursor, _, __) =>
{
this.tw.WriteLine(" @" + Methods.clang_getCursorSpelling(cxCursor).ToString() + " = " + Methods.clang_getEnumConstantDeclValue(cxCursor) + ",");
this.tw.WriteLine(" @" + clang.getCursorSpelling(cxCursor).ToString() + " = " + clang.getEnumConstantDeclValue(cxCursor) + ",");
return CXChildVisitResult.CXChildVisit_Continue;
}, new CXClientData(IntPtr.Zero));

Expand Down
66 changes: 33 additions & 33 deletions ClangSharpPInvokeGenerator/Extensions.cs
Expand Up @@ -8,14 +8,14 @@ internal static class Extensions
{
public static bool IsInSystemHeader(this CXCursor cursor)
{
return Methods.clang_Location_isInSystemHeader(Methods.clang_getCursorLocation(cursor)) != 0;
return clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0;
}

public static bool IsPtrToConstChar(this CXType type)
{
var pointee = Methods.clang_getPointeeType(type);
var pointee = clang.getPointeeType(type);

if (Methods.clang_isConstQualifiedType(pointee) != 0)
if (clang.isConstQualifiedType(pointee) != 0)
{
switch (pointee.kind)
{
Expand All @@ -29,7 +29,7 @@ public static bool IsPtrToConstChar(this CXType type)

public static string ToPlainTypeString(this CXType type, string unknownType = "UnknownType")
{
var canonical = Methods.clang_getCanonicalType(type);
var canonical = clang.getCanonicalType(type);
switch (type.kind)
{
case CXTypeKind.CXType_Bool:
Expand Down Expand Up @@ -68,7 +68,7 @@ public static string ToPlainTypeString(this CXType type, string unknownType = "U
case CXTypeKind.CXType_Unexposed:
if (canonical.kind == CXTypeKind.CXType_Unexposed)
{
return Methods.clang_getTypeSpelling(canonical).ToString();
return clang.getTypeSpelling(canonical).ToString();
}
return canonical.ToPlainTypeString();
default:
Expand All @@ -78,13 +78,13 @@ public static string ToPlainTypeString(this CXType type, string unknownType = "U

public static string ToMarshalString(this CXCursor cursor, string cursorSpelling)
{
var canonical = Methods.clang_getCanonicalType(Methods.clang_getCursorType(cursor));
var canonical = clang.getCanonicalType(clang.getCursorType(cursor));

switch (canonical.kind)
{
case CXTypeKind.CXType_ConstantArray:
long arraySize = Methods.clang_getArraySize(canonical);
var elementType = Methods.clang_getCanonicalType(Methods.clang_getArrayElementType(canonical));
long arraySize = clang.getArraySize(canonical);
var elementType = clang.getCanonicalType(clang.getArrayElementType(canonical));

var sb = new StringBuilder();
for (int i = 0; i < arraySize; ++i)
Expand All @@ -94,7 +94,7 @@ public static string ToMarshalString(this CXCursor cursor, string cursorSpelling

return sb.ToString();
case CXTypeKind.CXType_Pointer:
var pointeeType = Methods.clang_getCanonicalType(Methods.clang_getPointeeType(canonical));
var pointeeType = clang.getCanonicalType(clang.getPointeeType(canonical));
switch (pointeeType.kind)
{
case CXTypeKind.CXType_Char_S:
Expand All @@ -106,17 +106,17 @@ public static string ToMarshalString(this CXCursor cursor, string cursorSpelling
}
case CXTypeKind.CXType_Record:
case CXTypeKind.CXType_Enum:
return "public " + Methods.clang_getTypeSpelling(canonical).ToString() + " @" + cursorSpelling + ";";
return "public " + clang.getTypeSpelling(canonical).ToString() + " @" + cursorSpelling + ";";
default:
return "public " + canonical.ToPlainTypeString() + " @" + cursorSpelling + ";";
}
}

public static void WriteFunctionInfoHelper(CXCursor cursor, TextWriter tw, string prefixStrip)
{
var functionType = Methods.clang_getCursorType(cursor);
var functionName = Methods.clang_getCursorSpelling(cursor).ToString();
var resultType = Methods.clang_getCursorResultType(cursor);
var functionType = clang.getCursorType(cursor);
var functionName = clang.getCursorSpelling(cursor).ToString();
var resultType = clang.getCursorResultType(cursor);

tw.WriteLine(" [DllImport(libraryPath, CallingConvention = " + functionType.CallingConventionSpelling() + ")]");
tw.Write(" public static extern ");
Expand All @@ -130,11 +130,11 @@ public static void WriteFunctionInfoHelper(CXCursor cursor, TextWriter tw, strin

tw.Write(" " + functionName + "(");

int numArgTypes = Methods.clang_getNumArgTypes(functionType);
int numArgTypes = clang.getNumArgTypes(functionType);

for (uint i = 0; i < numArgTypes; ++i)
{
ArgumentHelper(functionType, Methods.clang_Cursor_getArgument(cursor, i), tw, i);
ArgumentHelper(functionType, clang.Cursor_getArgument(cursor, i), tw, i);
}

tw.WriteLine(");");
Expand All @@ -143,7 +143,7 @@ public static void WriteFunctionInfoHelper(CXCursor cursor, TextWriter tw, strin

public static string CallingConventionSpelling(this CXType type)
{
var callingConvention = Methods.clang_getFunctionTypeCallingConv(type);
var callingConvention = clang.getFunctionTypeCallingConv(type);
switch (callingConvention)
{
case CXCallingConv.CXCallingConv_X86StdCall:
Expand All @@ -169,11 +169,11 @@ public static void ReturnTypeHelper(CXType resultType, TextWriter tw)

public static void ArgumentHelper(CXType functionType, CXCursor paramCursor, TextWriter tw, uint index)
{
var numArgTypes = Methods.clang_getNumArgTypes(functionType);
var type = Methods.clang_getArgType(functionType, index);
var cursorType = Methods.clang_getCursorType(paramCursor);
var numArgTypes = clang.getNumArgTypes(functionType);
var type = clang.getArgType(functionType, index);
var cursorType = clang.getCursorType(paramCursor);

var spelling = Methods.clang_getCursorSpelling(paramCursor).ToString();
var spelling = clang.getCursorSpelling(paramCursor).ToString();
if (string.IsNullOrEmpty(spelling))
{
spelling = "param" + index;
Expand All @@ -182,14 +182,14 @@ public static void ArgumentHelper(CXType functionType, CXCursor paramCursor, Tex
switch (type.kind)
{
case CXTypeKind.CXType_Pointer:
var pointee = Methods.clang_getPointeeType(type);
var pointee = clang.getPointeeType(type);
switch (pointee.kind)
{
case CXTypeKind.CXType_Pointer:
tw.Write(pointee.IsPtrToConstChar() && Methods.clang_isConstQualifiedType(pointee) != 0 ? "string[]" : "out IntPtr");
tw.Write(pointee.IsPtrToConstChar() && clang.isConstQualifiedType(pointee) != 0 ? "string[]" : "out IntPtr");
break;
case CXTypeKind.CXType_FunctionProto:
tw.Write(Methods.clang_getTypeSpelling(cursorType).ToString());
tw.Write(clang.getTypeSpelling(cursorType).ToString());
break;
case CXTypeKind.CXType_Void:
tw.Write("IntPtr");
Expand Down Expand Up @@ -221,43 +221,43 @@ public static void ArgumentHelper(CXType functionType, CXCursor paramCursor, Tex

private static void CommonTypeHandling(CXType type, TextWriter tw, string outParam = "")
{
bool isConstQualifiedType = Methods.clang_isConstQualifiedType(type) != 0;
bool isConstQualifiedType = clang.isConstQualifiedType(type) != 0;
string spelling;
switch (type.kind)
{
case CXTypeKind.CXType_Typedef:
var cursor = Methods.clang_getTypeDeclaration(type);
if (Methods.clang_Location_isInSystemHeader(Methods.clang_getCursorLocation(cursor)) != 0)
var cursor = clang.getTypeDeclaration(type);
if (clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0)
{
spelling = Methods.clang_getCanonicalType(type).ToPlainTypeString();
spelling = clang.getCanonicalType(type).ToPlainTypeString();
}
else
{
spelling = Methods.clang_getCursorSpelling(cursor).ToString();
spelling = clang.getCursorSpelling(cursor).ToString();
}
break;
case CXTypeKind.CXType_Record:
case CXTypeKind.CXType_Enum:
spelling = Methods.clang_getTypeSpelling(type).ToString();
spelling = clang.getTypeSpelling(type).ToString();
break;
case CXTypeKind.CXType_IncompleteArray:
CommonTypeHandling(Methods.clang_getArrayElementType(type), tw);
CommonTypeHandling(clang.getArrayElementType(type), tw);
spelling = "[]";
break;
case CXTypeKind.CXType_Unexposed: // Often these are enums and canonical type gets you the enum spelling
var canonical = Methods.clang_getCanonicalType(type);
var canonical = clang.getCanonicalType(type);
// unexposed decl which turns into a function proto seems to be an un-typedef'd fn pointer
if (canonical.kind == CXTypeKind.CXType_FunctionProto)
{
spelling = "IntPtr";
}
else
{
spelling = Methods.clang_getTypeSpelling(canonical).ToString();
spelling = clang.getTypeSpelling(canonical).ToString();
}
break;
default:
spelling = Methods.clang_getCanonicalType(type).ToPlainTypeString();
spelling = clang.getCanonicalType(type).ToPlainTypeString();
break;
}

Expand Down
2 changes: 1 addition & 1 deletion ClangSharpPInvokeGenerator/ForwardDeclarationVisitor.cs
Expand Up @@ -23,7 +23,7 @@ public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
return CXChildVisitResult.CXChildVisit_Continue;
}

if (Methods.clang_equalCursors(cursor, this.beginningCursor) != 0)
if (clang.equalCursors(cursor, this.beginningCursor) != 0)
{
this.beginningCursorReached = true;
return CXChildVisitResult.CXChildVisit_Continue;
Expand Down
4 changes: 2 additions & 2 deletions ClangSharpPInvokeGenerator/FunctionVisitor.cs
Expand Up @@ -28,12 +28,12 @@ public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
return CXChildVisitResult.CXChildVisit_Continue;
}

CXCursorKind curKind = Methods.clang_getCursorKind(cursor);
CXCursorKind curKind = clang.getCursorKind(cursor);

// look only at function decls
if (curKind == CXCursorKind.CXCursor_FunctionDecl)
{
var functionName = Methods.clang_getCursorSpelling(cursor).ToString();
var functionName = clang.getCursorSpelling(cursor).ToString();

if (this.visitedFunctions.Contains(functionName))
{
Expand Down
24 changes: 12 additions & 12 deletions ClangSharpPInvokeGenerator/Program.cs
Expand Up @@ -92,7 +92,7 @@ public static void Main(string[] args)
}
}

var createIndex = Methods.clang_createIndex(0, 0);
var createIndex = clang.createIndex(0, 0);
string[] arr = { "-x", "c++" };

arr = arr.Concat(includeDirs.Select(x => "-I" + x)).ToArray();
Expand All @@ -103,18 +103,18 @@ public static void Main(string[] args)
{
CXTranslationUnit translationUnit;
CXUnsavedFile unsavedFile;
var translationUnitError = Methods.clang_parseTranslationUnit2(createIndex, file, arr, 3, out unsavedFile, 0, 0, out translationUnit);
var translationUnitError = clang.parseTranslationUnit2(createIndex, file, arr, 3, out unsavedFile, 0, 0, out translationUnit);

if (translationUnitError != CXErrorCode.CXError_Success)
{
Console.WriteLine("Error: " + translationUnitError);
var numDiagnostics = Methods.clang_getNumDiagnostics(translationUnit);
var numDiagnostics = clang.getNumDiagnostics(translationUnit);

for (uint i = 0; i < numDiagnostics; ++i)
{
var diagnostic = Methods.clang_getDiagnostic(translationUnit, i);
Console.WriteLine(Methods.clang_getDiagnosticSpelling(diagnostic).ToString());
Methods.clang_disposeDiagnostic(diagnostic);
var diagnostic = clang.getDiagnostic(translationUnit, i);
Console.WriteLine(clang.getDiagnosticSpelling(diagnostic).ToString());
clang.disposeDiagnostic(diagnostic);
}
}

Expand All @@ -133,19 +133,19 @@ public static void Main(string[] args)
var structVisitor = new StructVisitor(sw);
foreach (var tu in translationUnits)
{
Methods.clang_visitChildren(Methods.clang_getTranslationUnitCursor(tu), structVisitor.Visit, new CXClientData(IntPtr.Zero));
clang.visitChildren(clang.getTranslationUnitCursor(tu), structVisitor.Visit, new CXClientData(IntPtr.Zero));
}

var typeDefVisitor = new TypeDefVisitor(sw);
foreach (var tu in translationUnits)
{
Methods.clang_visitChildren(Methods.clang_getTranslationUnitCursor(tu), typeDefVisitor.Visit, new CXClientData(IntPtr.Zero));
clang.visitChildren(clang.getTranslationUnitCursor(tu), typeDefVisitor.Visit, new CXClientData(IntPtr.Zero));
}

var enumVisitor = new EnumVisitor(sw);
foreach (var tu in translationUnits)
{
Methods.clang_visitChildren(Methods.clang_getTranslationUnitCursor(tu), enumVisitor.Visit, new CXClientData(IntPtr.Zero));
clang.visitChildren(clang.getTranslationUnitCursor(tu), enumVisitor.Visit, new CXClientData(IntPtr.Zero));
}

sw.WriteLine(" public static partial class " + methodClassName);
Expand All @@ -154,7 +154,7 @@ public static void Main(string[] args)
var functionVisitor = new FunctionVisitor(sw, libraryPath, prefixStrip);
foreach (var tu in translationUnits)
{
Methods.clang_visitChildren(Methods.clang_getTranslationUnitCursor(tu), functionVisitor.Visit, new CXClientData(IntPtr.Zero));
clang.visitChildren(clang.getTranslationUnitCursor(tu), functionVisitor.Visit, new CXClientData(IntPtr.Zero));
}
}
sw.WriteLine(" }");
Expand All @@ -163,10 +163,10 @@ public static void Main(string[] args)

foreach (var tu in translationUnits)
{
Methods.clang_disposeTranslationUnit(tu);
clang.disposeTranslationUnit(tu);
}

Methods.clang_disposeIndex(createIndex);
clang.disposeIndex(createIndex);
}
}
}

0 comments on commit 31239fd

Please sign in to comment.