Skip to content

Commit

Permalink
Merge pull request #474 from JuliaInterop/no_sourcebuffers
Browse files Browse the repository at this point in the history
fix usage in precompiled modules: eliminate sourcebuffers
  • Loading branch information
Gnimuc authored May 30, 2020
2 parents aad6940 + db01af5 commit 1c1b72b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
20 changes: 8 additions & 12 deletions src/cxxstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,8 @@ function ArgCleanup(C,e,sv)
end
end

const sourcebuffers = Vector{Tuple{AbstractString,Symbol,Int,Int,Bool}}(undef, 0)

struct SourceBuf{id}; end
sourceid(::Type{SourceBuf{id}}) where {id} = id
struct SourceBuf{source,filename,line,col,disable_ac}; end
sourcebuf_data(::Type{SourceBuf{source,filename,line,col,disable_ac}}) where {source,filename,line,col,disable_ac} = String(source),filename,line,col,disable_ac

icxxcounter = 0

Expand Down Expand Up @@ -575,9 +573,9 @@ end
ret
end

function build_icxx_expr(id, exprs, isexprs, icxxs, compiler, impl_func = cxxstr_impl)
function build_icxx_expr(sourcebuf, exprs, isexprs, icxxs, compiler, impl_func = cxxstr_impl)
setup = Expr(:block)
cxxstr = Expr(:call,impl_func,compiler,:($(SourceBuf){$id}()))
cxxstr = Expr(:call,impl_func,compiler,sourcebuf)
for (i,e) in enumerate(exprs)
#=if isexprs[i]
s = gensym()
Expand Down Expand Up @@ -692,17 +690,15 @@ function process_cxx_string(str, global_scope=true, type_name=false, __source__=
Expr(:call, CxxType, :__current_compiler__,
CxxTypeName{Symbol(String(take!(sourcebuf)))}(),CodeLoc{filename,__source__.line,col}(),exprs...)
else
push!(sourcebuffers,(String(take!(sourcebuf)),filename,__source__.line, col, disable_ac))
id = length(sourcebuffers)
build_icxx_expr(id, exprs, isexprs, icxxs, compiler, cxxstr_impl)
SB = SourceBuf{Symbol(String(take!(sourcebuf))), filename, __source__.line, col, disable_ac}()
build_icxx_expr(SB, exprs, isexprs, icxxs, compiler, cxxstr_impl)
end
end
end

@generated function cxxstr_impl(CT, sourcebuf, args...)
@generated function cxxstr_impl(CT, SB, args...)
C = instance(CT)
id = sourceid(sourcebuf)
buf, filename, line, col, disable_ac = sourcebuffers[id]
buf, filename, line, col, disable_ac = sourcebuf_data(SB)

FD, llvmargs, argidxs, symargs = CreateFunctionWithBody(C,buf, args...; filename = filename, line = line, col = col, disable_ac=disable_ac)
EmitTopLevelDecl(C,FD)
Expand Down
10 changes: 4 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ compiler(C::CxxInstance) = compiler(instance(C))
shadow(C::CxxInstance) = shadow(instance(C))

# Try to dump the generated Clang AST generated by Cxx.jl
@generated function dumpast_impl(CT, sourcebuf, args...)
@generated function dumpast_impl(CT, SB, args...)
C = instance(CT)
id = sourceid(sourcebuf)
buf, filename, line, col = sourcebuffers[id]
buf, filename, line, col = sourcebuf_data(SB)

FD, llvmargs, argidxs = CreateFunctionWithBody(C,buf, args...;
filename = filename, line = line, col = col)
Expand All @@ -43,9 +42,8 @@ macro icxxdebug_str(str,args...)
if isempty(args)
args = (Symbol(""),1,1)
end
push!(sourcebuffers,(takebuf_string(sourcebuf),args...))
id = length(sourcebuffers)
esc(build_icxx_expr(id, exprs, isexprs, Any[], compiler, dumpast_impl))
SB = SourceBuf{Symbol(takebuf_string(sourcebuf)), Symbol(args[1]), args[2:end]...}()
esc(build_icxx_expr(SB, exprs, isexprs, Any[], compiler, dumpast_impl))
end

function collectSymbolsForExport(RD::pcpp"clang::CXXRecordDecl")
Expand Down

0 comments on commit 1c1b72b

Please sign in to comment.