text:
using Test
using PETSc, MPI, LinearAlgebra, SparseArrays

MPI.Init()
PETSc.initialize()

# Constructs the central finite-difference approximation of -∇² for an lx×ly box of nx×ny points
# with Dirichlet boundary conditions. Based on the code from
# http://math.mit.edu/~stevenj/18.303/lecture-10.html
function laplace(T, nx::Integer, ny::Integer=nx, lx::Integer=1, ly::Integer=lx)
    dx = T(lx) / T(nx + 1)
    dy = T(ly) / T(ny + 1)
    Dx = [[one(T) spzeros(T, 1, nx - 1)]; spdiagm(1=>ones(T, nx - 1)) - I] / dx
    Dy = [[one(T) spzeros(T, 1, ny - 1)]; spdiagm(1=>ones(T, ny - 1)) - I] / dy
    Ax = Dx' * Dx
    Ay = Dy' * Dy
    A = kron(sparse(I, ny, ny), Ax) + kron(Ay, sparse(I, nx, nx))
    return A
end

T = Float64
nx = 20
S = laplace(T, nx)

m, n = size(S)
M = PETSc.MatSeqAIJ(S)

ksp = PETSc.KSP(
    M;
    ksp_monitor_true_residual = true,
    ksp_view = true,
    ksp_type = "cg",
    ksp_rtol = 1e-8,
    pc_type = "gamg",
    # I think these are not being set properly:
    mg_levels_ksp_type = "chebyshev",
    mg_levels_ksp_max_it = 3,
    mg_levels_pc_type = "bjacobi",
    mg_levels_sub_pc_type = "icc",
    mg_coarse_ksp_type = "preonly",
    mg_coarse_pc_type = "cholesky",
)

# initial guess
x = PETSc.VecSeq(zeros(m))
b = PETSc.VecSeq(randn(n))
PETSc.solve!(x, ksp, b)

PETSc.destroy(ksp)
PETSc.destroy(M)
PETSc.destroy(b)
PETSc.destroy(x)

PETSc.finalize()


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

@doc raw"""Represents a Glusterfs mount that lasts the lifetime of a pod. Glusterfs volumes do not support ownership management or SELinux relabeling.

    IoK8sApiCoreV1GlusterfsPersistentVolumeSource(;
        endpoints=nothing,
        endpointsNamespace=nothing,
        path=nothing,
        readOnly=nothing,
    )

    - endpoints::String : EndpointsName is the endpoint name that details Glusterfs topology. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod
    - endpointsNamespace::String : EndpointsNamespace is the namespace that contains Glusterfs endpoint. If this field is empty, the EndpointNamespace defaults to the same namespace as the bound PVC. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod
    - path::String : Path is the Glusterfs volume path. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod
    - readOnly::Bool : ReadOnly here will force the Glusterfs volume to be mounted with read-only permissions. Defaults to false. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod
"""
mutable struct IoK8sApiCoreV1GlusterfsPersistentVolumeSource <: SwaggerModel
    endpoints::Any # spec type: Union{ Nothing, String } # spec name: endpoints
    endpointsNamespace::Any # spec type: Union{ Nothing, String } # spec name: endpointsNamespace
    path::Any # spec type: Union{ Nothing, String } # spec name: path
    readOnly::Any # spec type: Union{ Nothing, Bool } # spec name: readOnly

    function IoK8sApiCoreV1GlusterfsPersistentVolumeSource(;endpoints=nothing, endpointsNamespace=nothing, path=nothing, readOnly=nothing)
        o = new()
        validate_property(IoK8sApiCoreV1GlusterfsPersistentVolumeSource, Symbol("endpoints"), endpoints)
        setfield!(o, Symbol("endpoints"), endpoints)
        validate_property(IoK8sApiCoreV1GlusterfsPersistentVolumeSource, Symbol("endpointsNamespace"), endpointsNamespace)
        setfield!(o, Symbol("endpointsNamespace"), endpointsNamespace)
        validate_property(IoK8sApiCoreV1GlusterfsPersistentVolumeSource, Symbol("path"), path)
        setfield!(o, Symbol("path"), path)
        validate_property(IoK8sApiCoreV1GlusterfsPersistentVolumeSource, Symbol("readOnly"), readOnly)
        setfield!(o, Symbol("readOnly"), readOnly)
        o
    end
end # type IoK8sApiCoreV1GlusterfsPersistentVolumeSource

const _property_map_IoK8sApiCoreV1GlusterfsPersistentVolumeSource = Dict{Symbol,Symbol}(Symbol("endpoints")=>Symbol("endpoints"), Symbol("endpointsNamespace")=>Symbol("endpointsNamespace"), Symbol("path")=>Symbol("path"), Symbol("readOnly")=>Symbol("readOnly"))
const _property_types_IoK8sApiCoreV1GlusterfsPersistentVolumeSource = Dict{Symbol,String}(Symbol("endpoints")=>"String", Symbol("endpointsNamespace")=>"String", Symbol("path")=>"String", Symbol("readOnly")=>"Bool")
Base.propertynames(::Type{ IoK8sApiCoreV1GlusterfsPersistentVolumeSource }) = collect(keys(_property_map_IoK8sApiCoreV1GlusterfsPersistentVolumeSource))
Swagger.property_type(::Type{ IoK8sApiCoreV1GlusterfsPersistentVolumeSource }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApiCoreV1GlusterfsPersistentVolumeSource[name]))}
Swagger.field_name(::Type{ IoK8sApiCoreV1GlusterfsPersistentVolumeSource }, property_name::Symbol) =  _property_map_IoK8sApiCoreV1GlusterfsPersistentVolumeSource[property_name]

function check_required(o::IoK8sApiCoreV1GlusterfsPersistentVolumeSource)
    (getproperty(o, Symbol("endpoints")) === nothing) && (return false)
    (getproperty(o, Symbol("path")) === nothing) && (return false)
    true
end

function validate_property(::Type{ IoK8sApiCoreV1GlusterfsPersistentVolumeSource }, name::Symbol, val)
end

ext: jl


text:
#
# Shows real time status of current Manager
# TODO: explain all parameters
#
# @author DeadbraiN
#
module Status
  import ManagerTypes.ManagerData
  import ManagerTypes.Plugin
  import ManagerTypes.OrganismTask
  import ManagerTypes
  import Creature
  import Config
  import Event
  import Formatting.format

  export init
  #
  # Name of the current module
  #
  const MODULE_NAME = string(Status)
  #
  # Contains real time status data like IPS, RPS,...
  #
  type StatusData <: Plugin
    stamp::Float64    # current UNIX time stamp
    ips::Float64      # average IPS
    ipsAmount::Int    # amount of IPS calculations per status period
    rps::Int          # all requests per second
    eups::Int         # energy updates per second
    kops::Int         # killed organisms per second
    ytps::Int         # one side yieldto() calls per second
    yps::Int          # all yields per second
    cps::Int          # clones per second
    srps::Int         # moveXXX() related requests per second
    syps::Int         # moveXXX() related yields per second
    mps::Int          # mutations per second
    cmps::Int         # amount of mutations on clone
    energy::Int       # energy of organisms
    eMin::Int         # minimum organism energy
    eMax::Int         # maximum organism energy
    evals::Int        # amount of eval() calls till previous status
    csMin::Int        # minimum organism code size
    csMax::Int        # maximum organism code size
    code::Int         # average code size
    eatl::Int         # organism eats left
    eatr::Int         # organism eats right
    eatu::Int         # organism eats up
    eatd::Int         # organism eats down
    eatorg::Int       # amount of energy obtained by eating other organisms
    eate::Int         # amount of energy eated by organisms
    eated::Int        # total amount of eating for organisms
    stepl::Int        # organism moves left
    stepr::Int        # organism moves right
    stepu::Int        # organism moves up
    stepd::Int        # organism moves down
    steps::Int        # total amount of moving in population
    grabbed::Int      # amount of energy grabbed by the system from population
    orgs::Int         # average amount of organisms
    fit::UInt         # Fitness level (energy * mutationsFromStart)
  end
  #
  # Module initializer
  #
  function init(man::ManagerData)
    #
    # We havr to add ourself to plugins map
    #
    man.plugins[MODULE_NAME] = StatusData(0.0,0.0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,UInt(0), 0)
    #
    # All event handlers should be binded here
    #
    Event.on(man.obs, "ips", _onIps)

    Event.on(man.obs, "request", _onRequest)
    Event.on(man.obs, "updateenergy", _onUpdateEnergy)
    Event.on(man.obs, "killorganism", _onKillOrganism)
    Event.on(man.obs, "mutations", _onMutations)
    Event.on(man.obs, "clone", _onClone)
    Event.on(man.obs, "dotrequest", _onDotRequest)
    Event.on(man.obs, "organism", _onOrganism)
    Event.on(man.obs, "grabenergy", _onGrabEnergy)

    Event.on(man.obs, "eatorganism", _onEatOrganism)
    Event.on(man.obs, "eatenergy", _onEatEnergy)
    Event.on(man.obs, "eatleft", _onEatLeft)
    Event.on(man.obs, "eatright", _onEatRight)
    Event.on(man.obs, "eatup", _onEatUp)
    Event.on(man.obs, "eatdown", _onEatDown)

    Event.on(man.obs, "stepleft", _onStepLeft)
    Event.on(man.obs, "stepright", _onStepRight)
    Event.on(man.obs, "stepup", _onStepUp)
    Event.on(man.obs, "stepdown", _onStepDown)
  end
  #
  # Is called at the beginning of _onIps
  #
  function _onBeforeIps(man::ManagerData, sd::StatusData)
    sd.ips       += man.ips
    sd.orgs      += ManagerTypes.orgAmount(man)
    sd.ipsAmount += 1
    #
    # Condition for the first run
    #
    if man.cfg.orgEvals < 1 sd.evals = man.cfg.orgEvals end
    #
    # Energy should be calculated here in IPS method, because it's slow
    #
    _iterateOrganisms(man, sd)
  end
  #
  # Shows real time status obtained from StatusData type
  # @param man Manager data type object
  # @param stamp Current time stamp
  #
  function _onIps(man::ManagerData, stamp::Float64, codeRuns::Int)
    local sd::StatusData  = man.plugins[MODULE_NAME]
    local cfg::Config.ConfigData = man.cfg
    local orgs::Int
    local orgsIps::Int
    local ips::Float64

    _onBeforeIps(man, sd)
    if stamp - sd.stamp < cfg.modeStatusPeriod return nothing end

    ips      = sd.ips / sd.ipsAmount
    orgs     = div(sd.orgs, sd.ipsAmount)
    orgsIps  = div(orgs, ips)

    if orgs < 1 orgs = 1 end
    if orgsIps < 1 orgsIps = 1 end
    print(string(Dates.format(now(), "HH:MM:SS"), " "))
    _showParam(:green,  "org:",  orgs, 8)
    _showParam(:normal, "ips:",  (@sprintf "%.2f" ips), 11)
    _showParam(:green,  "nrg:",  div(sd.energy, sd.ipsAmount * orgsIps), 14, true)
    _showParam(:red,    "eat:",  div(sd.eate, orgs), 12, true)
    _showParam(:red,    "eato:", div(sd.eatorg, orgs), 14, true)
    _showParam(:red,    "grab:", div(sd.grabbed, orgs), 14, true)
    _showParam(:cyan,   "step:", div(sd.steps, orgs), 14, true)
    _showParam(:orange, "cmut:", (@sprintf "%.2f" sd.cmps / orgs), 11)
    _showParam(:orange, "mut:",  (@sprintf "%.2f" sd.mps  / orgs), 10)
    _showParam(:yellow, "kil:",  (@sprintf "%.2f" sd.kops / orgs), 10)
    _showParam(:yellow, "clon:", (@sprintf "%.2f" sd.cps  / orgs), 11)
    _showParam(:orange, "err:",  div(cfg.orgErrors, orgs), 14, true)
    _showParam(:orange, "cod:",  div(sd.code, sd.ipsAmount * orgs), 8)
    _showParam(:red,    "fit:",  round(Int, sd.fit / (sd.ipsAmount * orgs)), 16, true)
    print("\n")

    _onAfterIps(man, stamp, sd)
  end
  #
  # Is called at the end of _onIps() function
  #
  function _onAfterIps(man::ManagerData, stamp::Float64, sd::StatusData)
    sd.stamp      = stamp
    sd.ips        = 0.0
    sd.ipsAmount  = 0
    sd.ytps       = 0
    sd.yps        = 0
    sd.cps        = 0
    sd.eups       = 0
    sd.kops       = 0
    sd.rps        = 0
    sd.syps       = 0
    sd.srps       = 0
    sd.mps        = 0
    sd.cmps       = 0
    sd.eMin       = typemax(Int)
    sd.eMax       = 0
    sd.csMin      = typemax(Int)
    sd.csMax      = 0
    sd.code       = 0
    sd.evals      = man.cfg.orgEvals
    sd.eatl       = 0
    sd.eatr       = 0
    sd.eatu       = 0
    sd.eatd       = 0
    sd.eatorg     = 0
    sd.eate       = 0
    sd.eated      = 0
    sd.grabbed    = 0
    sd.stepl      = 0
    sd.stepr      = 0
    sd.stepu      = 0
    sd.stepd      = 0
    sd.steps      = 0
    sd.energy     = 0
    sd.orgs       = 0
    sd.fit        = UInt(0)
  end
  #
  # Calculates total energy of population
  # @param man Manager data type
  # @param sd Structure of status line
  #
  function _iterateOrganisms(man::ManagerData, sd::StatusData)
    local task::OrganismTask
    local org::Creature.Organism
    local i::Int

    @inbounds for i = 1:length(man.tasks)
      org = man.tasks[i].organism
      if !org.alive continue end
      sd.energy += org.energy
      sd.code   += org.codeSize
      #
      # Fitness level
      #
      sd.fit += UInt(org.energy) * UInt(org.mutationsFromStart)
    end
  end
  #
  # Shows one parameter in status line accordint to settings
  #
  function _showParam(color::Symbol, name::String, val::Any, width::Int, formatComas::Bool = false)
    if formatComas print_with_color(color, rpad(string(name, format(val, commas = true)), width))
    else print_with_color(color, rpad(string(name, val), width))
    end
  end
  #
  # Calls if yield() in Manager is called
  # @param man Manager data type object
  #
  function _onYield(man::ManagerData)
    man.plugins[MODULE_NAME].yps += 1
  end
  #
  # Calls if yieldto() in Manager is called
  # @param man Manager data type object
  #
  function _onYieldTo(man::ManagerData)
    man.plugins[MODULE_NAME].ytps += 1
  end
  #
  # Calls if request in Manager has sent
  # @param man Manager data type object
  #
  function _onRequest(man::ManagerData)
    man.plugins[MODULE_NAME].rps += 1
  end
  #
  # Calls if organisms energy was updated
  # @param man Manager data type object
  #
  function _onUpdateEnergy(man::ManagerData)
    man.plugins[MODULE_NAME].eups += 1
  end
  #
  # Calls if one organism was killed
  # @param man Manager data type object
  # @param org Killed organism
  #
  function _onKillOrganism(man::ManagerData, org::Creature.Organism)
    man.plugins[MODULE_NAME].kops += 1
  end
  #
  # Calculates amount of mutations for specified organism
  # @param man Manager related data object
  # @param org Organism we have to add to the pool
  # @param amount Amount of real mutations
  # @param onClone true if current mutations were applied on clonning
  # of organism and not as a rain mutations
  #
  function _onMutations(man::ManagerData, org::Creature.Organism, amount::Int, onClone::Bool)
    man.plugins[MODULE_NAME].mps += amount
    if onClone man.plugins[MODULE_NAME].cmps += amount end
  end
  #
  # Handles organism clonning
  # @param man Manager related data object
  # @param parentId Unique id of parent organism
  # @param childId Unique id of child organism
  #
  function _onClone(man::ManagerData, parentId::UInt, childId::UInt)
    man.plugins[MODULE_NAME].cps += 1
  end
  #
  # Handles one dot request
  # @param man Manager related data object
  #
  function _onDotRequest(man::ManagerData)
    man.plugins[MODULE_NAME].rps  += 1
    man.plugins[MODULE_NAME].srps += 1
  end
  #
  # Handles one "stepyield" event. It means, that yield() was called
  # for one organism step.
  # @param man Manager related data object
  #
  function _onStepYield(man::ManagerData)
    man.plugins[MODULE_NAME].yps  += 1
    man.plugins[MODULE_NAME].syps += 1
  end
  #
  # Handles "organism" event. Means, that one organism has processed (runned)
  # @param man Manager related data object
  # @param org Organism
  #
  function _onOrganism(man::ManagerData, org::Creature.Organism)
    local sd::StatusData = man.plugins[MODULE_NAME]
    #
    # Finds min/max energetic organisms in population
    #
    if org.energy < sd.eMin sd.eMin = org.energy end
    if org.energy >= sd.eMax sd.eMax = org.energy end
    #
    # Updates min/max code sizes
    #
    #if org.codeSize >  sd.csMax sd.csMax = org.codeSize end
    #if org.codeSize <= sd.csMin sd.csMin = org.codeSize end
  end
  #
  # Is called on enery grab of energy from organism
  # @param man Manager related data object
  # @param amount Amount of grabbed energy
  #
  function _onGrabEnergy(man::ManagerData, amount::Int)
    man.plugins[MODULE_NAME].grabbed += amount
  end
  #
  # Handler of "eatorganism" event
  # @param man Manager data type
  # @param eated Amount of energy obteined by eating of other organism
  #
  function _onEatOrganism(man::ManagerData, eated::Int)
    man.plugins[MODULE_NAME].eatorg += eated
  end
  #
  # Handler of "eatenergy" event
  # @param man Manager data type
  # @param eated Amount of energy obteined by eating of energy
  #
  function _onEatEnergy(man::ManagerData, eated::Int)
    man.plugins[MODULE_NAME].eate += eated
  end
  #
  # Is called every time if some organism calls eatLeft() function
  # @param man Manager data type
  # @param org Organism, who is eating
  # @param amount Amount of wanted eating (bite)
  # @param eated Amount of eated energy
  #
  function _onEatLeft(man::ManagerData, org::Creature.Organism, amount::Int, eated::Int)
    local sd::StatusData = man.plugins[MODULE_NAME]

    sd.eatl  += eated
    sd.eated += eated
  end
  #
  # Is called every time if some organism calls eatRight() function
  # @param man Manager data type
  # @param org Organism, who is eating
  # @param amount Amount of wanted eating (bite)
  # @param eated Amount of eated energy
  #
  function _onEatRight(man::ManagerData, org::Creature.Organism, amount::Int, eated::Int)
    local sd::StatusData = man.plugins[MODULE_NAME]

    sd.eatr  += eated
    sd.eated += eated
  end
  #
  # Is called every time if some organism calls eatUp() function
  # @param man Manager data type
  # @param org Organism, who is eating
  # @param amount Amount of wanted eating (bite)
  # @param eated Amount of eated energy
  #
  function _onEatUp(man::ManagerData, org::Creature.Organism, amount::Int, eated::Int)
    local sd::StatusData = man.plugins[MODULE_NAME]

    sd.eatu  += eated
    sd.eated += eated
  end
  #
  # Is called every time if some organism calls eatDown() function
  # @param man Manager data type
  # @param org Organism, who is eating
  # @param amount Amount of wanted eating (bite)
  # @param eated Amount of eated energy
  #
  function _onEatDown(man::ManagerData, org::Creature.Organism, amount::Int, eated::Int)
    local sd::StatusData = man.plugins[MODULE_NAME]

    sd.eatd  += eated
    sd.eated += eated
  end
  #
  # Is called every time if some organism calls stepLeft() function
  # @param man Manager data type
  # @param org Organism, who is moving
  # @param stepDone Is step was successful or not
  #
  function _onStepLeft(man::ManagerData, org::Creature.Organism, stepDone::Bool)
    local sd::StatusData = man.plugins[MODULE_NAME]

    if stepDone
      sd.stepl += 1
      sd.steps += 1
    end
  end
  #
  # Is called every time if some organism calls stepRight() function
  # @param man Manager data type
  # @param org Organism, who is moving
  # @param stepDone Is step was successful or not
  #
  function _onStepRight(man::ManagerData, org::Creature.Organism, stepDone::Bool)
    local sd::StatusData = man.plugins[MODULE_NAME]

    if stepDone
      sd.stepr += 1
      sd.steps += 1
    end
  end
  #
  # Is called every time if some organism calls stepUp() function
  # @param man Manager data type
  # @param org Organism, who is moving
  # @param stepDone Is step was successful or not
  #
  function _onStepUp(man::ManagerData, org::Creature.Organism, stepDone::Bool)
    local sd::StatusData = man.plugins[MODULE_NAME]

    if stepDone
      sd.stepu += 1
      sd.steps += 1
    end
  end
  #
  # Is called every time if some organism calls stepDown() function
  # @param man Manager data type
  # @param org Organism, who is moving
  # @param stepDone Is step was successful or not
  #
  function _onStepDown(man::ManagerData, org::Creature.Organism, stepDone::Bool)
    local sd::StatusData = man.plugins[MODULE_NAME]

    if stepDone
      sd.stepd += 1
      sd.steps += 1
    end
  end
