# Phase that assign a `FFILanguage` to all `AExternCodeBlock`
#
# It will also report errors when using an unknown foreign langages.
class FFILanguageAssignationPhase
super Phase
# All supported languages
var languages = new Array[FFILanguage]
redef fun process_nmodule(nmodule)
do
for block in nmodule.n_extern_code_blocks do
verify_foreign_code_on_node( block )
end
end
redef fun process_npropdef(npropdef)
do
if npropdef isa AMethPropdef then
var code_block = npropdef.n_extern_code_block
if code_block != null then
verify_foreign_code_on_node( code_block )
end
end
end
redef fun process_nclassdef(nclassdef)
do
if nclassdef isa AStdClassdef and nclassdef.n_extern_code_block != null then
verify_foreign_code_on_node( nclassdef.n_extern_code_block.as(not null) )
end
end
private fun verify_foreign_code_on_node(n: AExternCodeBlock)
do
var found = false
for v in languages do
var identified = v.identify_language(n)
if identified then
if found and identified then
toolcontext.error(n.location, "FFI Error: two languages identified as possible handlers.")
end
n.language = v
found = true
end
end
if not found then toolcontext.error(n.location, "FFI Error: unsupported language.")
end
end
src/ffi/light_ffi_base.nit:30,1--79,3