Skip to content

Commit

Permalink
Improve support for CLMacroDefinition (#277)
Browse files Browse the repository at this point in the history
support for `_Generic` will be added later
  • Loading branch information
Gnimuc authored Jan 12, 2021
1 parent 01bf3e8 commit 5b3055e
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 148 deletions.
23 changes: 18 additions & 5 deletions gen/libclang_common.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Automatically generated using Clang.jl


const LLVM_CLANG_C_BUILDSYSTEM_H = nothing
const CXVirtualFileOverlayImpl = Cvoid
const CXVirtualFileOverlay = Ptr{CXVirtualFileOverlayImpl}
const CXModuleMapDescriptorImpl = Cvoid
const CXModuleMapDescriptor = Ptr{CXModuleMapDescriptorImpl}
const LLVM_CLANG_C_CXCOMPILATIONDATABASE_H = nothing
const CXCompilationDatabase = Ptr{Cvoid}
const CXCompileCommands = Ptr{Cvoid}
const CXCompileCommand = Ptr{Cvoid}
Expand All @@ -14,6 +16,9 @@ const CXCompileCommand = Ptr{Cvoid}
CXCompilationDatabase_CanNotLoadDatabase = 1
end


const LLVM_CLANG_C_CXERRORCODE_H = nothing

@cenum CXErrorCode::UInt32 begin
CXError_Success = 0
CXError_Failure = 1
Expand All @@ -23,6 +28,8 @@ end
end


const LLVM_CLANG_C_CXSTRING_H = nothing

struct CXString
data::Ptr{Cvoid}
private_flags::Cuint
Expand All @@ -33,6 +40,7 @@ struct CXStringSet
Count::Cuint
end

const LLVM_CLANG_C_DOCUMENTATION_H = nothing
const CXTranslationUnitImpl = Cvoid
const CXTranslationUnit = Ptr{CXTranslationUnitImpl}

Expand Down Expand Up @@ -71,15 +79,18 @@ end
end


const LLVM_CLANG_C_INDEX_H = nothing
const CINDEX_VERSION_MAJOR = 0
const CINDEX_VERSION_MINOR = 59

# Skipping MacroDefinition: CINDEX_VERSION_ENCODE ( major , minor ) ( ( ( major ) * 10000 ) + ( ( minor ) * 1 ) )
# Skipping MacroDefinition: CINDEX_VERSION CINDEX_VERSION_ENCODE ( CINDEX_VERSION_MAJOR , CINDEX_VERSION_MINOR )
# Skipping MacroDefinition: CINDEX_VERSION_STRINGIZE_ ( major , minor ) # major "." # minor
# Skipping MacroDefinition: CINDEX_VERSION_STRINGIZE ( major , minor ) CINDEX_VERSION_STRINGIZE_ ( major , minor )
# Skipping MacroDefinition: CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE ( CINDEX_VERSION_MAJOR , CINDEX_VERSION_MINOR )
CINDEX_VERSION_ENCODE(major, minor) = major * 10000 + minor * 1

const CINDEX_VERSION = CINDEX_VERSION_ENCODE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)

CINDEX_VERSION_STRINGIZE_(major, minor) = nothing
CINDEX_VERSION_STRINGIZE(major, minor) = CINDEX_VERSION_STRINGIZE_(major, minor)

const CINDEX_VERSION_STRING = CINDEX_VERSION_STRINGIZE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)
const CXIndex = Ptr{Cvoid}
const CXTargetInfoImpl = Cvoid
const CXTargetInfo = Ptr{CXTargetInfoImpl}
Expand Down Expand Up @@ -1187,5 +1198,7 @@ end


const CXFieldVisitor = Ptr{Cvoid}
const LLVM_CLANG_C_PLATFORM_H = nothing
const CINDEX_LINKAGE = nothing

# Skipping MacroDefinition: CINDEX_DEPRECATED __attribute__ ( ( deprecated ) )
2 changes: 0 additions & 2 deletions src/Clang.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export fields
include("token.jl")
export TokenList, tokenize, annotate

include("show.jl")

include("utils.jl")
export name_safe, symbol_safe
export copydeps, print_template
Expand Down
9 changes: 9 additions & 0 deletions src/cltypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Base.convert(::Type{T}, x::CXCursor) where {T<:CLCursor} = CLCursor(x)
Base.cconvert(::Type{CXCursor}, x::CLCursor) = x
Base.unsafe_convert(::Type{CXCursor}, x::CLCursor) = x.cursor

Base.show(io::IO, x::CXCursor) = print(io, "$(kind(x)): $(spelling(x))")
Base.show(io::IO, x::CLCursor) = print(io, "CLCursor (", typeof(x), ") ", name(x))

# each CXTypeKind enum gets a specific Julia type wrapping
# so that we can dispatch directly on node kinds.
abstract type CLType end
Expand All @@ -45,6 +48,9 @@ Base.convert(::Type{T}, x::CXType) where {T<:CLType} = CLType(x)
Base.cconvert(::Type{CXType}, x::CLType) = x
Base.unsafe_convert(::Type{CXType}, x::CLType) = x.type

Base.show(io::IO, x::CXType) = print(io, "$(kind(x)): $(spelling(x))")
Base.show(io::IO, x::CLType) = print(io, "CLType (", typeof(x), ") ")

# CLToken
abstract type CLToken end

Expand All @@ -64,3 +70,6 @@ end

Base.cconvert(::Type{CXToken}, x::CLToken) = x
Base.unsafe_convert(::Type{CXToken}, x::CLToken) = x.token

Base.show(io::IO, x::CXToken) = print(io, "$(kind(x))")
Base.show(io::IO, x::CLToken) = print(io, typeof(x), "(\"", x.text, "\")")
3 changes: 3 additions & 0 deletions src/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
mutable struct InternalOptions
wrap_structs::Bool
ismutable::Bool
aggresively_parse_macros::Bool
end
InternalOptions(wrap_structs, ismutable) = InternalOptions(wrap_structs, ismutable, true)
InternalOptions() = InternalOptions(true, false)

"""
Expand Down Expand Up @@ -94,6 +96,7 @@ function Base.run(wc::WrapContext, generate_template=true)
parse_headers!(ctx, wc.headers; args=wc.clang_args, includes=wc.clang_includes)
ctx.options["is_function_strictly_typed"] = false
ctx.options["is_struct_mutable"] = wc.options.ismutable
ctx.options["aggresively_parse_macros"] = wc.options.aggresively_parse_macros
# Helper to store file handles
filehandles = Dict{String,IOStream}()
getfile(f) = (f in keys(filehandles)) ? filehandles[f] : (filehandles[f] = open(f, "w"))
Expand Down
2 changes: 1 addition & 1 deletion src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mutable struct DefaultContext <: AbstractContext
trans_units::Vector{TranslationUnit}
options::Dict{String,Bool}
libname::String
force_name::String
force_name::String # a tmp cursor name
common_buffer::OrderedDict{Symbol,ExprUnit}
api_buffer::Vector
cursor_stack::Vector{CLCursor}
Expand Down
8 changes: 0 additions & 8 deletions src/show.jl

This file was deleted.

Loading

0 comments on commit 5b3055e

Please sign in to comment.