end

# if cfg.modeStatusFull
#   print_with_color(:red,   rpad(string("eat:",    sd.eatl),                        11))
#   print_with_color(:red,   rpad(string(sd.eatr),                                    8))
#   print_with_color(:red,   rpad(string(sd.eatu),                                    8))
#   print_with_color(:red,   rpad(string(sd.eatd),                                    8))
#   print_with_color(:red,   rpad(string(format(sd.eated, commas=true)),             10))
# end
# if cfg.modeStatusFull
#   print_with_color(:red, rpad(string("step:", sd.stepl),                           11))
#   print_with_color(:red, rpad(string(sd.stepr),                                     6))
#   print_with_color(:red, rpad(string(sd.stepu),                                     6))
#   print_with_color(:red, rpad(string(sd.stepd),                                     6))
#   print_with_color(:red, rpad(string(format(sd.steps, commas=true)),               10))
# end
# if cfg.modeStatusFull
#   print_with_color(:yellow,  rpad(string("sreq:",   div(sd.srps, ips)),                       9))
#   print_with_color(:yellow,  rpad(string("enup:",   div(sd.eups, ips)),                       8))
# end
# if cfg.modeStatusFull
#   print_with_color(:orange,    rpad(string("code:",   sd.csMin),                   12))
#   print_with_color(:orange,    rpad(string(sd.csMax),                               7))
# end
# if cfg.modeStatusFull
#   print_with_color(:orange,    rpad(string("nrg:",    sd.eMin),                    11))
#   print_with_color(:orange,    rpad(string(format(sd.eMax, commas=true)),            7), "\n")
# end
#print_with_color(:red,    rpad(string("ytps:",   sd.ytps)), 11))
#print_with_color(:red,    rpad(string("yps:",    sd.yps)),  9))
#print_with_color(:red,    rpad(string("syps:",   sd.syps)),  9))

max_stars_repo_name: tmptrash/jevo

max_issues_repo_name: tmptrash/jevo

max_forks_repo_name: tmptrash/jevo


text:
mutable struct TreeGrid{N} <: AbstractGrid{N}
    tree::Tree{N}
    nr_cells::Int
    nr_faces::Int

    cells::Vector{Tree{N}}
    faces::Vector{Face{N}}

    cells_level_start::Vector{Int}
    faces_level_start::Vector{Int}
end

@inline function TreeGrid(position::Vector; periodic = fill(false, length(position)))
    if isa(periodic, Bool) periodic = fill(periodic, length(position)) end
    tmp = 0
    N = length(position)
    grid = TreeGrid(Tree(position, periodic = periodic, cell_state = cell -> Ref(1), face_state = face -> Ref(tmp += 1)), 1, 4 - count(periodic), fill(Tree{N}(), 0), fill(Face{N}(), 0), zeros(Int64, 0), zeros(Int64, 0))

    update_cells!(grid)
    update_faces!(grid)
    update_indices!(grid)
    grid
end

@inline cells(grid::TreeGrid; filter = _ -> true) = Base.filter(filter, grid.cells)
@inline faces(grid::TreeGrid; filter = _ -> true) = Base.filter(filter, grid.faces)

# @inline function refine!(grid::TreeGrid{N}, cell::Tree{N}; recurse = false) where N
#     FullyThreadedTree.refine!(cell, cell_state = cell -> cell_incrementer!(grid), face_state = face -> face_incrementer!(grid), recurse = recurse)
#     # NB  Refine does not remove any cells/faces
# end

@inline function refine!(grid::TreeGrid{N}, cells::Vector{Tree{N}}; recurse = false, issorted = false) where N
    FullyThreadedTree.refine!(cells, cell_state = cell -> cell_incrementer!(grid), face_state = face -> face_incrementer!(grid), recurse = recurse, issorted = issorted)

    update_cells!(grid)
    update_faces!(grid)
    update_indices!(grid)
end

@inline function coarsen!(grid::TreeGrid{N}, cells::Vector{Tree{N}}) where N
    FullyThreadedTree.coarsen!(cells, face_state = face -> face_incrementer!(grid))

    update_cells!(grid)
    update_faces!(grid)
    update_indices!(grid)
end

@inline cell_incrementer!(grid::TreeGrid) = Ref(grid.nr_cells += 1)
@inline face_incrementer!(grid::TreeGrid) = Ref(grid.nr_faces += 1)

function update_cells!(grid::TreeGrid)
    grid.cells = FullyThreadedTree.collect_cells(grid.tree)
    sort!(grid.cells, by = level)
end
function update_faces!(grid::TreeGrid)
    grid.faces = FullyThreadedTree.collect_faces(grid.tree)
    sort!(grid.faces, by = level)
end

function update_indices!(grid::TreeGrid)
    grid.nr_cells = 0
    current_level = 0
    grid.cells_level_start = zeros(Int, level(grid.cells[end]))
    for cell ∈ grid.cells
        cell.state.x = grid.nr_cells += 1
        if level(cell) > current_level
            current_level = current_level + 1
            grid.cells_level_start[current_level] = grid.nr_cells
        end
    end

    grid.nr_faces = 0
    current_level = 0
    grid.faces_level_start = zeros(Int, level(grid.faces[end]))
    for face ∈ grid.faces
        face.state.x = grid.nr_faces += 1
        if level(face) > current_level
            current_level = current_level + 1
            grid.faces_level_start[current_level] = grid.nr_faces
        end
    end
end
@inline index(cell::Tree) = cell.state.x
@inline index(face::Face) = face.state.x

# TODO this does not work with periodicity at level 0
function normal_sign(cell::Tree, face::Face)
    if at_boundary(face)
        return active(face.cells[1]) ? +1 : -1
    else#if !at_refinement(face)
        return index(cell) == index(face.cells[1]) ? +1 : -1
    # else
    #     return level(cell) == level(face.cells[1]) ? +1 : -1
    end
end
@inline direction(face::Face) = face.face_direction


text:
int main)( {
        return 0;
        return 1;
}

max_stars_repo_name: jwilk/jtc

max_issues_repo_name: jwilk/jtc

max_forks_repo_name: jwilk/jtc


text:
# Use baremodule to shave off a few KB from the serialized `.ji` file
baremodule xsum_jll
using Base
using Base: UUID
import JLLWrappers

JLLWrappers.@generate_main_file_header("xsum")
JLLWrappers.@generate_main_file("xsum", UUID("e979a739-315a-50ee-b437-b496a9503be1"))
end  # module xsum_jll


text:
using RobustAndOptimalControl, ControlSystems, MonteCarloMeasurements, Plots
unsafe_comparisons(true)

using RobustAndOptimalControl: δr, δc

# example in section 3.7.1, spinning satellite
a = 10
P = ss([0 a; -a 0], I(2), [1 a; -a 1], 0)
K = ss(I(2))

w = 2π .* exp10.(LinRange(-2, 2, 500))
S, PS, CS, T = RobustAndOptimalControl.gangoffour2(P, K)
sigmaplot(S, w, lab="S")
sigmaplot!(T, w, c=2, lab="T", ylims=(0.01, 45))
# Both sensitivity functions are very large, expect a non-robust system!

## Parametric uncertainty
a = 10*(1 + δr(100))
P = ss([0 a; -a 0], I(2), [1 a; -a 1], 0)

Sp, PSp, CSp, Tp = RobustAndOptimalControl.gangoffour2(P, K)
sigmaplot(Sp, w, lab="S")
sigmaplot!(Tp, w, c=2, lab="T", ylims=(0.01, 45))
# Not only are sensitivity functions large, they vary a lot under the considered uncertainty

## Add complex diagonal multiplicative input uncertainty
# With input uncertainty of magnitude ϵ < 1 / σ̄(T) we are guaranteed robust stability (even for “full-block complex perturbations")
a = 10
P = ss([0 a; -a 0], I(2), [1 a; -a 1], 0)

W0 = makeweight(0.2, 2)
W = I(2) + W0 * diagm([δc(100), δc(100)])
Ps = P*W
Ss, PSs, CSs, Ts = RobustAndOptimalControl.gangoffour2(Ps, K)
sigmaplot(Ss, w, lab="S")
sigmaplot!(Ts, w, c=2, lab="T", ylims=(0.01, 45))
# Under this uncertainty, the sensitivity could potentially be sky high., note how some of the 100 realizations peak much higher than the others

##

# 3.7.2 Motivating robustness example no. 2: Distillation Process
M = [87.8 -86.4; 108.2 -109.6]
G = ss(tf(1, [75, 1])) * M
RGA = relative_gain_array(G, 0)
sum(abs, RGA) # A good estimate of the true condition number, which is 141.7
# large elments in the RGA indicate a process that is difficult to control

# We consider the following inverse-based controller, which may also be looked
# upon as a steady-state decoupler with a PI controlle
k1 = 0.7
Kinv = ss(tf(k1*[75, 1], [1, 0])) * inv(M)

# reference filter
F = tf(1, [5, 1])

sigmaplot(input_sensitivity(G, Kinv), w)
sigmaplot!(output_sensitivity(G, Kinv), w, c=2)
# Sensitivity looks nice, how about step response
plot(step(feedback(G*Kinv)*F, 20))
# Looks excellent..

# We consider again the input gain uncertainty as in the previous example,
# and we select ϵ1 = 0.2 and ϵ2 = 0.2. We then have
G′ = G * diagm([1 + 0.2, 1 - 0.2])
plot!(step(feedback(G′*Kinv)*F, 20), l=:dash)
# Looks very poor! The system was not robust to simultaneous input uncertainty!

# We can also do this with a complex, diagonal input uncertainty that grows with frequency
W0 = makeweight(0.2, 1, 2) # uncertainty goes from 20% at low frequencies to 200% at high frequencies
W = I(2) + W0 * diagm([δc(100), δc(100)])
Gs = G*W
res = step(c2d(feedback(Gs*Kinv)*F, 0.01), 20)
mcplot!(res.t, abs.(res.y[:, :, 1]'), alpha=0.3)
mcplot!(res.t, abs.(res.y[:, :, 2]'), alpha=0.3)
# The system is very sensitive to complex input uncertainty

# How about real input uncertainty?
W = I(2) + W0 * diagm([δr(100), δr(100)])
Gs = G*W

plot(step(feedback(G*Kinv)*F, 20))
plot!(step(feedback(G′*Kinv)*F, 20), l=:dash)
res = step(c2d(feedback(Gs*Kinv)*F, 0.01), 20)
mcplot!(res.t, abs.(res.y[:, :, 1]'), alpha=0.3)
mcplot!(res.t, abs.(res.y[:, :, 2]'), alpha=0.3)
# Also bad

Si = input_sensitivity(Gs, Kinv)
sigmaplot(Si, w, c=1, lab="Si")
So = output_sensitivity(Gs, Kinv)
sigmaplot!(So, w, c=2, lab="So")
# The sensitivity at the plant output is enormous. A low sensitivity with the nominal system does not guarantee robustness!


text:
using Sugar
using Base.Test

# write your own tests here
imagesc(randn(100, 120))
@test 1 == 1


text:
using Revise
using ADSeismic
using ADCME
using JLD2
ADCME.options.customop.verbose = false
mpi_init()
M = N = Int(sqrt(mpi_size()))
n = 100

param = MPIElasticPropagatorParams(NX= n * M, NY= n * N, n=n, NSTEP=2000, DELTAT=1e-4/2,
                        DELTAX=1.0, DELTAY=1.0)
compute_PML_Params!(param)
vp = 3300.
vs = 3300. / 1.732
rho = 2800.
λ, μ, ρ = compute_lame_parameters(param, vp, vs, rho)
source = Ricker(param, 50.0, 200.0)

srci = [div(param.NX,5)]
srcj = [div(param.NY,2)]
srctype = [0]
srcv = reshape(source, :, 1)
src = MPIElasticSource(param, srci, srcj, srctype, srcv)

rcvj = Array(20:n*param.M-19)
rcvi = ones(Int64, length(rcvj))*((n*param.N)÷5)
rcvtype = zeros(Int64, length(rcvj))
receiver =  MPIElasticReceiver(param, rcvi, rcvj, rcvtype)

propagator = MPIElasticPropagatorSolver(param, src, ρ, λ, μ)
MPISimulatedObservation!(propagator, receiver)

sess = Session(); init(sess)
@info "starting..."
rcvv, Vx = run(sess, [receiver.rcvv, propagator.vx])

@info "saving..."
@save "data/dat$(mpi_rank())-$(mpi_size()).jld2" rcvv

if mpi_size()>1
    mpi_finalize()
end
# if mpi_rank()==0 && mpi_size()==1
#     close("all")
#     pcolormesh(rcvv, cmap="gray")
#     colorbar()
#     xlabel("Location")
#     ylabel("Time")
#     savefig("receiver.png")

#     close("all")
#     visualize_wavefield(Vx, param)

# end


text:
@testset "pixel_shuffle" begin
    x = reshape(1:16, (2, 2, 4, 1))
    # [:, :, 1, 1] =
    #     1  3
    #     2  4
    # [:, :, 2, 1] =
    #     5  7
    #     6  8
    # [:, :, 3, 1] =
    #     9  11
    #     10  12
    # [:, :, 4, 1] =
    #     13  15
    #     14  16

    y_true = [1  9 3 11
              5 13 7 15
              2 10 4 12
              6 14 8 16][:,:,:,:]

    y = pixel_shuffle(x, 2)
    @test size(y) == size(y_true)
    @test y_true == y

    x = reshape(1:32, (2, 2, 8, 1))
    y_true = zeros(Int, 4, 4, 2, 1)
    y_true[:,:,1,1] .= [ 1   9  3  11
                         5  13  7  15
                         2  10  4  12
                         6  14  8  16 ]

    y_true[:,:,2,1] .= [ 17  25  19  27
                         21  29  23  31
                         18  26  20  28
                         22  30  24  32]

    y = pixel_shuffle(x, 2)
    @test size(y) == size(y_true)
    @test y_true == y

    x = reshape(1:4*3*27*2, (4,3,27,2))
    y = pixel_shuffle(x, 3)
    @test size(y) == (12, 9, 3, 2)
    # batch dimension is preserved
    x1 = x[:,:,:,[1]]
    x2 = x[:,:,:,[2]]
    y1 = pixel_shuffle(x1, 3)
    y2 = pixel_shuffle(x2, 3)
    @test cat(y1, y2, dims=4) == y

    for d in [1, 2, 3]
        r = rand(1:5)
        n = rand(1:5)
        c = rand(1:5)
        insize = rand(1:5, d)
        x = rand(insize..., r^d*c, n)

        y = pixel_shuffle(x, r)
        @test size(y) == ((r .* insize)..., c, n)

        gradtest(x -> pixel_shuffle(x, r), x)
    end
end


text:
#Test for integral
seed = rand(Int)
print_with_color(:green, "Testing integration")
print_with_color(:blue, "    using seed $seed\n")

max_len = 100
len = 2+abs(rand(Int))%(max_len-2)
knots = Float64[]

while length(knots) < len
	knots = sort(unique([(rand()*len)::Float64 for i in 1:len]))
end

values = [rand() for i in knots]

s = Spline(knots, values)

@test_approx_eq integral(s, knots[1], knots[end]) -1*integral(s, knots[end], knots[1])

k0 = rand(Int)%(len-1)
k1 = k0+1
x0 = s.knots[k0]
x1 = s.knots[k1]

@test_approx_eq integral(s, x0, x1) Splines.integrate_cubic(0.0, x1-x0, s.a[k0], s.b[k0], s.c[k0], s.d[k0])


text:
using BilevelJuMP
using Test, MathOptInterface, JuMP, Dualization
# using MathOptFormat

const MOI  = MathOptInterface
const MOIU = MathOptInterface.Utilities
const MOIB = MathOptInterface.Bridges
const MOIT = MathOptInterface.Test

# TODO
# add JUMPExtension test

solvers = NamedTuple{(:opt, :mode),Tuple{Any,Any}}[]
solvers_quad = NamedTuple{(:opt, :mode),Tuple{Any,Any}}[]

include("solvers/cbc.jl")
# include("solvers/gurobi.jl")

include("moi.jl")
include("jump.jl")

@testset "Simple LP" begin
    for solver in solvers
        moi_01(solver.opt)
    end
end

@testset "Simple BLP" begin
    for solver in solvers
        moi_02(solver.opt, solver.mode)
    end
end

@testset "Simple BLP2" begin
    for solver in solvers
        moi_03(solver.opt, solver.mode)
    end
end

@testset "Simple BLP JuMP" begin
    for solver in solvers
        jump_01(solver.opt, solver.mode)
    end
end

@testset "Simple BLP2 JuMP" begin
    for solver in solvers
        jump_02(solver.opt, solver.mode)
    end
end

@testset "Simple 3 JuMP" begin
    for solver in solvers
        jump_03(solver.opt, solver.mode)
    end
end

@testset "Simple 4 JuMP" begin
    for solver in solvers
        jump_04(solver.opt, solver.mode)
    end
end

@testset "Simple 5 JuMP" begin
    for solver in solvers
        jump_05(solver.opt, solver.mode)
    end
end

@testset "Simple 3SAT JuMP" begin
    for solver in solvers
        jump_3SAT(solver.opt, solver.mode)
    end
end

@testset "JuMP quad" begin
    for solver in solvers_quad
        jump_quad_01_a(solver.opt, solver.mode)
        jump_quad_01_b(solver.opt, solver.mode)
        jump_quad_01_c(solver.opt, solver.mode)
        jump_13_quad(solver.opt, solver.mode)
    end
end

@testset "Simple 6 JuMP" begin
    for solver in solvers
        jump_06(solver.opt, solver.mode)
    end
end

@testset "Simple 7 JuMP" begin
    for solver in solvers
        jump_07(solver.opt, solver.mode)
    end
end

@testset "Simple 8 JuMP" begin
    for solver in solvers
        jump_08(solver.opt, solver.mode)
    end
end

@testset "Simple 9 JuMP" begin
    for solver in solvers
        jump_09a(solver.opt, solver.mode)
        jump_09b(solver.opt, solver.mode)
    end
end

@testset "Simple 11 JuMP" begin
    for solver in solvers
        jump_11a(solver.opt, solver.mode)
        jump_11b(solver.opt, solver.mode)
    end
end

@testset "Simple 12 JuMP" begin
    for solver in solvers
        jump_12(solver.opt, solver.mode)
    end
end

@testset "Simple 14 JuMP" begin
    for solver in solvers
        jump_14(solver.opt, solver.mode)
    end
end

@testset "Princeton Handbook of Test Problems" begin
    for solver in solvers
        jump_HTP_lin01(solver.opt, solver.mode)
        jump_HTP_lin02(solver.opt, solver.mode)
        jump_HTP_lin03(solver.opt, solver.mode)
        jump_HTP_lin04(solver.opt, solver.mode)
        println("Skipping HTP linear 05")
        # jump_HTP_lin05(solver.opt, solver.mode) # broken on cbc linux on julia 1.0 and 1.2 but not 1.1 see: https://travis-ci.org/joaquimg/BilevelJuMP.jl/builds/619335351
        jump_HTP_lin06(solver.opt, solver.mode)
        jump_HTP_lin07(solver.opt, solver.mode)
        jump_HTP_lin08(solver.opt, solver.mode)
        jump_HTP_lin09(solver.opt, solver.mode)
        jump_HTP_lin10(solver.opt, solver.mode)
    end
end

@testset "Ferris educational" begin
    for solver in solvers
        jump_jointc1(solver.opt, solver.mode)
        jump_jointc2(solver.opt, solver.mode)
    end
end

@testset "Bard Efficient Point Example" begin
    for solver in solvers
        jump_EffPointAlgo(solver.opt, solver.mode)
    end
end

@testset "SemiRandom" begin
    for solver in solvers
        jump_SemiRand(solver.opt, solver.mode)
    end
end

@testset "DNE" begin
    for solver in solvers
        jump_DTMP_01(solver.opt, solver.mode)
    end
end

@testset "DNE - modifications" begin
    for solver in solvers
        jump_DTMP_01_mod1(solver.opt, solver.mode)
        jump_DTMP_01_mod2_error(solver.opt, solver.mode)
    end
end


text:
using KLIEPInference
using JLD

file = jldopen("../exper1/graphs/chain1_25.jld", "r")
γy = pack(read(file, "Θy"))
close(file)

# setting 1. (none)
idx0 = KLIEPInference.trimap(5, 6)
for δ in -0.75:0.05:0.75
    γx = deepcopy(γy)
    γx[idx0] += δ
    @save "graphs/params_exp2_set1_$(δ).jld" γx γy
end

# setting 2. (strong)
idx1 = KLIEPInference.trimap(4, 5)
idx2 = KLIEPInference.trimap(6, 7)
for δ in -0.75:0.05:0.75
    γx = deepcopy(γy)
    γx[idx0] += δ
    γx[idx1] += 0.4
    γx[idx2] -= 0.4
    @save "graphs/params_exp2_set2_$(δ).jld" γx γy
end

# setting 3. (weak)
idx3 = KLIEPInference.trimap(4, 6)
idx4 = KLIEPInference.trimap(5, 7)
for δ in -0.75:0.05:0.75
    γx = deepcopy(γy)
    γx[idx0] += δ
    γx[idx3] += 0.2
    γx[idx4] += 0.2
    @save "graphs/params_exp2_set3_$(δ).jld" γx γy
end

# setting 4. (mixed)
for δ in -0.75:0.05:0.75
    γx = deepcopy(γy)
    γx[idx0] += δ
    γx[idx1] += 0.4
    γx[idx2] -= 0.4
    γx[idx3] += 0.2
    γx[idx4] += 0.2
    @save "graphs/params_exp2_set4_$(δ).jld" γx γy
end


text:
# Julia wrapper for header: BuildSystem.h
# Automatically generated using Clang.jl

function clang_getBuildSessionTimestamp()
    ccall((:clang_getBuildSessionTimestamp, libclang), Culonglong, ())
end

function clang_VirtualFileOverlay_create(options)
    ccall((:clang_VirtualFileOverlay_create, libclang), CXVirtualFileOverlay, (UInt32,), options)
end

function clang_VirtualFileOverlay_addFileMapping(arg1, virtualPath, realPath)
    ccall((:clang_VirtualFileOverlay_addFileMapping, libclang), CXErrorCode, (CXVirtualFileOverlay, Cstring, Cstring), arg1, virtualPath, realPath)
end

function clang_VirtualFileOverlay_setCaseSensitivity(arg1, caseSensitive)
    ccall((:clang_VirtualFileOverlay_setCaseSensitivity, libclang), CXErrorCode, (CXVirtualFileOverlay, Cint), arg1, caseSensitive)
end

function clang_VirtualFileOverlay_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
    ccall((:clang_VirtualFileOverlay_writeToBuffer, libclang), CXErrorCode, (CXVirtualFileOverlay, UInt32, Ptr{Cstring}, Ptr{UInt32}), arg1, options, out_buffer_ptr, out_buffer_size)
end

function clang_free(buffer)
    ccall((:clang_free, libclang), Cvoid, (Ptr{Cvoid},), buffer)
end

function clang_VirtualFileOverlay_dispose(arg1)
    ccall((:clang_VirtualFileOverlay_dispose, libclang), Cvoid, (CXVirtualFileOverlay,), arg1)
end

function clang_ModuleMapDescriptor_create(options)
    ccall((:clang_ModuleMapDescriptor_create, libclang), CXModuleMapDescriptor, (UInt32,), options)
end

function clang_ModuleMapDescriptor_setFrameworkModuleName(arg1, name)
    ccall((:clang_ModuleMapDescriptor_setFrameworkModuleName, libclang), CXErrorCode, (CXModuleMapDescriptor, Cstring), arg1, name)
end

function clang_ModuleMapDescriptor_setUmbrellaHeader(arg1, name)
    ccall((:clang_ModuleMapDescriptor_setUmbrellaHeader, libclang), CXErrorCode, (CXModuleMapDescriptor, Cstring), arg1, name)
end

function clang_ModuleMapDescriptor_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
    ccall((:clang_ModuleMapDescriptor_writeToBuffer, libclang), CXErrorCode, (CXModuleMapDescriptor, UInt32, Ptr{Cstring}, Ptr{UInt32}), arg1, options, out_buffer_ptr, out_buffer_size)
end

function clang_ModuleMapDescriptor_dispose(arg1)
    ccall((:clang_ModuleMapDescriptor_dispose, libclang), Cvoid, (CXModuleMapDescriptor,), arg1)
end
# Julia wrapper for header: CXCompilationDatabase.h
# Automatically generated using Clang.jl

function clang_CompilationDatabase_fromDirectory(BuildDir, ErrorCode)
    ccall((:clang_CompilationDatabase_fromDirectory, libclang), CXCompilationDatabase, (Cstring, Ptr{CXCompilationDatabase_Error}), BuildDir, ErrorCode)
end

function clang_CompilationDatabase_dispose(arg1)
    ccall((:clang_CompilationDatabase_dispose, libclang), Cvoid, (CXCompilationDatabase,), arg1)
end

function clang_CompilationDatabase_getCompileCommands(arg1, CompleteFileName)
    ccall((:clang_CompilationDatabase_getCompileCommands, libclang), CXCompileCommands, (CXCompilationDatabase, Cstring), arg1, CompleteFileName)
end

function clang_CompilationDatabase_getAllCompileCommands(arg1)
    ccall((:clang_CompilationDatabase_getAllCompileCommands, libclang), CXCompileCommands, (CXCompilationDatabase,), arg1)
end

function clang_CompileCommands_dispose(arg1)
    ccall((:clang_CompileCommands_dispose, libclang), Cvoid, (CXCompileCommands,), arg1)
end

function clang_CompileCommands_getSize(arg1)
    ccall((:clang_CompileCommands_getSize, libclang), UInt32, (CXCompileCommands,), arg1)
end

function clang_CompileCommands_getCommand(arg1, I)
    ccall((:clang_CompileCommands_getCommand, libclang), CXCompileCommand, (CXCompileCommands, UInt32), arg1, I)
end

function clang_CompileCommand_getDirectory(arg1)
    ccall((:clang_CompileCommand_getDirectory, libclang), CXString, (CXCompileCommand,), arg1)
end

function clang_CompileCommand_getFilename(arg1)
    ccall((:clang_CompileCommand_getFilename, libclang), CXString, (CXCompileCommand,), arg1)
end

function clang_CompileCommand_getNumArgs(arg1)
    ccall((:clang_CompileCommand_getNumArgs, libclang), UInt32, (CXCompileCommand,), arg1)
end

function clang_CompileCommand_getArg(arg1, I)
    ccall((:clang_CompileCommand_getArg, libclang), CXString, (CXCompileCommand, UInt32), arg1, I)
end

function clang_CompileCommand_getMappedSourcePath(arg1, I)
    @warn "`clang_CompileCommand_getMappedSourcePath` Left here for backward compatibility.\nNo mapped sources exists in the C++ backend anymore.\nThis function just return Null `CXString`.\n\nSee:\n- [Remove unused CompilationDatabase::MappedSources](https://reviews.llvm.org/D32351)\n"
    ccall((:clang_CompileCommand_getMappedSourcePath, libclang), CXString, (CXCompileCommand, UInt32), arg1, I)
end

function clang_CompileCommand_getMappedSourceContent(arg1, I)
    @warn "`clang_CompileCommand_getMappedSourceContent` Left here for backward compatibility.\nNo mapped sources exists in the C++ backend anymore.\nThis function just return Null `CXString`.\n\nSee:\n- [Remove unused CompilationDatabase::MappedSources](https://reviews.llvm.org/D32351)\n"
    ccall((:clang_CompileCommand_getMappedSourceContent, libclang), CXString, (CXCompileCommand, UInt32), arg1, I)
end
# Julia wrapper for header: CXErrorCode.h
# Automatically generated using Clang.jl

# Julia wrapper for header: CXString.h
# Automatically generated using Clang.jl

function clang_getCString(string)
    ccall((:clang_getCString, libclang), Cstring, (CXString,), string)
end

function clang_disposeString(string)
    ccall((:clang_disposeString, libclang), Cvoid, (CXString,), string)
end

function clang_disposeStringSet(set)
    ccall((:clang_disposeStringSet, libclang), Cvoid, (Ptr{CXStringSet},), set)
end
# Julia wrapper for header: Documentation.h
# Automatically generated using Clang.jl

function clang_Cursor_getParsedComment(C)
    ccall((:clang_Cursor_getParsedComment, libclang), CXComment, (CXCursor,), C)
end

function clang_Comment_getKind(Comment)
    ccall((:clang_Comment_getKind, libclang), CXCommentKind, (CXComment,), Comment)
end

function clang_Comment_getNumChildren(Comment)
    ccall((:clang_Comment_getNumChildren, libclang), UInt32, (CXComment,), Comment)
end

function clang_Comment_getChild(Comment, ChildIdx)
    ccall((:clang_Comment_getChild, libclang), CXComment, (CXComment, UInt32), Comment, ChildIdx)
end

function clang_Comment_isWhitespace(Comment)
    ccall((:clang_Comment_isWhitespace, libclang), UInt32, (CXComment,), Comment)
end

function clang_InlineContentComment_hasTrailingNewline(Comment)
    ccall((:clang_InlineContentComment_hasTrailingNewline, libclang), UInt32, (CXComment,), Comment)
end

function clang_TextComment_getText(Comment)
    ccall((:clang_TextComment_getText, libclang), CXString, (CXComment,), Comment)
end

function clang_InlineCommandComment_getCommandName(Comment)
    ccall((:clang_InlineCommandComment_getCommandName, libclang), CXString, (CXComment,), Comment)
end

function clang_InlineCommandComment_getRenderKind(Comment)
    ccall((:clang_InlineCommandComment_getRenderKind, libclang), CXCommentInlineCommandRenderKind, (CXComment,), Comment)
end

function clang_InlineCommandComment_getNumArgs(Comment)
    ccall((:clang_InlineCommandComment_getNumArgs, libclang), UInt32, (CXComment,), Comment)
end

function clang_InlineCommandComment_getArgText(Comment, ArgIdx)
    ccall((:clang_InlineCommandComment_getArgText, libclang), CXString, (CXComment, UInt32), Comment, ArgIdx)
end

function clang_HTMLTagComment_getTagName(Comment)
    ccall((:clang_HTMLTagComment_getTagName, libclang), CXString, (CXComment,), Comment)
end

function clang_HTMLStartTagComment_isSelfClosing(Comment)
    ccall((:clang_HTMLStartTagComment_isSelfClosing, libclang), UInt32, (CXComment,), Comment)
end

function clang_HTMLStartTag_getNumAttrs(Comment)
    ccall((:clang_HTMLStartTag_getNumAttrs, libclang), UInt32, (CXComment,), Comment)
end

function clang_HTMLStartTag_getAttrName(Comment, AttrIdx)
    ccall((:clang_HTMLStartTag_getAttrName, libclang), CXString, (CXComment, UInt32), Comment, AttrIdx)
end

function clang_HTMLStartTag_getAttrValue(Comment, AttrIdx)
    ccall((:clang_HTMLStartTag_getAttrValue, libclang), CXString, (CXComment, UInt32), Comment, AttrIdx)
end

function clang_BlockCommandComment_getCommandName(Comment)
    ccall((:clang_BlockCommandComment_getCommandName, libclang), CXString, (CXComment,), Comment)
end

function clang_BlockCommandComment_getNumArgs(Comment)
    ccall((:clang_BlockCommandComment_getNumArgs, libclang), UInt32, (CXComment,), Comment)
end

function clang_BlockCommandComment_getArgText(Comment, ArgIdx)
    ccall((:clang_BlockCommandComment_getArgText, libclang), CXString, (CXComment, UInt32), Comment, ArgIdx)
end

function clang_BlockCommandComment_getParagraph(Comment)
    ccall((:clang_BlockCommandComment_getParagraph, libclang), CXComment, (CXComment,), Comment)
end

function clang_ParamCommandComment_getParamName(Comment)
    ccall((:clang_ParamCommandComment_getParamName, libclang), CXString, (CXComment,), Comment)
end

function clang_ParamCommandComment_isParamIndexValid(Comment)
    ccall((:clang_ParamCommandComment_isParamIndexValid, libclang), UInt32, (CXComment,), Comment)
end

function clang_ParamCommandComment_getParamIndex(Comment)
    ccall((:clang_ParamCommandComment_getParamIndex, libclang), UInt32, (CXComment,), Comment)
end

function clang_ParamCommandComment_isDirectionExplicit(Comment)
    ccall((:clang_ParamCommandComment_isDirectionExplicit, libclang), UInt32, (CXComment,), Comment)
end

function clang_ParamCommandComment_getDirection(Comment)
    ccall((:clang_ParamCommandComment_getDirection, libclang), CXCommentParamPassDirection, (CXComment,), Comment)
end

function clang_TParamCommandComment_getParamName(Comment)
    ccall((:clang_TParamCommandComment_getParamName, libclang), CXString, (CXComment,), Comment)
end

function clang_TParamCommandComment_isParamPositionValid(Comment)
    ccall((:clang_TParamCommandComment_isParamPositionValid, libclang), UInt32, (CXComment,), Comment)
end

function clang_TParamCommandComment_getDepth(Comment)
    ccall((:clang_TParamCommandComment_getDepth, libclang), UInt32, (CXComment,), Comment)
end

function clang_TParamCommandComment_getIndex(Comment, Depth)
    ccall((:clang_TParamCommandComment_getIndex, libclang), UInt32, (CXComment, UInt32), Comment, Depth)
end

function clang_VerbatimBlockLineComment_getText(Comment)
    ccall((:clang_VerbatimBlockLineComment_getText, libclang), CXString, (CXComment,), Comment)
end

function clang_VerbatimLineComment_getText(Comment)
    ccall((:clang_VerbatimLineComment_getText, libclang), CXString, (CXComment,), Comment)
end

function clang_HTMLTagComment_getAsString(Comment)
    ccall((:clang_HTMLTagComment_getAsString, libclang), CXString, (CXComment,), Comment)
end

function clang_FullComment_getAsHTML(Comment)
    ccall((:clang_FullComment_getAsHTML, libclang), CXString, (CXComment,), Comment)
end

function clang_FullComment_getAsXML(Comment)
    ccall((:clang_FullComment_getAsXML, libclang), CXString, (CXComment,), Comment)
end
# Julia wrapper for header: Index.h
# Automatically generated using Clang.jl

function clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics)
    ccall((:clang_createIndex, libclang), CXIndex, (Cint, Cint), excludeDeclarationsFromPCH, displayDiagnostics)
end

function clang_disposeIndex(index)
    ccall((:clang_disposeIndex, libclang), Cvoid, (CXIndex,), index)
end

function clang_CXIndex_setGlobalOptions(arg1, options)
    ccall((:clang_CXIndex_setGlobalOptions, libclang), Cvoid, (CXIndex, UInt32), arg1, options)
end

function clang_CXIndex_getGlobalOptions(arg1)
    ccall((:clang_CXIndex_getGlobalOptions, libclang), UInt32, (CXIndex,), arg1)
end

function clang_CXIndex_setInvocationEmissionPathOption(arg1, Path)
    ccall((:clang_CXIndex_setInvocationEmissionPathOption, libclang), Cvoid, (CXIndex, Cstring), arg1, Path)
end

function clang_getFileName(SFile)
    ccall((:clang_getFileName, libclang), CXString, (CXFile,), SFile)
end

function clang_getFileTime(SFile)
    ccall((:clang_getFileTime, libclang), Ctime_t, (CXFile,), SFile)
end

function clang_getFileUniqueID(file, outID)
    ccall((:clang_getFileUniqueID, libclang), Cint, (CXFile, Ptr{CXFileUniqueID}), file, outID)
end

function clang_isFileMultipleIncludeGuarded(tu, file)
    ccall((:clang_isFileMultipleIncludeGuarded, libclang), UInt32, (CXTranslationUnit, CXFile), tu, file)
end

function clang_getFile(tu, file_name)
    ccall((:clang_getFile, libclang), CXFile, (CXTranslationUnit, Cstring), tu, file_name)
end

function clang_getFileContents(tu, file, size)
    ccall((:clang_getFileContents, libclang), Cstring, (CXTranslationUnit, CXFile, Ptr{Csize_t}), tu, file, size)
end

function clang_File_isEqual(file1, file2)
    ccall((:clang_File_isEqual, libclang), Cint, (CXFile, CXFile), file1, file2)
end

function clang_getNullLocation()
    ccall((:clang_getNullLocation, libclang), CXSourceLocation, ())
end

function clang_equalLocations(loc1, loc2)
    ccall((:clang_equalLocations, libclang), UInt32, (CXSourceLocation, CXSourceLocation), loc1, loc2)
end

function clang_getLocation(tu, file, line, column)
    ccall((:clang_getLocation, libclang), CXSourceLocation, (CXTranslationUnit, CXFile, UInt32, UInt32), tu, file, line, column)
end

function clang_getLocationForOffset(tu, file, offset)
    ccall((:clang_getLocationForOffset, libclang), CXSourceLocation, (CXTranslationUnit, CXFile, UInt32), tu, file, offset)
end

function clang_Location_isInSystemHeader(location)
    ccall((:clang_Location_isInSystemHeader, libclang), Cint, (CXSourceLocation,), location)
end

function clang_Location_isFromMainFile(location)
    ccall((:clang_Location_isFromMainFile, libclang), Cint, (CXSourceLocation,), location)
end

function clang_getNullRange()
    ccall((:clang_getNullRange, libclang), CXSourceRange, ())
end

function clang_getRange(_begin, _end)
    ccall((:clang_getRange, libclang), CXSourceRange, (CXSourceLocation, CXSourceLocation), _begin, _end)
end

function clang_equalRanges(range1, range2)
    ccall((:clang_equalRanges, libclang), UInt32, (CXSourceRange, CXSourceRange), range1, range2)
end

function clang_Range_isNull(range)
    ccall((:clang_Range_isNull, libclang), Cint, (CXSourceRange,), range)
end

function clang_getExpansionLocation(location, file, line, column, offset)
    ccall((:clang_getExpansionLocation, libclang), Cvoid, (CXSourceLocation, Ptr{CXFile}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), location, file, line, column, offset)
end

function clang_getPresumedLocation(location, filename, line, column)
    ccall((:clang_getPresumedLocation, libclang), Cvoid, (CXSourceLocation, Ptr{CXString}, Ptr{UInt32}, Ptr{UInt32}), location, filename, line, column)
end

function clang_getInstantiationLocation(location, file, line, column, offset)
    ccall((:clang_getInstantiationLocation, libclang), Cvoid, (CXSourceLocation, Ptr{CXFile}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), location, file, line, column, offset)
end

function clang_getSpellingLocation(location, file, line, column, offset)
    ccall((:clang_getSpellingLocation, libclang), Cvoid, (CXSourceLocation, Ptr{CXFile}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), location, file, line, column, offset)
end

function clang_getFileLocation(location, file, line, column, offset)
    ccall((:clang_getFileLocation, libclang), Cvoid, (CXSourceLocation, Ptr{CXFile}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), location, file, line, column, offset)
end

function clang_getRangeStart(range)
    ccall((:clang_getRangeStart, libclang), CXSourceLocation, (CXSourceRange,), range)
end

function clang_getRangeEnd(range)
    ccall((:clang_getRangeEnd, libclang), CXSourceLocation, (CXSourceRange,), range)
end

function clang_getSkippedRanges(tu, file)
    ccall((:clang_getSkippedRanges, libclang), Ptr{CXSourceRangeList}, (CXTranslationUnit, CXFile), tu, file)
end

function clang_getAllSkippedRanges(tu)
    ccall((:clang_getAllSkippedRanges, libclang), Ptr{CXSourceRangeList}, (CXTranslationUnit,), tu)
end

function clang_disposeSourceRangeList(ranges)
    ccall((:clang_disposeSourceRangeList, libclang), Cvoid, (Ptr{CXSourceRangeList},), ranges)
end

function clang_getNumDiagnosticsInSet(Diags)
    ccall((:clang_getNumDiagnosticsInSet, libclang), UInt32, (CXDiagnosticSet,), Diags)
end

function clang_getDiagnosticInSet(Diags, Index)
    ccall((:clang_getDiagnosticInSet, libclang), CXDiagnostic, (CXDiagnosticSet, UInt32), Diags, Index)
end

function clang_loadDiagnostics(file, error, errorString)
    ccall((:clang_loadDiagnostics, libclang), CXDiagnosticSet, (Cstring, Ptr{CXLoadDiag_Error}, Ptr{CXString}), file, error, errorString)
end

function clang_disposeDiagnosticSet(Diags)
    ccall((:clang_disposeDiagnosticSet, libclang), Cvoid, (CXDiagnosticSet,), Diags)
end

function clang_getChildDiagnostics(D)
    ccall((:clang_getChildDiagnostics, libclang), CXDiagnosticSet, (CXDiagnostic,), D)
end

function clang_getNumDiagnostics(Unit)
    ccall((:clang_getNumDiagnostics, libclang), UInt32, (CXTranslationUnit,), Unit)
end

function clang_getDiagnostic(Unit, Index)
    ccall((:clang_getDiagnostic, libclang), CXDiagnostic, (CXTranslationUnit, UInt32), Unit, Index)
end

function clang_getDiagnosticSetFromTU(Unit)
    ccall((:clang_getDiagnosticSetFromTU, libclang), CXDiagnosticSet, (CXTranslationUnit,), Unit)
end

function clang_disposeDiagnostic(Diagnostic)
    ccall((:clang_disposeDiagnostic, libclang), Cvoid, (CXDiagnostic,), Diagnostic)
end

function clang_formatDiagnostic(Diagnostic, Options)
    ccall((:clang_formatDiagnostic, libclang), CXString, (CXDiagnostic, UInt32), Diagnostic, Options)
end

function clang_defaultDiagnosticDisplayOptions()
    ccall((:clang_defaultDiagnosticDisplayOptions, libclang), UInt32, ())
end

function clang_getDiagnosticSeverity(arg1)
    ccall((:clang_getDiagnosticSeverity, libclang), CXDiagnosticSeverity, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticLocation(arg1)
    ccall((:clang_getDiagnosticLocation, libclang), CXSourceLocation, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticSpelling(arg1)
    ccall((:clang_getDiagnosticSpelling, libclang), CXString, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticOption(Diag, Disable)
    ccall((:clang_getDiagnosticOption, libclang), CXString, (CXDiagnostic, Ptr{CXString}), Diag, Disable)
end

function clang_getDiagnosticCategory(arg1)
    ccall((:clang_getDiagnosticCategory, libclang), UInt32, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticCategoryName(Category)
    ccall((:clang_getDiagnosticCategoryName, libclang), CXString, (UInt32,), Category)
end

function clang_getDiagnosticCategoryText(arg1)
    ccall((:clang_getDiagnosticCategoryText, libclang), CXString, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticNumRanges(arg1)
    ccall((:clang_getDiagnosticNumRanges, libclang), UInt32, (CXDiagnostic,), arg1)
end

function clang_getDiagnosticRange(Diagnostic, Range)
    ccall((:clang_getDiagnosticRange, libclang), CXSourceRange, (CXDiagnostic, UInt32), Diagnostic, Range)
end

function clang_getDiagnosticNumFixIts(Diagnostic)
    ccall((:clang_getDiagnosticNumFixIts, libclang), UInt32, (CXDiagnostic,), Diagnostic)
end

function clang_getDiagnosticFixIt(Diagnostic, FixIt, ReplacementRange)
    ccall((:clang_getDiagnosticFixIt, libclang), CXString, (CXDiagnostic, UInt32, Ptr{CXSourceRange}), Diagnostic, FixIt, ReplacementRange)
end

function clang_getTranslationUnitSpelling(CTUnit)
    ccall((:clang_getTranslationUnitSpelling, libclang), CXString, (CXTranslationUnit,), CTUnit)
end

function clang_createTranslationUnitFromSourceFile(CIdx, source_filename, num_clang_command_line_args, clang_command_line_args, num_unsaved_files, unsaved_files)
    ccall((:clang_createTranslationUnitFromSourceFile, libclang), CXTranslationUnit, (CXIndex, Cstring, Cint, Ptr{Cstring}, UInt32, Ptr{CXUnsavedFile}), CIdx, source_filename, num_clang_command_line_args, clang_command_line_args, num_unsaved_files, unsaved_files)
end

function clang_createTranslationUnit(CIdx, ast_filename)
    ccall((:clang_createTranslationUnit, libclang), CXTranslationUnit, (CXIndex, Cstring), CIdx, ast_filename)
end

function clang_createTranslationUnit2(CIdx, ast_filename, out_TU)
    ccall((:clang_createTranslationUnit2, libclang), CXErrorCode, (CXIndex, Cstring, Ptr{CXTranslationUnit}), CIdx, ast_filename, out_TU)
end

function clang_defaultEditingTranslationUnitOptions()
    ccall((:clang_defaultEditingTranslationUnitOptions, libclang), UInt32, ())
end

function clang_parseTranslationUnit(CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options)
    ccall((:clang_parseTranslationUnit, libclang), CXTranslationUnit, (CXIndex, Cstring, Ptr{Cstring}, Cint, Ptr{CXUnsavedFile}, UInt32, UInt32), CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options)
end

function clang_parseTranslationUnit2(CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options, out_TU)
    ccall((:clang_parseTranslationUnit2, libclang), CXErrorCode, (CXIndex, Cstring, Ptr{Cstring}, Cint, Ptr{CXUnsavedFile}, UInt32, UInt32, Ptr{CXTranslationUnit}), CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options, out_TU)
end

function clang_parseTranslationUnit2FullArgv(CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options, out_TU)
    ccall((:clang_parseTranslationUnit2FullArgv, libclang), CXErrorCode, (CXIndex, Cstring, Ptr{Cstring}, Cint, Ptr{CXUnsavedFile}, UInt32, UInt32, Ptr{CXTranslationUnit}), CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options, out_TU)
end

function clang_defaultSaveOptions(TU)
    ccall((:clang_defaultSaveOptions, libclang), UInt32, (CXTranslationUnit,), TU)
end

function clang_saveTranslationUnit(TU, FileName, options)
    ccall((:clang_saveTranslationUnit, libclang), Cint, (CXTranslationUnit, Cstring, UInt32), TU, FileName, options)
end

function clang_suspendTranslationUnit(arg1)
    ccall((:clang_suspendTranslationUnit, libclang), UInt32, (CXTranslationUnit,), arg1)
end

function clang_disposeTranslationUnit(arg1)
    ccall((:clang_disposeTranslationUnit, libclang), Cvoid, (CXTranslationUnit,), arg1)
end

function clang_defaultReparseOptions(TU)
    ccall((:clang_defaultReparseOptions, libclang), UInt32, (CXTranslationUnit,), TU)
end

function clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, options)
    ccall((:clang_reparseTranslationUnit, libclang), Cint, (CXTranslationUnit, UInt32, Ptr{CXUnsavedFile}, UInt32), TU, num_unsaved_files, unsaved_files, options)
end

function clang_getTUResourceUsageName(kind)
    ccall((:clang_getTUResourceUsageName, libclang), Cstring, (CXTUResourceUsageKind,), kind)
end

function clang_getCXTUResourceUsage(TU)
    ccall((:clang_getCXTUResourceUsage, libclang), CXTUResourceUsage, (CXTranslationUnit,), TU)
end

function clang_disposeCXTUResourceUsage(usage)
    ccall((:clang_disposeCXTUResourceUsage, libclang), Cvoid, (CXTUResourceUsage,), usage)
end

function clang_getTranslationUnitTargetInfo(CTUnit)
    ccall((:clang_getTranslationUnitTargetInfo, libclang), CXTargetInfo, (CXTranslationUnit,), CTUnit)
end

function clang_TargetInfo_dispose(Info)
    ccall((:clang_TargetInfo_dispose, libclang), Cvoid, (CXTargetInfo,), Info)
end

function clang_TargetInfo_getTriple(Info)
    ccall((:clang_TargetInfo_getTriple, libclang), CXString, (CXTargetInfo,), Info)
end

function clang_TargetInfo_getPointerWidth(Info)
    ccall((:clang_TargetInfo_getPointerWidth, libclang), Cint, (CXTargetInfo,), Info)
end

function clang_getNullCursor()
    ccall((:clang_getNullCursor, libclang), CXCursor, ())
end

function clang_getTranslationUnitCursor(arg1)
    ccall((:clang_getTranslationUnitCursor, libclang), CXCursor, (CXTranslationUnit,), arg1)
end

function clang_equalCursors(arg1, arg2)
    ccall((:clang_equalCursors, libclang), UInt32, (CXCursor, CXCursor), arg1, arg2)
end

function clang_Cursor_isNull(cursor)
    ccall((:clang_Cursor_isNull, libclang), Cint, (CXCursor,), cursor)
end

function clang_hashCursor(arg1)
    ccall((:clang_hashCursor, libclang), UInt32, (CXCursor,), arg1)
end

function clang_getCursorKind(arg1)
    ccall((:clang_getCursorKind, libclang), CXCursorKind, (CXCursor,), arg1)
end

function clang_isDeclaration(arg1)
    ccall((:clang_isDeclaration, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isReference(arg1)
    ccall((:clang_isReference, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isExpression(arg1)
    ccall((:clang_isExpression, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isStatement(arg1)
    ccall((:clang_isStatement, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isAttribute(arg1)
    ccall((:clang_isAttribute, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_Cursor_hasAttrs(C)
    ccall((:clang_Cursor_hasAttrs, libclang), UInt32, (CXCursor,), C)
end

function clang_isInvalid(arg1)
    ccall((:clang_isInvalid, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isTranslationUnit(arg1)
    ccall((:clang_isTranslationUnit, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isPreprocessing(arg1)
    ccall((:clang_isPreprocessing, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_isUnexposed(arg1)
    ccall((:clang_isUnexposed, libclang), UInt32, (CXCursorKind,), arg1)
end

function clang_getCursorLinkage(cursor)
    ccall((:clang_getCursorLinkage, libclang), CXLinkageKind, (CXCursor,), cursor)
end

function clang_getCursorVisibility(cursor)
    ccall((:clang_getCursorVisibility, libclang), CXVisibilityKind, (CXCursor,), cursor)
end

function clang_getCursorAvailability(cursor)
    ccall((:clang_getCursorAvailability, libclang), CXAvailabilityKind, (CXCursor,), cursor)
end

function clang_getCursorPlatformAvailability(cursor, always_deprecated, deprecated_message, always_unavailable, unavailable_message, availability, availability_size)
    ccall((:clang_getCursorPlatformAvailability, libclang), Cint, (CXCursor, Ptr{Cint}, Ptr{CXString}, Ptr{Cint}, Ptr{CXString}, Ptr{CXPlatformAvailability}, Cint), cursor, always_deprecated, deprecated_message, always_unavailable, unavailable_message, availability, availability_size)
end

function clang_disposeCXPlatformAvailability(availability)
    ccall((:clang_disposeCXPlatformAvailability, libclang), Cvoid, (Ptr{CXPlatformAvailability},), availability)
end

function clang_getCursorLanguage(cursor)
    ccall((:clang_getCursorLanguage, libclang), CXLanguageKind, (CXCursor,), cursor)
end

function clang_getCursorTLSKind(cursor)
    ccall((:clang_getCursorTLSKind, libclang), CXTLSKind, (CXCursor,), cursor)
end

function clang_Cursor_getTranslationUnit(arg1)
    ccall((:clang_Cursor_getTranslationUnit, libclang), CXTranslationUnit, (CXCursor,), arg1)
end

function clang_createCXCursorSet()
    ccall((:clang_createCXCursorSet, libclang), CXCursorSet, ())
end

function clang_disposeCXCursorSet(cset)
    ccall((:clang_disposeCXCursorSet, libclang), Cvoid, (CXCursorSet,), cset)
end

function clang_CXCursorSet_contains(cset, cursor)
    ccall((:clang_CXCursorSet_contains, libclang), UInt32, (CXCursorSet, CXCursor), cset, cursor)
end

function clang_CXCursorSet_insert(cset, cursor)
    ccall((:clang_CXCursorSet_insert, libclang), UInt32, (CXCursorSet, CXCursor), cset, cursor)
end

function clang_getCursorSemanticParent(cursor)
    ccall((:clang_getCursorSemanticParent, libclang), CXCursor, (CXCursor,), cursor)
end

function clang_getCursorLexicalParent(cursor)
    ccall((:clang_getCursorLexicalParent, libclang), CXCursor, (CXCursor,), cursor)
end

function clang_getOverriddenCursors(cursor, overridden, num_overridden)
    ccall((:clang_getOverriddenCursors, libclang), Cvoid, (CXCursor, Ptr{Ptr{CXCursor}}, Ptr{UInt32}), cursor, overridden, num_overridden)
end

function clang_disposeOverriddenCursors(overridden)
    ccall((:clang_disposeOverriddenCursors, libclang), Cvoid, (Ptr{CXCursor},), overridden)
end

function clang_getIncludedFile(cursor)
    ccall((:clang_getIncludedFile, libclang), CXFile, (CXCursor,), cursor)
end

function clang_getCursor(arg1, arg2)
    ccall((:clang_getCursor, libclang), CXCursor, (CXTranslationUnit, CXSourceLocation), arg1, arg2)
end

function clang_getCursorLocation(arg1)
    ccall((:clang_getCursorLocation, libclang), CXSourceLocation, (CXCursor,), arg1)
end

function clang_getCursorExtent(arg1)
    ccall((:clang_getCursorExtent, libclang), CXSourceRange, (CXCursor,), arg1)
end

function clang_getCursorType(C)
    ccall((:clang_getCursorType, libclang), CXType, (CXCursor,), C)
end

function clang_getTypeSpelling(CT)
    ccall((:clang_getTypeSpelling, libclang), CXString, (CXType,), CT)
end

function clang_getTypedefDeclUnderlyingType(C)
    ccall((:clang_getTypedefDeclUnderlyingType, libclang), CXType, (CXCursor,), C)
end

function clang_getEnumDeclIntegerType(C)
    ccall((:clang_getEnumDeclIntegerType, libclang), CXType, (CXCursor,), C)
end

function clang_getEnumConstantDeclValue(C)
    ccall((:clang_getEnumConstantDeclValue, libclang), Clonglong, (CXCursor,), C)
end

function clang_getEnumConstantDeclUnsignedValue(C)
    ccall((:clang_getEnumConstantDeclUnsignedValue, libclang), Culonglong, (CXCursor,), C)
end

function clang_getFieldDeclBitWidth(C)
    ccall((:clang_getFieldDeclBitWidth, libclang), Cint, (CXCursor,), C)
end

function clang_Cursor_getNumArguments(C)
    ccall((:clang_Cursor_getNumArguments, libclang), Cint, (CXCursor,), C)
end

function clang_Cursor_getArgument(C, i)
    ccall((:clang_Cursor_getArgument, libclang), CXCursor, (CXCursor, UInt32), C, i)
end

function clang_Cursor_getNumTemplateArguments(C)
    ccall((:clang_Cursor_getNumTemplateArguments, libclang), Cint, (CXCursor,), C)
end

function clang_Cursor_getTemplateArgumentKind(C, I)
    ccall((:clang_Cursor_getTemplateArgumentKind, libclang), CXTemplateArgumentKind, (CXCursor, UInt32), C, I)
end

function clang_Cursor_getTemplateArgumentType(C, I)
    ccall((:clang_Cursor_getTemplateArgumentType, libclang), CXType, (CXCursor, UInt32), C, I)
end

function clang_Cursor_getTemplateArgumentValue(C, I)
    ccall((:clang_Cursor_getTemplateArgumentValue, libclang), Clonglong, (CXCursor, UInt32), C, I)
end

function clang_Cursor_getTemplateArgumentUnsignedValue(C, I)
    ccall((:clang_Cursor_getTemplateArgumentUnsignedValue, libclang), Culonglong, (CXCursor, UInt32), C, I)
end

function clang_equalTypes(A, B)
    ccall((:clang_equalTypes, libclang), UInt32, (CXType, CXType), A, B)
end

function clang_getCanonicalType(T)
    ccall((:clang_getCanonicalType, libclang), CXType, (CXType,), T)
end

function clang_isConstQualifiedType(T)
    ccall((:clang_isConstQualifiedType, libclang), UInt32, (CXType,), T)
end

function clang_Cursor_isMacroFunctionLike(C)
    ccall((:clang_Cursor_isMacroFunctionLike, libclang), UInt32, (CXCursor,), C)
end

function clang_Cursor_isMacroBuiltin(C)
    ccall((:clang_Cursor_isMacroBuiltin, libclang), UInt32, (CXCursor,), C)
end

function clang_Cursor_isFunctionInlined(C)
    ccall((:clang_Cursor_isFunctionInlined, libclang), UInt32, (CXCursor,), C)
end

function clang_isVolatileQualifiedType(T)
    ccall((:clang_isVolatileQualifiedType, libclang), UInt32, (CXType,), T)
end

function clang_isRestrictQualifiedType(T)
    ccall((:clang_isRestrictQualifiedType, libclang), UInt32, (CXType,), T)
end

function clang_getAddressSpace(T)
    ccall((:clang_getAddressSpace, libclang), UInt32, (CXType,), T)
end

function clang_getTypedefName(CT)
    ccall((:clang_getTypedefName, libclang), CXString, (CXType,), CT)
end

function clang_getPointeeType(T)
    ccall((:clang_getPointeeType, libclang), CXType, (CXType,), T)
end

function clang_getTypeDeclaration(T)
    ccall((:clang_getTypeDeclaration, libclang), CXCursor, (CXType,), T)
end

function clang_getDeclObjCTypeEncoding(C)
    ccall((:clang_getDeclObjCTypeEncoding, libclang), CXString, (CXCursor,), C)
end

function clang_Type_getObjCEncoding(type)
    ccall((:clang_Type_getObjCEncoding, libclang), CXString, (CXType,), type)
end

function clang_getTypeKindSpelling(K)
    ccall((:clang_getTypeKindSpelling, libclang), CXString, (CXTypeKind,), K)
end

function clang_getFunctionTypeCallingConv(T)
    ccall((:clang_getFunctionTypeCallingConv, libclang), CXCallingConv, (CXType,), T)
end

function clang_getResultType(T)
    ccall((:clang_getResultType, libclang), CXType, (CXType,), T)
end

function clang_getExceptionSpecificationType(T)
    ccall((:clang_getExceptionSpecificationType, libclang), Cint, (CXType,), T)
end

function clang_getNumArgTypes(T)
    ccall((:clang_getNumArgTypes, libclang), Cint, (CXType,), T)
end

function clang_getArgType(T, i)
    ccall((:clang_getArgType, libclang), CXType, (CXType, UInt32), T, i)
end

function clang_isFunctionTypeVariadic(T)
    ccall((:clang_isFunctionTypeVariadic, libclang), UInt32, (CXType,), T)
end

function clang_getCursorResultType(C)
    ccall((:clang_getCursorResultType, libclang), CXType, (CXCursor,), C)
end

function clang_getCursorExceptionSpecificationType(C)
    ccall((:clang_getCursorExceptionSpecificationType, libclang), Cint, (CXCursor,), C)
end

function clang_isPODType(T)
    ccall((:clang_isPODType, libclang), UInt32, (CXType,), T)
end

function clang_getElementType(T)
    ccall((:clang_getElementType, libclang), CXType, (CXType,), T)
end

function clang_getNumElements(T)
    ccall((:clang_getNumElements, libclang), Clonglong, (CXType,), T)
end

function clang_getArrayElementType(T)
    ccall((:clang_getArrayElementType, libclang), CXType, (CXType,), T)
end

function clang_getArraySize(T)
    ccall((:clang_getArraySize, libclang), Clonglong, (CXType,), T)
end

function clang_Type_getNamedType(T)
    ccall((:clang_Type_getNamedType, libclang), CXType, (CXType,), T)
end

function clang_Type_isTransparentTagTypedef(T)
    ccall((:clang_Type_isTransparentTagTypedef, libclang), UInt32, (CXType,), T)
end

function clang_Type_getAlignOf(T)
    ccall((:clang_Type_getAlignOf, libclang), Clonglong, (CXType,), T)
end

function clang_Type_getClassType(T)
    ccall((:clang_Type_getClassType, libclang), CXType, (CXType,), T)
end

function clang_Type_getSizeOf(T)
    ccall((:clang_Type_getSizeOf, libclang), Clonglong, (CXType,), T)
end

function clang_Type_getOffsetOf(T, S)
    ccall((:clang_Type_getOffsetOf, libclang), Clonglong, (CXType, Cstring), T, S)
end

function clang_Cursor_getOffsetOfField(C)
    ccall((:clang_Cursor_getOffsetOfField, libclang), Clonglong, (CXCursor,), C)
end

function clang_Cursor_isAnonymous(C)
    ccall((:clang_Cursor_isAnonymous, libclang), UInt32, (CXCursor,), C)
end

function clang_Type_getNumTemplateArguments(T)
    ccall((:clang_Type_getNumTemplateArguments, libclang), Cint, (CXType,), T)
end

function clang_Type_getTemplateArgumentAsType(T, i)
    ccall((:clang_Type_getTemplateArgumentAsType, libclang), CXType, (CXType, UInt32), T, i)
end

function clang_Type_getCXXRefQualifier(T)
    ccall((:clang_Type_getCXXRefQualifier, libclang), CXRefQualifierKind, (CXType,), T)
end

function clang_Cursor_isBitField(C)
    ccall((:clang_Cursor_isBitField, libclang), UInt32, (CXCursor,), C)
end

function clang_isVirtualBase(arg1)
    ccall((:clang_isVirtualBase, libclang), UInt32, (CXCursor,), arg1)
end

function clang_getCXXAccessSpecifier(arg1)
    ccall((:clang_getCXXAccessSpecifier, libclang), CX_CXXAccessSpecifier, (CXCursor,), arg1)
end

function clang_Cursor_getStorageClass(arg1)
    ccall((:clang_Cursor_getStorageClass, libclang), CX_StorageClass, (CXCursor,), arg1)
end

function clang_getNumOverloadedDecls(cursor)
    ccall((:clang_getNumOverloadedDecls, libclang), UInt32, (CXCursor,), cursor)
end

function clang_getOverloadedDecl(cursor, index)
    ccall((:clang_getOverloadedDecl, libclang), CXCursor, (CXCursor, UInt32), cursor, index)
end

function clang_getIBOutletCollectionType(arg1)
    ccall((:clang_getIBOutletCollectionType, libclang), CXType, (CXCursor,), arg1)
end

function clang_visitChildren(parent, visitor, client_data)
    ccall((:clang_visitChildren, libclang), UInt32, (CXCursor, CXCursorVisitor, CXClientData), parent, visitor, client_data)
end

function clang_visitChildrenWithBlock(parent, block)
    ccall((:clang_visitChildrenWithBlock, libclang), UInt32, (CXCursor, CXCursorVisitorBlock), parent, block)
end

function clang_getCursorUSR(arg1)
    ccall((:clang_getCursorUSR, libclang), CXString, (CXCursor,), arg1)
end

function clang_constructUSR_ObjCClass(class_name)
    ccall((:clang_constructUSR_ObjCClass, libclang), CXString, (Cstring,), class_name)
end

function clang_constructUSR_ObjCCategory(class_name, category_name)
    ccall((:clang_constructUSR_ObjCCategory, libclang), CXString, (Cstring, Cstring), class_name, category_name)
end

function clang_constructUSR_ObjCProtocol(protocol_name)
    ccall((:clang_constructUSR_ObjCProtocol, libclang), CXString, (Cstring,), protocol_name)
end

function clang_constructUSR_ObjCIvar(name, classUSR)
    ccall((:clang_constructUSR_ObjCIvar, libclang), CXString, (Cstring, CXString), name, classUSR)
end

function clang_constructUSR_ObjCMethod(name, isInstanceMethod, classUSR)
    ccall((:clang_constructUSR_ObjCMethod, libclang), CXString, (Cstring, UInt32, CXString), name, isInstanceMethod, classUSR)
end

function clang_constructUSR_ObjCProperty(property, classUSR)
    ccall((:clang_constructUSR_ObjCProperty, libclang), CXString, (Cstring, CXString), property, classUSR)
end

function clang_getCursorSpelling(arg1)
    ccall((:clang_getCursorSpelling, libclang), CXString, (CXCursor,), arg1)
end

function clang_Cursor_getSpellingNameRange(arg1, pieceIndex, options)
    ccall((:clang_Cursor_getSpellingNameRange, libclang), CXSourceRange, (CXCursor, UInt32, UInt32), arg1, pieceIndex, options)
end

function clang_getCursorDisplayName(arg1)
    ccall((:clang_getCursorDisplayName, libclang), CXString, (CXCursor,), arg1)
end

function clang_getCursorReferenced(arg1)
    ccall((:clang_getCursorReferenced, libclang), CXCursor, (CXCursor,), arg1)
end

function clang_getCursorDefinition(arg1)
    ccall((:clang_getCursorDefinition, libclang), CXCursor, (CXCursor,), arg1)
end

function clang_isCursorDefinition(arg1)
    ccall((:clang_isCursorDefinition, libclang), UInt32, (CXCursor,), arg1)
end

function clang_getCanonicalCursor(arg1)
    ccall((:clang_getCanonicalCursor, libclang), CXCursor, (CXCursor,), arg1)
end

function clang_Cursor_getObjCSelectorIndex(arg1)
    ccall((:clang_Cursor_getObjCSelectorIndex, libclang), Cint, (CXCursor,), arg1)
end

function clang_Cursor_isDynamicCall(C)
    ccall((:clang_Cursor_isDynamicCall, libclang), Cint, (CXCursor,), C)
end

function clang_Cursor_getReceiverType(C)
    ccall((:clang_Cursor_getReceiverType, libclang), CXType, (CXCursor,), C)
end

function clang_Cursor_getObjCPropertyAttributes(C, reserved)
    ccall((:clang_Cursor_getObjCPropertyAttributes, libclang), UInt32, (CXCursor, UInt32), C, reserved)
end

function clang_Cursor_getObjCDeclQualifiers(C)
    ccall((:clang_Cursor_getObjCDeclQualifiers, libclang), UInt32, (CXCursor,), C)
end

function clang_Cursor_isObjCOptional(C)
    ccall((:clang_Cursor_isObjCOptional, libclang), UInt32, (CXCursor,), C)
end

function clang_Cursor_isVariadic(C)
    ccall((:clang_Cursor_isVariadic, libclang), UInt32, (CXCursor,), C)
end

function clang_Cursor_isExternalSymbol(C, language, definedIn, isGenerated)
    ccall((:clang_Cursor_isExternalSymbol, libclang), UInt32, (CXCursor, Ptr{CXString}, Ptr{CXString}, Ptr{UInt32}), C, language, definedIn, isGenerated)
end

function clang_Cursor_getCommentRange(C)
    ccall((:clang_Cursor_getCommentRange, libclang), CXSourceRange, (CXCursor,), C)
end

function clang_Cursor_getRawCommentText(C)
    ccall((:clang_Cursor_getRawCommentText, libclang), CXString, (CXCursor,), C)
end

function clang_Cursor_getBriefCommentText(C)
    ccall((:clang_Cursor_getBriefCommentText, libclang), CXString, (CXCursor,), C)
end

function clang_Cursor_getMangling(arg1)
    ccall((:clang_Cursor_getMangling, libclang), CXString, (CXCursor,), arg1)
end

function clang_Cursor_getCXXManglings(arg1)
    ccall((:clang_Cursor_getCXXManglings, libclang), Ptr{CXStringSet}, (CXCursor,), arg1)
end

function clang_Cursor_getObjCManglings(arg1)
    ccall((:clang_Cursor_getObjCManglings, libclang), Ptr{CXStringSet}, (CXCursor,), arg1)
end

function clang_Cursor_getModule(C)
    ccall((:clang_Cursor_getModule, libclang), CXModule, (CXCursor,), C)
end

function clang_getModuleForFile(arg1, arg2)
    ccall((:clang_getModuleForFile, libclang), CXModule, (CXTranslationUnit, CXFile), arg1, arg2)
end

function clang_Module_getASTFile(Module)
    ccall((:clang_Module_getASTFile, libclang), CXFile, (CXModule,), Module)
end

function clang_Module_getParent(Module)
    ccall((:clang_Module_getParent, libclang), CXModule, (CXModule,), Module)
end

function clang_Module_getName(Module)
    ccall((:clang_Module_getName, libclang), CXString, (CXModule,), Module)
end

function clang_Module_getFullName(Module)
    ccall((:clang_Module_getFullName, libclang), CXString, (CXModule,), Module)
end

function clang_Module_isSystem(Module)
    ccall((:clang_Module_isSystem, libclang), Cint, (CXModule,), Module)
end

function clang_Module_getNumTopLevelHeaders(arg1, Module)
    ccall((:clang_Module_getNumTopLevelHeaders, libclang), UInt32, (CXTranslationUnit, CXModule), arg1, Module)
end

function clang_Module_getTopLevelHeader(arg1, Module, Index)
    ccall((:clang_Module_getTopLevelHeader, libclang), CXFile, (CXTranslationUnit, CXModule, UInt32), arg1, Module, Index)
end

function clang_CXXConstructor_isConvertingConstructor(C)
    ccall((:clang_CXXConstructor_isConvertingConstructor, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXConstructor_isCopyConstructor(C)
    ccall((:clang_CXXConstructor_isCopyConstructor, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXConstructor_isDefaultConstructor(C)
    ccall((:clang_CXXConstructor_isDefaultConstructor, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXConstructor_isMoveConstructor(C)
    ccall((:clang_CXXConstructor_isMoveConstructor, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXField_isMutable(C)
    ccall((:clang_CXXField_isMutable, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXMethod_isDefaulted(C)
    ccall((:clang_CXXMethod_isDefaulted, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXMethod_isPureVirtual(C)
    ccall((:clang_CXXMethod_isPureVirtual, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXMethod_isStatic(C)
    ccall((:clang_CXXMethod_isStatic, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXMethod_isVirtual(C)
    ccall((:clang_CXXMethod_isVirtual, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXRecord_isAbstract(C)
    ccall((:clang_CXXRecord_isAbstract, libclang), UInt32, (CXCursor,), C)
end

function clang_EnumDecl_isScoped(C)
    ccall((:clang_EnumDecl_isScoped, libclang), UInt32, (CXCursor,), C)
end

function clang_CXXMethod_isConst(C)
    ccall((:clang_CXXMethod_isConst, libclang), UInt32, (CXCursor,), C)
end

function clang_getTemplateCursorKind(C)
    ccall((:clang_getTemplateCursorKind, libclang), CXCursorKind, (CXCursor,), C)
end

function clang_getSpecializedCursorTemplate(C)
    ccall((:clang_getSpecializedCursorTemplate, libclang), CXCursor, (CXCursor,), C)
end

function clang_getCursorReferenceNameRange(C, NameFlags, PieceIndex)
    ccall((:clang_getCursorReferenceNameRange, libclang), CXSourceRange, (CXCursor, UInt32, UInt32), C, NameFlags, PieceIndex)
end

function clang_getTokenKind(arg1)
    ccall((:clang_getTokenKind, libclang), CXTokenKind, (CXToken,), arg1)
end

function clang_getTokenSpelling(arg1, arg2)
    ccall((:clang_getTokenSpelling, libclang), CXString, (CXTranslationUnit, CXToken), arg1, arg2)
end

function clang_getTokenLocation(arg1, arg2)
    ccall((:clang_getTokenLocation, libclang), CXSourceLocation, (CXTranslationUnit, CXToken), arg1, arg2)
end

function clang_getTokenExtent(arg1, arg2)
    ccall((:clang_getTokenExtent, libclang), CXSourceRange, (CXTranslationUnit, CXToken), arg1, arg2)
end

function clang_tokenize(TU, Range, Tokens, NumTokens)
    ccall((:clang_tokenize, libclang), Cvoid, (CXTranslationUnit, CXSourceRange, Ptr{Ptr{CXToken}}, Ptr{UInt32}), TU, Range, Tokens, NumTokens)
end

function clang_annotateTokens(TU, Tokens, NumTokens, Cursors)
    ccall((:clang_annotateTokens, libclang), Cvoid, (CXTranslationUnit, Ptr{CXToken}, UInt32, Ptr{CXCursor}), TU, Tokens, NumTokens, Cursors)
end

function clang_disposeTokens(TU, Tokens, NumTokens)
    ccall((:clang_disposeTokens, libclang), Cvoid, (CXTranslationUnit, Ptr{CXToken}, UInt32), TU, Tokens, NumTokens)
end

function clang_getCursorKindSpelling(Kind)
    ccall((:clang_getCursorKindSpelling, libclang), CXString, (CXCursorKind,), Kind)
end

function clang_getDefinitionSpellingAndExtent(arg1, startBuf, endBuf, startLine, startColumn, endLine, endColumn)
    ccall((:clang_getDefinitionSpellingAndExtent, libclang), Cvoid, (CXCursor, Ptr{Cstring}, Ptr{Cstring}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), arg1, startBuf, endBuf, startLine, startColumn, endLine, endColumn)
end

function clang_enableStackTraces()
    ccall((:clang_enableStackTraces, libclang), Cvoid, ())
end

function clang_executeOnThread(fn, user_data, stack_size)
    ccall((:clang_executeOnThread, libclang), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, UInt32), fn, user_data, stack_size)
end

function clang_getCompletionChunkKind(completion_string, chunk_number)
    ccall((:clang_getCompletionChunkKind, libclang), CXCompletionChunkKind, (CXCompletionString, UInt32), completion_string, chunk_number)
end

function clang_getCompletionChunkText(completion_string, chunk_number)
    ccall((:clang_getCompletionChunkText, libclang), CXString, (CXCompletionString, UInt32), completion_string, chunk_number)
end

function clang_getCompletionChunkCompletionString(completion_string, chunk_number)
    ccall((:clang_getCompletionChunkCompletionString, libclang), CXCompletionString, (CXCompletionString, UInt32), completion_string, chunk_number)
end

function clang_getNumCompletionChunks(completion_string)
    ccall((:clang_getNumCompletionChunks, libclang), UInt32, (CXCompletionString,), completion_string)
end

function clang_getCompletionPriority(completion_string)
    ccall((:clang_getCompletionPriority, libclang), UInt32, (CXCompletionString,), completion_string)
end

function clang_getCompletionAvailability(completion_string)
    ccall((:clang_getCompletionAvailability, libclang), CXAvailabilityKind, (CXCompletionString,), completion_string)
end

function clang_getCompletionNumAnnotations(completion_string)
    ccall((:clang_getCompletionNumAnnotations, libclang), UInt32, (CXCompletionString,), completion_string)
end

function clang_getCompletionAnnotation(completion_string, annotation_number)
    ccall((:clang_getCompletionAnnotation, libclang), CXString, (CXCompletionString, UInt32), completion_string, annotation_number)
end

function clang_getCompletionParent(completion_string, kind)
    ccall((:clang_getCompletionParent, libclang), CXString, (CXCompletionString, Ptr{CXCursorKind}), completion_string, kind)
end

function clang_getCompletionBriefComment(completion_string)
    ccall((:clang_getCompletionBriefComment, libclang), CXString, (CXCompletionString,), completion_string)
end

function clang_getCursorCompletionString(cursor)
    ccall((:clang_getCursorCompletionString, libclang), CXCompletionString, (CXCursor,), cursor)
end

function clang_defaultCodeCompleteOptions()
    ccall((:clang_defaultCodeCompleteOptions, libclang), UInt32, ())
end

function clang_codeCompleteAt(TU, complete_filename, complete_line, complete_column, unsaved_files, num_unsaved_files, options)
    ccall((:clang_codeCompleteAt, libclang), Ptr{CXCodeCompleteResults}, (CXTranslationUnit, Cstring, UInt32, UInt32, Ptr{CXUnsavedFile}, UInt32, UInt32), TU, complete_filename, complete_line, complete_column, unsaved_files, num_unsaved_files, options)
end

function clang_sortCodeCompletionResults(Results, NumResults)
    ccall((:clang_sortCodeCompletionResults, libclang), Cvoid, (Ptr{CXCompletionResult}, UInt32), Results, NumResults)
end

function clang_disposeCodeCompleteResults(Results)
    ccall((:clang_disposeCodeCompleteResults, libclang), Cvoid, (Ptr{CXCodeCompleteResults},), Results)
end

function clang_codeCompleteGetNumDiagnostics(Results)
    ccall((:clang_codeCompleteGetNumDiagnostics, libclang), UInt32, (Ptr{CXCodeCompleteResults},), Results)
end

function clang_codeCompleteGetDiagnostic(Results, Index)
    ccall((:clang_codeCompleteGetDiagnostic, libclang), CXDiagnostic, (Ptr{CXCodeCompleteResults}, UInt32), Results, Index)
end

function clang_codeCompleteGetContexts(Results)
    ccall((:clang_codeCompleteGetContexts, libclang), Culonglong, (Ptr{CXCodeCompleteResults},), Results)
end

function clang_codeCompleteGetContainerKind(Results, IsIncomplete)
    ccall((:clang_codeCompleteGetContainerKind, libclang), CXCursorKind, (Ptr{CXCodeCompleteResults}, Ptr{UInt32}), Results, IsIncomplete)
end

function clang_codeCompleteGetContainerUSR(Results)
    ccall((:clang_codeCompleteGetContainerUSR, libclang), CXString, (Ptr{CXCodeCompleteResults},), Results)
end

function clang_codeCompleteGetObjCSelector(Results)
    ccall((:clang_codeCompleteGetObjCSelector, libclang), CXString, (Ptr{CXCodeCompleteResults},), Results)
end

function clang_getClangVersion()
    ccall((:clang_getClangVersion, libclang), CXString, ())
end

function clang_toggleCrashRecovery(isEnabled)
    ccall((:clang_toggleCrashRecovery, libclang), Cvoid, (UInt32,), isEnabled)
end

function clang_getInclusions(tu, visitor, client_data)
    ccall((:clang_getInclusions, libclang), Cvoid, (CXTranslationUnit, CXInclusionVisitor, CXClientData), tu, visitor, client_data)
end

function clang_Cursor_Evaluate(C)
    ccall((:clang_Cursor_Evaluate, libclang), CXEvalResult, (CXCursor,), C)
end

function clang_EvalResult_getKind(E)
    ccall((:clang_EvalResult_getKind, libclang), CXEvalResultKind, (CXEvalResult,), E)
end

function clang_EvalResult_getAsInt(E)
    ccall((:clang_EvalResult_getAsInt, libclang), Cint, (CXEvalResult,), E)
end

function clang_EvalResult_getAsLongLong(E)
    ccall((:clang_EvalResult_getAsLongLong, libclang), Clonglong, (CXEvalResult,), E)
end

function clang_EvalResult_isUnsignedInt(E)
    ccall((:clang_EvalResult_isUnsignedInt, libclang), UInt32, (CXEvalResult,), E)
end

function clang_EvalResult_getAsUnsigned(E)
    ccall((:clang_EvalResult_getAsUnsigned, libclang), Culonglong, (CXEvalResult,), E)
end

function clang_EvalResult_getAsDouble(E)
    ccall((:clang_EvalResult_getAsDouble, libclang), Cdouble, (CXEvalResult,), E)
end

function clang_EvalResult_getAsStr(E)
    ccall((:clang_EvalResult_getAsStr, libclang), Cstring, (CXEvalResult,), E)
end

function clang_EvalResult_dispose(E)
    ccall((:clang_EvalResult_dispose, libclang), Cvoid, (CXEvalResult,), E)
end

function clang_getRemappings(path)
    ccall((:clang_getRemappings, libclang), CXRemapping, (Cstring,), path)
end

function clang_getRemappingsFromFileList(filePaths, numFiles)
    ccall((:clang_getRemappingsFromFileList, libclang), CXRemapping, (Ptr{Cstring}, UInt32), filePaths, numFiles)
end

function clang_remap_getNumFiles(arg1)
    ccall((:clang_remap_getNumFiles, libclang), UInt32, (CXRemapping,), arg1)
end

function clang_remap_getFilenames(arg1, index, original, transformed)
    ccall((:clang_remap_getFilenames, libclang), Cvoid, (CXRemapping, UInt32, Ptr{CXString}, Ptr{CXString}), arg1, index, original, transformed)
end

function clang_remap_dispose(arg1)
    ccall((:clang_remap_dispose, libclang), Cvoid, (CXRemapping,), arg1)
end

function clang_findReferencesInFile(cursor, file, visitor)
    ccall((:clang_findReferencesInFile, libclang), CXResult, (CXCursor, CXFile, CXCursorAndRangeVisitor), cursor, file, visitor)
end

function clang_findIncludesInFile(TU, file, visitor)
    ccall((:clang_findIncludesInFile, libclang), CXResult, (CXTranslationUnit, CXFile, CXCursorAndRangeVisitor), TU, file, visitor)
end

function clang_findReferencesInFileWithBlock(arg1, arg2, arg3)
    ccall((:clang_findReferencesInFileWithBlock, libclang), CXResult, (CXCursor, CXFile, CXCursorAndRangeVisitorBlock), arg1, arg2, arg3)
end

function clang_findIncludesInFileWithBlock(arg1, arg2, arg3)
    ccall((:clang_findIncludesInFileWithBlock, libclang), CXResult, (CXTranslationUnit, CXFile, CXCursorAndRangeVisitorBlock), arg1, arg2, arg3)
end

function clang_index_isEntityObjCContainerKind(arg1)
    ccall((:clang_index_isEntityObjCContainerKind, libclang), Cint, (CXIdxEntityKind,), arg1)
end

function clang_index_getObjCContainerDeclInfo(arg1)
    ccall((:clang_index_getObjCContainerDeclInfo, libclang), Ptr{CXIdxObjCContainerDeclInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getObjCInterfaceDeclInfo(arg1)
    ccall((:clang_index_getObjCInterfaceDeclInfo, libclang), Ptr{CXIdxObjCInterfaceDeclInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getObjCCategoryDeclInfo(arg1)
    ccall((:clang_index_getObjCCategoryDeclInfo, libclang), Ptr{CXIdxObjCCategoryDeclInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getObjCProtocolRefListInfo(arg1)
    ccall((:clang_index_getObjCProtocolRefListInfo, libclang), Ptr{CXIdxObjCProtocolRefListInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getObjCPropertyDeclInfo(arg1)
    ccall((:clang_index_getObjCPropertyDeclInfo, libclang), Ptr{CXIdxObjCPropertyDeclInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getIBOutletCollectionAttrInfo(arg1)
    ccall((:clang_index_getIBOutletCollectionAttrInfo, libclang), Ptr{CXIdxIBOutletCollectionAttrInfo}, (Ptr{CXIdxAttrInfo},), arg1)
end

function clang_index_getCXXClassDeclInfo(arg1)
    ccall((:clang_index_getCXXClassDeclInfo, libclang), Ptr{CXIdxCXXClassDeclInfo}, (Ptr{CXIdxDeclInfo},), arg1)
end

function clang_index_getClientContainer(arg1)
    ccall((:clang_index_getClientContainer, libclang), CXIdxClientContainer, (Ptr{CXIdxContainerInfo},), arg1)
end

function clang_index_setClientContainer(arg1, arg2)
    ccall((:clang_index_setClientContainer, libclang), Cvoid, (Ptr{CXIdxContainerInfo}, CXIdxClientContainer), arg1, arg2)
end

function clang_index_getClientEntity(arg1)
    ccall((:clang_index_getClientEntity, libclang), CXIdxClientEntity, (Ptr{CXIdxEntityInfo},), arg1)
end

function clang_index_setClientEntity(arg1, arg2)
    ccall((:clang_index_setClientEntity, libclang), Cvoid, (Ptr{CXIdxEntityInfo}, CXIdxClientEntity), arg1, arg2)
end

function clang_IndexAction_create(CIdx)
    ccall((:clang_IndexAction_create, libclang), CXIndexAction, (CXIndex,), CIdx)
end

function clang_IndexAction_dispose(arg1)
    ccall((:clang_IndexAction_dispose, libclang), Cvoid, (CXIndexAction,), arg1)
end

function clang_indexSourceFile(arg1, client_data, index_callbacks, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, out_TU, TU_options)
    ccall((:clang_indexSourceFile, libclang), Cint, (CXIndexAction, CXClientData, Ptr{IndexerCallbacks}, UInt32, UInt32, Cstring, Ptr{Cstring}, Cint, Ptr{CXUnsavedFile}, UInt32, Ptr{CXTranslationUnit}, UInt32), arg1, client_data, index_callbacks, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, out_TU, TU_options)
end

function clang_indexSourceFileFullArgv(arg1, client_data, index_callbacks, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, out_TU, TU_options)
    ccall((:clang_indexSourceFileFullArgv, libclang), Cint, (CXIndexAction, CXClientData, Ptr{IndexerCallbacks}, UInt32, UInt32, Cstring, Ptr{Cstring}, Cint, Ptr{CXUnsavedFile}, UInt32, Ptr{CXTranslationUnit}, UInt32), arg1, client_data, index_callbacks, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, out_TU, TU_options)
end

function clang_indexTranslationUnit(arg1, client_data, index_callbacks, index_callbacks_size, index_options, arg2)
    ccall((:clang_indexTranslationUnit, libclang), Cint, (CXIndexAction, CXClientData, Ptr{IndexerCallbacks}, UInt32, UInt32, CXTranslationUnit), arg1, client_data, index_callbacks, index_callbacks_size, index_options, arg2)
end

function clang_indexLoc_getFileLocation(loc, indexFile, file, line, column, offset)
    ccall((:clang_indexLoc_getFileLocation, libclang), Cvoid, (CXIdxLoc, Ptr{CXIdxClientFile}, Ptr{CXFile}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}), loc, indexFile, file, line, column, offset)
end

function clang_indexLoc_getCXSourceLocation(loc)
    ccall((:clang_indexLoc_getCXSourceLocation, libclang), CXSourceLocation, (CXIdxLoc,), loc)
end

function clang_Type_visitFields(T, visitor, client_data)
    ccall((:clang_Type_visitFields, libclang), UInt32, (CXType, CXFieldVisitor, CXClientData), T, visitor, client_data)
end
# Julia wrapper for header: Platform.h
# Automatically generated using Clang.jl


text:
# AKLT ground state using DMRG

include("Schollwock.jl")
# include("AKLT-graph.jl")
using Plots

# function W_constructor(l::Int)
#     W = Dict{Int,Array{ComplexF64,4}}()
#     Z = Diagonal([1.0,0.0,-1.0])
#     Sm = diagm(-1=>[sqrt(2.0),sqrt(2.0)])
#     Sp = diagm(1=>[sqrt(2.0),sqrt(2.0)])
#     X = (Sm+Sp)/2.0
#     Y = (Sp-Sm)/2im
#     for k in 2:l-1
#         W[k] = zeros(Float64,(3,3,14,14))
#     end
# end
δ = 0.001
H = zeros(Float64,(9,9))
H[1,1] = 4.0/3.0 + δ^2
H[2,2] = 1.0/3.0
H[2,4] = 1.0
H[4,2] = 1.0
H[3,3] = -1.00/3.0 - δ^2
H[3,5] = 2.0/3.0
H[5,3] = 2.0/3.0
H[3,7] = 1.00/3.0
H[7,3] = 1.00/3.0
H[4,4] = 1.00/3.0
H[5,5] = 2.0/3.0
H[5,7] = 2.0/3.0
H[7,5] = 2.0/3.0
H[6,6] = 1.00/3.0 - δ^2
H[6,8] = 1.0
H[8,6] = 1.0
H[7,7] = -1.00/3.0
H[8,8] = 1.00/3.0
H[9,9] = 4.0/3.0 + δ^2

function InnerProductOfAdjoiningMPS(Le::Int,n::Int,BD::Int)
    mps_long = DMRG(NNHtoMPO(H,Le+n),Le+n,D=BD,σ=3,ϵ=1.0e-15,maxiteration=30)
    mps_short_temp = DMRG(NNHtoMPO(H,Le),Le,D=BD,σ=3,ϵ=1.0e-15,maxiteration=30)
    mps_cut = CutEntanglement(mps_long,Le,after=true)
    tensors = mps_short_temp.tensors
    for i in Le+1:Le+n
        σ,_,_ = size(mps_cut.tensors[i])
        tensors[i] = ones(typeof(mps_cut.tensors[i][1]),(σ,1,1))
    end
    mps_short = MPS2(tensors, Le+n,mps_short_temp.BD,Le,3)
    norm_of_MPS = sqrt(abs(inner(mps_short,mps_short)))
    mps_short.tensors[Le] = mps_short.tensors[Le]/norm_of_MPS
    return (mps_long.BD,abs2(inner(mps_short,mps_long)))
end

function main()
    l = 50
    D = 2
    local inners = Array{Float64,1}()
    for Le in 3:1:l
        try
            D,temp_inner = InnerProductOfAdjoiningMPS(Le,1,D)
            push!(inners,temp_inner)
        catch er
            write(stderr,"$(er)\n")
        end
    end
    plot(4:1:l+1,inners)
end
# M = DMRG(NNHtoMPO(H,21),21,D=2,σ=3)
# println(abs(inner(M,CutEntanglement(M,20,after=true))))
# println(abs(inner(M,CutEntanglement(M,21,after = false))))
# main()

GS1 = DMRG(NNHtoMPO(H,30),30,D=5,σ=3,ϵ=1.0e-15,maxiteration=100)
GS2 = DMRG(NNHtoMPO(H,30),30,D=5,σ=3,ϵ=1.0e-15,maxiteration=100)
println(inner(GS1,GS2))
println(abs2(inner(GS1,GS2)))
println(abs2(inner(GS1,GS1)))

max_stars_repo_name: CNOT/DMRG

max_issues_repo_name: CNOT/DMRG

max_forks_repo_name: CNOT/DMRG