chore: initial commit of OpenWRT
This commit is contained in:
BIN
flint1-armv7/binaries/btop-static-armv7
Executable file
BIN
flint1-armv7/binaries/btop-static-armv7
Executable file
Binary file not shown.
BIN
flint1-armv7/binaries/mosh-client-static-armv7
Executable file
BIN
flint1-armv7/binaries/mosh-client-static-armv7
Executable file
Binary file not shown.
BIN
flint1-armv7/binaries/mosh-server-static-armv7
Executable file
BIN
flint1-armv7/binaries/mosh-server-static-armv7
Executable file
Binary file not shown.
76
flint1-armv7/build/build-mosh-static.sh
Executable file
76
flint1-armv7/build/build-mosh-static.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
CROSS=arm-linux-gnueabihf
|
||||
CFLAGS_CROSS="-O2 -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
|
||||
CFLAGS_CROSS="-O2 -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
|
||||
# Debian armhf packages use these paths
|
||||
ARM_INCLUDE="-I/usr/include/arm-linux-gnueabihf -I/usr/include"
|
||||
ARM_LIBDIR="/usr/lib/arm-linux-gnueabihf"
|
||||
SYSROOT=/home/user/Public/Projects/OpenWRT/flint1-armv7/src/mosh-sysroot
|
||||
BUILDDIR=/tmp/mosh-arm-build
|
||||
SRCDIR=/home/user/Public/Projects/OpenWRT/flint1-armv7/src/mosh
|
||||
BINDIR=/home/user/Public/Projects/OpenWRT/flint1-armv7/binaries
|
||||
|
||||
mkdir -p "$SYSROOT" "$BUILDDIR" "$BINDIR"
|
||||
|
||||
echo "=== [1/3] Building protobuf host tools + ARM library ==="
|
||||
PROTO_VER=3.21.12
|
||||
cd "$BUILDDIR"
|
||||
rm -rf protobuf-"${PROTO_VER}"
|
||||
tar -xzf /tmp/protobuf-"${PROTO_VER}".tar.gz
|
||||
cd protobuf-"${PROTO_VER}"
|
||||
|
||||
# Build host protoc
|
||||
./configure --prefix=/tmp/host-protoc
|
||||
make -j$(nproc)
|
||||
make install
|
||||
HOST_PROTOC=/tmp/host-protoc/bin/protoc
|
||||
echo " host protoc: $($HOST_PROTOC --version)"
|
||||
|
||||
# Cross-compile protobuf library
|
||||
make distclean
|
||||
./configure \
|
||||
--host=${CROSS} \
|
||||
--prefix="$SYSROOT" \
|
||||
--with-protoc="$HOST_PROTOC" \
|
||||
CC=${CROSS}-gcc \
|
||||
CXX=${CROSS}-g++ \
|
||||
CFLAGS="-static ${CFLAGS_CROSS}" \
|
||||
CXXFLAGS="-static ${CFLAGS_CROSS} -std=c++14" \
|
||||
LDFLAGS="-static"
|
||||
make -j$(nproc)
|
||||
make install
|
||||
echo " protobuf ARM OK: $SYSROOT/lib/libprotobuf.a"
|
||||
|
||||
echo "=== [2/3] Configuring mosh ==="
|
||||
cd "$SRCDIR"
|
||||
[ -f configure ] || ./autogen.sh
|
||||
|
||||
./configure \
|
||||
--host=${CROSS} \
|
||||
--prefix="$SYSROOT" \
|
||||
CC=${CROSS}-gcc \
|
||||
CXX=${CROSS}-g++ \
|
||||
CFLAGS="-static ${CFLAGS_CROSS}" \
|
||||
CXXFLAGS="-static ${CFLAGS_CROSS}" \
|
||||
LDFLAGS="-static -L${SYSROOT}/lib -L${ARM_LIBDIR}" \
|
||||
LIBS="-lz -lzstd -ldl" \
|
||||
CPPFLAGS="-I${SYSROOT}/include ${ARM_INCLUDE}" \
|
||||
PKG_CONFIG="pkg-config" \
|
||||
PKG_CONFIG_PATH="${SYSROOT}/lib/pkgconfig:${ARM_LIBDIR}/pkgconfig" \
|
||||
PKG_CONFIG_LIBDIR="${SYSROOT}/lib/pkgconfig:${ARM_LIBDIR}/pkgconfig"
|
||||
|
||||
echo "=== [3/3] Compiling mosh ==="
|
||||
make -j$(nproc)
|
||||
|
||||
cp src/frontend/mosh-server "$BINDIR/mosh-server-static-armv7" 2>/dev/null || \
|
||||
cp src/frontend/mosh-server "$BINDIR/mosh-server-static-armv7"
|
||||
cp src/frontend/mosh-client "$BINDIR/mosh-client-static-armv7" 2>/dev/null || \
|
||||
cp src/frontend/mosh-client "$BINDIR/mosh-client-static-armv7"
|
||||
|
||||
echo ""
|
||||
echo "=== Build Complete ==="
|
||||
file "$BINDIR/mosh-server-static-armv7"
|
||||
file "$BINDIR/mosh-client-static-armv7"
|
||||
ls -lh "$BINDIR/"
|
||||
BIN
flint1-armv7/firmware/official/ax1800-4.8.3_beta1-930-1226-1766720311.img
Executable file
BIN
flint1-armv7/firmware/official/ax1800-4.8.3_beta1-930-1226-1766720311.img
Executable file
Binary file not shown.
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.5.16-0321-1711030388.img
Executable file
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.5.16-0321-1711030388.img
Executable file
Binary file not shown.
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.6.6-0926-1727315351.img
Executable file
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.6.6-0926-1727315351.img
Executable file
Binary file not shown.
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.6.8-1017-1729176012.img
Executable file
BIN
flint1-armv7/firmware/official/openwrt-ax1800-4.6.8-1017-1729176012.img
Executable file
Binary file not shown.
BIN
flint1-armv7/firmware/official/qsdk-ax1800-3.214-0509.img
Executable file
BIN
flint1-armv7/firmware/official/qsdk-ax1800-3.214-0509.img
Executable file
Binary file not shown.
BIN
flint1-armv7/firmware/official/qsdk-ax1800-3.216-0321-1679391158.img
Executable file
BIN
flint1-armv7/firmware/official/qsdk-ax1800-3.216-0321-1679391158.img
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
flint1-armv7/sdk/armv7l-linux-musleabihf-cross/usr
Executable file
1
flint1-armv7/sdk/armv7l-linux-musleabihf-cross/usr
Executable file
@@ -0,0 +1 @@
|
||||
.
|
||||
BIN
flint1-armv7/sdk/musl-toolchain.tgz
Executable file
BIN
flint1-armv7/sdk/musl-toolchain.tgz
Executable file
Binary file not shown.
@@ -0,0 +1 @@
|
||||
lib
|
||||
@@ -0,0 +1 @@
|
||||
21.1.6
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
offload-arch
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import os.path
|
||||
this_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
|
||||
|
||||
from libscanbuild.analyze import analyze_build
|
||||
|
||||
if __name__ == '__main__':
|
||||
multiprocessing.freeze_support()
|
||||
sys.exit(analyze_build())
|
||||
@@ -0,0 +1 @@
|
||||
clang-21
|
||||
@@ -0,0 +1 @@
|
||||
clang
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-21.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-check.bin" "$@"
|
||||
@@ -0,0 +1 @@
|
||||
clang
|
||||
@@ -0,0 +1 @@
|
||||
clang
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-extdef-mapping.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-format.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-installapi.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-linker-wrapper.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-nvlink-wrapper.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-offload-bundler.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-offload-packager.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-refactor.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-repl.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-scan-deps.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.clang-sycl-linker.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.diagtool.bin" "$@"
|
||||
@@ -0,0 +1,858 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# ===- git-clang-format - ClangFormat Git Integration -------*- python -*--=== #
|
||||
#
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
# ===----------------------------------------------------------------------=== #
|
||||
|
||||
r"""
|
||||
clang-format git integration
|
||||
============================
|
||||
|
||||
This file provides a clang-format integration for git. Put it somewhere in your
|
||||
path and ensure that it is executable. Then, "git clang-format" will invoke
|
||||
clang-format on the changes in current files or a specific commit.
|
||||
|
||||
For further details, run:
|
||||
git clang-format -h
|
||||
|
||||
Requires Python version >=3.8
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
import argparse
|
||||
import collections
|
||||
import contextlib
|
||||
import errno
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
usage = "git clang-format [OPTIONS] [<commit>] [<commit>|--staged] [--] [<file>...]"
|
||||
|
||||
desc = """
|
||||
If zero or one commits are given, run clang-format on all lines that differ
|
||||
between the working directory and <commit>, which defaults to HEAD. Changes are
|
||||
only applied to the working directory, or in the stage/index.
|
||||
|
||||
Examples:
|
||||
To format staged changes, i.e everything that's been `git add`ed:
|
||||
git clang-format
|
||||
|
||||
To also format everything touched in the most recent commit:
|
||||
git clang-format HEAD~1
|
||||
|
||||
If you're on a branch off main, to format everything touched on your branch:
|
||||
git clang-format main
|
||||
|
||||
If two commits are given (requires --diff), run clang-format on all lines in the
|
||||
second <commit> that differ from the first <commit>.
|
||||
|
||||
The following git-config settings set the default of the corresponding option:
|
||||
clangFormat.binary
|
||||
clangFormat.commit
|
||||
clangFormat.extensions
|
||||
clangFormat.style
|
||||
"""
|
||||
|
||||
# Name of the temporary index file in which save the output of clang-format.
|
||||
# This file is created within the .git directory.
|
||||
temp_index_basename = "clang-format-index"
|
||||
|
||||
|
||||
Range = collections.namedtuple("Range", "start, count")
|
||||
|
||||
|
||||
def main():
|
||||
config = load_git_config()
|
||||
|
||||
# In order to keep '--' yet allow options after positionals, we need to
|
||||
# check for '--' ourselves. (Setting nargs='*' throws away the '--', while
|
||||
# nargs=argparse.REMAINDER disallows options after positionals.)
|
||||
argv = sys.argv[1:]
|
||||
try:
|
||||
idx = argv.index("--")
|
||||
except ValueError:
|
||||
dash_dash = []
|
||||
else:
|
||||
dash_dash = argv[idx:]
|
||||
argv = argv[:idx]
|
||||
|
||||
default_extensions = ",".join(
|
||||
[
|
||||
# From clang/lib/Frontend/FrontendOptions.cpp, all lower case
|
||||
"c",
|
||||
"h", # C
|
||||
"m", # ObjC
|
||||
"mm", # ObjC++
|
||||
"cc",
|
||||
"cp",
|
||||
"cpp",
|
||||
"c++",
|
||||
"cxx",
|
||||
"hh",
|
||||
"hpp",
|
||||
"hxx",
|
||||
"inc", # C++
|
||||
"ccm",
|
||||
"cppm",
|
||||
"cxxm",
|
||||
"c++m", # C++ Modules
|
||||
"cu",
|
||||
"cuh", # CUDA
|
||||
"cl", # OpenCL
|
||||
# Other languages that clang-format supports
|
||||
"proto",
|
||||
"protodevel", # Protocol Buffers
|
||||
"java", # Java
|
||||
"js",
|
||||
"mjs",
|
||||
"cjs", # JavaScript
|
||||
"ts", # TypeScript
|
||||
"cs", # C Sharp
|
||||
"json",
|
||||
"ipynb", # Json
|
||||
"sv",
|
||||
"svh",
|
||||
"v",
|
||||
"vh", # Verilog
|
||||
"td", # TableGen
|
||||
"txtpb",
|
||||
"textpb",
|
||||
"pb.txt",
|
||||
"textproto",
|
||||
"asciipb", # TextProto
|
||||
]
|
||||
)
|
||||
|
||||
p = argparse.ArgumentParser(
|
||||
usage=usage,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description=desc,
|
||||
)
|
||||
p.add_argument(
|
||||
"--binary",
|
||||
default=config.get("clangformat.binary", "clang-format"),
|
||||
help="path to clang-format",
|
||||
),
|
||||
p.add_argument(
|
||||
"--commit",
|
||||
default=config.get("clangformat.commit", "HEAD"),
|
||||
help="default commit to use if none is specified",
|
||||
),
|
||||
p.add_argument(
|
||||
"--diff",
|
||||
action="store_true",
|
||||
help="print a diff instead of applying the changes",
|
||||
)
|
||||
p.add_argument(
|
||||
"--diffstat",
|
||||
action="store_true",
|
||||
help="print a diffstat instead of applying the changes",
|
||||
)
|
||||
p.add_argument(
|
||||
"--extensions",
|
||||
default=config.get("clangformat.extensions", default_extensions),
|
||||
help=(
|
||||
"comma-separated list of file extensions to format, "
|
||||
"excluding the period and case-insensitive"
|
||||
),
|
||||
),
|
||||
p.add_argument(
|
||||
"-f",
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="allow changes to unstaged files",
|
||||
)
|
||||
p.add_argument(
|
||||
"-p", "--patch", action="store_true", help="select hunks interactively"
|
||||
)
|
||||
p.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="count",
|
||||
default=0,
|
||||
help="print less information",
|
||||
)
|
||||
p.add_argument(
|
||||
"--staged",
|
||||
"--cached",
|
||||
action="store_true",
|
||||
help="format lines in the stage instead of the working dir",
|
||||
)
|
||||
p.add_argument(
|
||||
"--style",
|
||||
default=config.get("clangformat.style", None),
|
||||
help="passed to clang-format",
|
||||
),
|
||||
p.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="count",
|
||||
default=0,
|
||||
help="print extra information",
|
||||
)
|
||||
p.add_argument(
|
||||
"--diff_from_common_commit",
|
||||
action="store_true",
|
||||
help=(
|
||||
"diff from the last common commit for commits in "
|
||||
"separate branches rather than the exact point of the "
|
||||
"commits"
|
||||
),
|
||||
)
|
||||
# We gather all the remaining positional arguments into 'args' since we need
|
||||
# to use some heuristics to determine whether or not <commit> was present.
|
||||
# However, to print pretty messages, we make use of metavar and help.
|
||||
p.add_argument(
|
||||
"args",
|
||||
nargs="*",
|
||||
metavar="<commit>",
|
||||
help="revision from which to compute the diff",
|
||||
)
|
||||
p.add_argument(
|
||||
"ignored",
|
||||
nargs="*",
|
||||
metavar="<file>...",
|
||||
help="if specified, only consider differences in these files",
|
||||
)
|
||||
opts = p.parse_args(argv)
|
||||
|
||||
opts.verbose -= opts.quiet
|
||||
del opts.quiet
|
||||
|
||||
commits, files = interpret_args(opts.args, dash_dash, opts.commit)
|
||||
if len(commits) > 2:
|
||||
die("at most two commits allowed; %d given" % len(commits))
|
||||
if len(commits) == 2:
|
||||
if opts.staged:
|
||||
die("--staged is not allowed when two commits are given")
|
||||
if not opts.diff:
|
||||
die("--diff is required when two commits are given")
|
||||
elif opts.diff_from_common_commit:
|
||||
die("--diff_from_common_commit is only allowed when two commits are given")
|
||||
|
||||
if os.path.dirname(opts.binary):
|
||||
opts.binary = os.path.abspath(opts.binary)
|
||||
|
||||
changed_lines = compute_diff_and_extract_lines(
|
||||
commits, files, opts.staged, opts.diff_from_common_commit
|
||||
)
|
||||
if opts.verbose >= 1:
|
||||
ignored_files = set(changed_lines)
|
||||
filter_by_extension(changed_lines, opts.extensions.lower().split(","))
|
||||
# The computed diff outputs absolute paths, so we must cd before accessing
|
||||
# those files.
|
||||
cd_to_toplevel()
|
||||
filter_symlinks(changed_lines)
|
||||
filter_ignored_files(changed_lines, binary=opts.binary)
|
||||
if opts.verbose >= 1:
|
||||
ignored_files.difference_update(changed_lines)
|
||||
if ignored_files:
|
||||
print(
|
||||
"Ignoring the following files (wrong extension, symlink, or "
|
||||
"ignored by clang-format):"
|
||||
)
|
||||
for filename in ignored_files:
|
||||
print(" %s" % filename)
|
||||
if changed_lines:
|
||||
print("Running clang-format on the following files:")
|
||||
for filename in changed_lines:
|
||||
print(" %s" % filename)
|
||||
|
||||
if not changed_lines:
|
||||
if opts.verbose >= 0:
|
||||
print("no modified files to format")
|
||||
return 0
|
||||
|
||||
if len(commits) > 1:
|
||||
old_tree = commits[1]
|
||||
revision = old_tree
|
||||
elif opts.staged:
|
||||
old_tree = create_tree_from_index(changed_lines)
|
||||
revision = ""
|
||||
else:
|
||||
old_tree = create_tree_from_workdir(changed_lines)
|
||||
revision = None
|
||||
new_tree = run_clang_format_and_save_to_tree(
|
||||
changed_lines, revision, binary=opts.binary, style=opts.style
|
||||
)
|
||||
if opts.verbose >= 1:
|
||||
print("old tree: %s" % old_tree)
|
||||
print("new tree: %s" % new_tree)
|
||||
|
||||
if old_tree == new_tree:
|
||||
if opts.verbose >= 0:
|
||||
print("clang-format did not modify any files")
|
||||
return 0
|
||||
|
||||
if opts.diff:
|
||||
return print_diff(old_tree, new_tree)
|
||||
if opts.diffstat:
|
||||
return print_diffstat(old_tree, new_tree)
|
||||
|
||||
changed_files = apply_changes(
|
||||
old_tree, new_tree, force=opts.force, patch_mode=opts.patch
|
||||
)
|
||||
if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
|
||||
print("changed files:")
|
||||
for filename in changed_files:
|
||||
print(" %s" % filename)
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
def load_git_config(non_string_options=None):
|
||||
"""Return the git configuration as a dictionary.
|
||||
|
||||
All options are assumed to be strings unless in `non_string_options`, in
|
||||
which is a dictionary mapping option name (in lower case) to either "--bool"
|
||||
or "--int"."""
|
||||
if non_string_options is None:
|
||||
non_string_options = {}
|
||||
out = {}
|
||||
for entry in run("git", "config", "--list", "--null").split("\0"):
|
||||
if entry:
|
||||
if "\n" in entry:
|
||||
name, value = entry.split("\n", 1)
|
||||
else:
|
||||
# A setting with no '=' ('\n' with --null) is implicitly 'true'
|
||||
name = entry
|
||||
value = "true"
|
||||
if name in non_string_options:
|
||||
value = run("git", "config", non_string_options[name], name)
|
||||
out[name] = value
|
||||
return out
|
||||
|
||||
|
||||
def interpret_args(args, dash_dash, default_commit):
|
||||
"""Interpret `args` as "[commits] [--] [files]" and return (commits, files).
|
||||
|
||||
It is assumed that "--" and everything that follows has been removed from
|
||||
args and placed in `dash_dash`.
|
||||
|
||||
If "--" is present (i.e., `dash_dash` is non-empty), the arguments to its
|
||||
left (if present) are taken as commits. Otherwise, the arguments are
|
||||
checked from left to right if they are commits or files. If commits are not
|
||||
given, a list with `default_commit` is used."""
|
||||
if dash_dash:
|
||||
if len(args) == 0:
|
||||
commits = [default_commit]
|
||||
else:
|
||||
commits = args
|
||||
for commit in commits:
|
||||
object_type = get_object_type(commit)
|
||||
if object_type not in ("commit", "tag"):
|
||||
if object_type is None:
|
||||
die("'%s' is not a commit" % commit)
|
||||
else:
|
||||
die(
|
||||
"'%s' is a %s, but a commit was expected"
|
||||
% (commit, object_type)
|
||||
)
|
||||
files = dash_dash[1:]
|
||||
elif args:
|
||||
commits = []
|
||||
while args:
|
||||
if not disambiguate_revision(args[0]):
|
||||
break
|
||||
commits.append(args.pop(0))
|
||||
if not commits:
|
||||
commits = [default_commit]
|
||||
files = args
|
||||
else:
|
||||
commits = [default_commit]
|
||||
files = []
|
||||
return commits, files
|
||||
|
||||
|
||||
def disambiguate_revision(value):
|
||||
"""Returns True if `value` is a revision, False if it is a file, or dies."""
|
||||
# If `value` is ambiguous (neither a commit nor a file), the following
|
||||
# command will die with an appropriate error message.
|
||||
run("git", "rev-parse", value, verbose=False)
|
||||
object_type = get_object_type(value)
|
||||
if object_type is None:
|
||||
return False
|
||||
if object_type in ("commit", "tag"):
|
||||
return True
|
||||
die("`%s` is a %s, but a commit or filename was expected" % (value, object_type))
|
||||
|
||||
|
||||
def get_object_type(value):
|
||||
"""Returns a string description of an object's type, or None if it is not
|
||||
a valid git object."""
|
||||
cmd = ["git", "cat-file", "-t", value]
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
return None
|
||||
return convert_string(stdout.strip())
|
||||
|
||||
|
||||
def compute_diff_and_extract_lines(commits, files, staged, diff_common_commit):
|
||||
"""Calls compute_diff() followed by extract_lines()."""
|
||||
diff_process = compute_diff(commits, files, staged, diff_common_commit)
|
||||
changed_lines = extract_lines(diff_process.stdout)
|
||||
diff_process.stdout.close()
|
||||
diff_process.wait()
|
||||
if diff_process.returncode != 0:
|
||||
# Assume error was already printed to stderr.
|
||||
sys.exit(2)
|
||||
return changed_lines
|
||||
|
||||
|
||||
def compute_diff(commits, files, staged, diff_common_commit):
|
||||
"""Return a subprocess object producing the diff from `commits`.
|
||||
|
||||
The return value's `stdin` file object will produce a patch with the
|
||||
differences between the working directory (or stage if --staged is used) and
|
||||
the first commit if a single one was specified, or the difference between
|
||||
both specified commits, filtered on `files` (if non-empty).
|
||||
Zero context lines are used in the patch."""
|
||||
git_tool = "diff-index"
|
||||
extra_args = []
|
||||
if len(commits) == 2:
|
||||
git_tool = "diff-tree"
|
||||
if diff_common_commit:
|
||||
extra_args += ["--merge-base"]
|
||||
elif staged:
|
||||
extra_args += ["--cached"]
|
||||
|
||||
cmd = ["git", git_tool, "-p", "-U0"] + extra_args + commits + ["--"]
|
||||
cmd.extend(files)
|
||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
p.stdin.close()
|
||||
return p
|
||||
|
||||
|
||||
def extract_lines(patch_file):
|
||||
"""Extract the changed lines in `patch_file`.
|
||||
|
||||
The return value is a dictionary mapping filename to a list of (start_line,
|
||||
line_count) pairs.
|
||||
|
||||
The input must have been produced with ``-U0``, meaning unidiff format with
|
||||
zero lines of context. The return value is a dict mapping filename to a
|
||||
list of line `Range`s."""
|
||||
matches = {}
|
||||
for line in patch_file:
|
||||
line = convert_string(line)
|
||||
match = re.search(r"^\+\+\+\ [^/]+/(.*)", line)
|
||||
if match:
|
||||
filename = match.group(1).rstrip("\r\n\t")
|
||||
match = re.search(r"^@@ -[0-9,]+ \+(\d+)(,(\d+))?", line)
|
||||
if match:
|
||||
start_line = int(match.group(1))
|
||||
line_count = 1
|
||||
if match.group(3):
|
||||
line_count = int(match.group(3))
|
||||
if line_count == 0:
|
||||
line_count = 1
|
||||
if start_line == 0:
|
||||
continue
|
||||
matches.setdefault(filename, []).append(Range(start_line, line_count))
|
||||
return matches
|
||||
|
||||
|
||||
def filter_by_extension(dictionary, allowed_extensions):
|
||||
"""Delete every key in `dictionary` that doesn't have an allowed extension.
|
||||
|
||||
`allowed_extensions` must be a collection of lowercase file extensions,
|
||||
excluding the period."""
|
||||
allowed_extensions = frozenset(allowed_extensions)
|
||||
for filename in list(dictionary.keys()):
|
||||
base_ext = filename.rsplit(".", 1)
|
||||
if len(base_ext) == 1 and "" in allowed_extensions:
|
||||
continue
|
||||
if len(base_ext) == 1 or base_ext[1].lower() not in allowed_extensions:
|
||||
del dictionary[filename]
|
||||
|
||||
|
||||
def filter_symlinks(dictionary):
|
||||
"""Delete every key in `dictionary` that is a symlink."""
|
||||
for filename in list(dictionary.keys()):
|
||||
if os.path.islink(filename):
|
||||
del dictionary[filename]
|
||||
|
||||
|
||||
def filter_ignored_files(dictionary, binary):
|
||||
"""Delete every key in `dictionary` that is ignored by clang-format."""
|
||||
ignored_files = run(binary, "-list-ignored", *dictionary.keys())
|
||||
if not ignored_files:
|
||||
return
|
||||
ignored_files = ignored_files.split("\n")
|
||||
for filename in ignored_files:
|
||||
del dictionary[filename]
|
||||
|
||||
|
||||
def cd_to_toplevel():
|
||||
"""Change to the top level of the git repository."""
|
||||
toplevel = run("git", "rev-parse", "--show-toplevel")
|
||||
os.chdir(toplevel)
|
||||
|
||||
|
||||
def create_tree_from_workdir(filenames):
|
||||
"""Create a new git tree with the given files from the working directory.
|
||||
|
||||
Returns the object ID (SHA-1) of the created tree."""
|
||||
return create_tree(filenames, "--stdin")
|
||||
|
||||
|
||||
def create_tree_from_index(filenames):
|
||||
# Copy the environment, because the files have to be read from the original
|
||||
# index.
|
||||
env = os.environ.copy()
|
||||
|
||||
def index_contents_generator():
|
||||
for filename in filenames:
|
||||
git_ls_files_cmd = [
|
||||
"git",
|
||||
"ls-files",
|
||||
"--stage",
|
||||
"-z",
|
||||
"--",
|
||||
filename,
|
||||
]
|
||||
git_ls_files = subprocess.Popen(
|
||||
git_ls_files_cmd,
|
||||
env=env,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
stdout = git_ls_files.communicate()[0]
|
||||
yield convert_string(stdout.split(b"\0")[0])
|
||||
|
||||
return create_tree(index_contents_generator(), "--index-info")
|
||||
|
||||
|
||||
def run_clang_format_and_save_to_tree(
|
||||
changed_lines, revision=None, binary="clang-format", style=None
|
||||
):
|
||||
"""Run clang-format on each file and save the result to a git tree.
|
||||
|
||||
Returns the object ID (SHA-1) of the created tree."""
|
||||
# Copy the environment when formatting the files in the index, because the
|
||||
# files have to be read from the original index.
|
||||
env = os.environ.copy() if revision == "" else None
|
||||
|
||||
def iteritems(container):
|
||||
try:
|
||||
return container.iteritems() # Python 2
|
||||
except AttributeError:
|
||||
return container.items() # Python 3
|
||||
|
||||
def index_info_generator():
|
||||
for filename, line_ranges in iteritems(changed_lines):
|
||||
if revision is not None:
|
||||
if len(revision) > 0:
|
||||
git_metadata_cmd = [
|
||||
"git",
|
||||
"ls-tree",
|
||||
"%s:%s" % (revision, os.path.dirname(filename)),
|
||||
os.path.basename(filename),
|
||||
]
|
||||
else:
|
||||
git_metadata_cmd = [
|
||||
"git",
|
||||
"ls-files",
|
||||
"--stage",
|
||||
"--",
|
||||
filename,
|
||||
]
|
||||
git_metadata = subprocess.Popen(
|
||||
git_metadata_cmd,
|
||||
env=env,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
stdout = git_metadata.communicate()[0]
|
||||
mode = oct(int(stdout.split()[0], 8))
|
||||
else:
|
||||
mode = oct(os.stat(filename).st_mode)
|
||||
# Adjust python3 octal format so that it matches what git expects
|
||||
if mode.startswith("0o"):
|
||||
mode = "0" + mode[2:]
|
||||
blob_id = clang_format_to_blob(
|
||||
filename,
|
||||
line_ranges,
|
||||
revision=revision,
|
||||
binary=binary,
|
||||
style=style,
|
||||
env=env,
|
||||
)
|
||||
yield "%s %s\t%s" % (mode, blob_id, filename)
|
||||
|
||||
return create_tree(index_info_generator(), "--index-info")
|
||||
|
||||
|
||||
def create_tree(input_lines, mode):
|
||||
"""Create a tree object from the given input.
|
||||
|
||||
If mode is '--stdin', it must be a list of filenames. If mode is
|
||||
'--index-info' is must be a list of values suitable for "git update-index
|
||||
--index-info", such as "<mode> <SP> <sha1> <TAB> <filename>". Any other
|
||||
mode is invalid."""
|
||||
assert mode in ("--stdin", "--index-info")
|
||||
cmd = ["git", "update-index", "--add", "-z", mode]
|
||||
with temporary_index_file():
|
||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
|
||||
for line in input_lines:
|
||||
p.stdin.write(to_bytes("%s\0" % line))
|
||||
p.stdin.close()
|
||||
if p.wait() != 0:
|
||||
die("`%s` failed" % " ".join(cmd))
|
||||
tree_id = run("git", "write-tree")
|
||||
return tree_id
|
||||
|
||||
|
||||
def clang_format_to_blob(
|
||||
filename,
|
||||
line_ranges,
|
||||
revision=None,
|
||||
binary="clang-format",
|
||||
style=None,
|
||||
env=None,
|
||||
):
|
||||
"""Run clang-format on the given file and save the result to a git blob.
|
||||
|
||||
Runs on the file in `revision` if not None, or on the file in the working
|
||||
directory if `revision` is None. Revision can be set to an empty string to
|
||||
run clang-format on the file in the index.
|
||||
|
||||
Returns the object ID (SHA-1) of the created blob."""
|
||||
clang_format_cmd = [binary]
|
||||
if style:
|
||||
clang_format_cmd.extend(["--style=" + style])
|
||||
clang_format_cmd.extend(
|
||||
[
|
||||
"--lines=%s:%s" % (start_line, start_line + line_count - 1)
|
||||
for start_line, line_count in line_ranges
|
||||
]
|
||||
)
|
||||
if revision is not None:
|
||||
clang_format_cmd.extend(["--assume-filename=" + filename])
|
||||
git_show_cmd = [
|
||||
"git",
|
||||
"cat-file",
|
||||
"blob",
|
||||
"%s:%s" % (revision, filename),
|
||||
]
|
||||
git_show = subprocess.Popen(
|
||||
git_show_cmd, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
git_show.stdin.close()
|
||||
clang_format_stdin = git_show.stdout
|
||||
else:
|
||||
clang_format_cmd.extend([filename])
|
||||
git_show = None
|
||||
clang_format_stdin = subprocess.PIPE
|
||||
try:
|
||||
clang_format = subprocess.Popen(
|
||||
clang_format_cmd, stdin=clang_format_stdin, stdout=subprocess.PIPE
|
||||
)
|
||||
if clang_format_stdin == subprocess.PIPE:
|
||||
clang_format_stdin = clang_format.stdin
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
die('cannot find executable "%s"' % binary)
|
||||
else:
|
||||
raise
|
||||
clang_format_stdin.close()
|
||||
hash_object_cmd = [
|
||||
"git",
|
||||
"hash-object",
|
||||
"-w",
|
||||
"--path=" + filename,
|
||||
"--stdin",
|
||||
]
|
||||
hash_object = subprocess.Popen(
|
||||
hash_object_cmd, stdin=clang_format.stdout, stdout=subprocess.PIPE
|
||||
)
|
||||
clang_format.stdout.close()
|
||||
stdout = hash_object.communicate()[0]
|
||||
if hash_object.returncode != 0:
|
||||
die("`%s` failed" % " ".join(hash_object_cmd))
|
||||
if clang_format.wait() != 0:
|
||||
die("`%s` failed" % " ".join(clang_format_cmd))
|
||||
if git_show and git_show.wait() != 0:
|
||||
die("`%s` failed" % " ".join(git_show_cmd))
|
||||
return convert_string(stdout).rstrip("\r\n")
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def temporary_index_file(tree=None):
|
||||
"""Context manager for setting GIT_INDEX_FILE to a temporary file and
|
||||
deleting the file afterward."""
|
||||
index_path = create_temporary_index(tree)
|
||||
old_index_path = os.environ.get("GIT_INDEX_FILE")
|
||||
os.environ["GIT_INDEX_FILE"] = index_path
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if old_index_path is None:
|
||||
del os.environ["GIT_INDEX_FILE"]
|
||||
else:
|
||||
os.environ["GIT_INDEX_FILE"] = old_index_path
|
||||
os.remove(index_path)
|
||||
|
||||
|
||||
def create_temporary_index(tree=None):
|
||||
"""Create a temporary index file and return the created file's path.
|
||||
|
||||
If `tree` is not None, use that as the tree to read in. Otherwise, an
|
||||
empty index is created."""
|
||||
gitdir = run("git", "rev-parse", "--git-dir")
|
||||
path = os.path.join(gitdir, temp_index_basename)
|
||||
if tree is None:
|
||||
tree = "--empty"
|
||||
run("git", "read-tree", "--index-output=" + path, tree)
|
||||
return path
|
||||
|
||||
|
||||
def print_diff(old_tree, new_tree):
|
||||
"""Print the diff between the two trees to stdout."""
|
||||
# We use the porcelain 'diff' and not plumbing 'diff-tree' because the
|
||||
# output is expected to be viewed by the user, and only the former does nice
|
||||
# things like color and pagination.
|
||||
#
|
||||
# We also only print modified files since `new_tree` only contains the files
|
||||
# that were modified, so unmodified files would show as deleted without the
|
||||
# filter.
|
||||
return subprocess.run(
|
||||
["git", "diff", "--diff-filter=M", "--exit-code", old_tree, new_tree]
|
||||
).returncode
|
||||
|
||||
|
||||
def print_diffstat(old_tree, new_tree):
|
||||
"""Print the diffstat between the two trees to stdout."""
|
||||
# We use the porcelain 'diff' and not plumbing 'diff-tree' because the
|
||||
# output is expected to be viewed by the user, and only the former does nice
|
||||
# things like color and pagination.
|
||||
#
|
||||
# We also only print modified files since `new_tree` only contains the files
|
||||
# that were modified, so unmodified files would show as deleted without the
|
||||
# filter.
|
||||
return subprocess.run(
|
||||
[
|
||||
"git",
|
||||
"diff",
|
||||
"--diff-filter=M",
|
||||
"--exit-code",
|
||||
"--stat",
|
||||
old_tree,
|
||||
new_tree,
|
||||
]
|
||||
).returncode
|
||||
|
||||
|
||||
def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
|
||||
"""Apply the changes in `new_tree` to the working directory.
|
||||
|
||||
Bails if there are local changes in those files and not `force`. If
|
||||
`patch_mode`, runs `git checkout --patch` to select hunks interactively."""
|
||||
changed_files = (
|
||||
run(
|
||||
"git",
|
||||
"diff-tree",
|
||||
"--diff-filter=M",
|
||||
"-r",
|
||||
"-z",
|
||||
"--name-only",
|
||||
old_tree,
|
||||
new_tree,
|
||||
)
|
||||
.rstrip("\0")
|
||||
.split("\0")
|
||||
)
|
||||
if not force:
|
||||
unstaged_files = run("git", "diff-files", "--name-status", *changed_files)
|
||||
if unstaged_files:
|
||||
print(
|
||||
"The following files would be modified but have unstaged changes:",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(unstaged_files, file=sys.stderr)
|
||||
print("Please commit, stage, or stash them first.", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if patch_mode:
|
||||
# In patch mode, we could just as well create an index from the new tree
|
||||
# and checkout from that, but then the user will be presented with a
|
||||
# message saying "Discard ... from worktree". Instead, we use the old
|
||||
# tree as the index and checkout from new_tree, which gives the slightly
|
||||
# better message, "Apply ... to index and worktree". This is not quite
|
||||
# right, since it won't be applied to the user's index, but oh well.
|
||||
with temporary_index_file(old_tree):
|
||||
subprocess.run(["git", "checkout", "--patch", new_tree], check=True)
|
||||
index_tree = old_tree
|
||||
else:
|
||||
with temporary_index_file(new_tree):
|
||||
run("git", "checkout-index", "-f", "--", *changed_files)
|
||||
return changed_files
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
stdin = kwargs.pop("stdin", "")
|
||||
verbose = kwargs.pop("verbose", True)
|
||||
strip = kwargs.pop("strip", True)
|
||||
for name in kwargs:
|
||||
raise TypeError("run() got an unexpected keyword argument '%s'" % name)
|
||||
p = subprocess.Popen(
|
||||
args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
stdin=subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = p.communicate(input=stdin)
|
||||
|
||||
stdout = convert_string(stdout)
|
||||
stderr = convert_string(stderr)
|
||||
|
||||
if p.returncode == 0:
|
||||
if stderr:
|
||||
if verbose:
|
||||
print("`%s` printed to stderr:" % " ".join(args), file=sys.stderr)
|
||||
print(stderr.rstrip(), file=sys.stderr)
|
||||
if strip:
|
||||
stdout = stdout.rstrip("\r\n")
|
||||
return stdout
|
||||
if verbose:
|
||||
print("`%s` returned %s" % (" ".join(args), p.returncode), file=sys.stderr)
|
||||
if stderr:
|
||||
print(stderr.rstrip(), file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
def die(message):
|
||||
print("error:", message, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
def to_bytes(str_input):
|
||||
# Encode to UTF-8 to get binary data.
|
||||
if isinstance(str_input, bytes):
|
||||
return str_input
|
||||
return str_input.encode("utf-8")
|
||||
|
||||
|
||||
def to_string(bytes_input):
|
||||
if isinstance(bytes_input, str):
|
||||
return bytes_input
|
||||
return bytes_input.encode("utf-8")
|
||||
|
||||
|
||||
def convert_string(bytes_input):
|
||||
try:
|
||||
return to_string(bytes_input.decode("utf-8"))
|
||||
except AttributeError: # 'str' object has no attribute 'decode'.
|
||||
return str(bytes_input)
|
||||
except UnicodeError:
|
||||
return str(bytes_input)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,297 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
from ctypes import ArgumentError
|
||||
import json
|
||||
import optparse
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
###
|
||||
|
||||
k_header_magic_LE = b'pamh'
|
||||
k_header_magic_BE = b'hmap'
|
||||
|
||||
def hmap_hash(str):
|
||||
"""hash(str) -> int
|
||||
|
||||
Apply the "well-known" headermap hash function.
|
||||
"""
|
||||
|
||||
return sum((ord(c.lower()) * 13
|
||||
for c in str), 0)
|
||||
|
||||
class HeaderMap(object):
|
||||
@staticmethod
|
||||
def frompath(path):
|
||||
with open(path, 'rb') as f:
|
||||
magic = f.read(4)
|
||||
if magic == k_header_magic_LE:
|
||||
endian_code = '<'
|
||||
elif magic == k_header_magic_BE:
|
||||
endian_code = '>'
|
||||
else:
|
||||
raise SystemExit("error: %s: not a headermap" % (
|
||||
path,))
|
||||
|
||||
# Read the header information.
|
||||
header_fmt = endian_code + 'HHIIII'
|
||||
header_size = struct.calcsize(header_fmt)
|
||||
data = f.read(header_size)
|
||||
if len(data) != header_size:
|
||||
raise SystemExit("error: %s: truncated headermap header" % (
|
||||
path,))
|
||||
|
||||
(version, reserved, strtable_offset, num_entries,
|
||||
num_buckets, _) = struct.unpack(header_fmt, data)
|
||||
|
||||
if version != 1:
|
||||
raise SystemExit("error: %s: unknown headermap version: %r" % (
|
||||
path, version))
|
||||
if reserved != 0:
|
||||
raise SystemExit("error: %s: invalid reserved value in header" % (
|
||||
path,))
|
||||
|
||||
# The number of buckets must be a power of two.
|
||||
if num_buckets == 0 or (num_buckets & num_buckets - 1) != 0:
|
||||
raise SystemExit("error: %s: invalid number of buckets" % (
|
||||
path,))
|
||||
|
||||
# Read all of the buckets.
|
||||
bucket_fmt = endian_code + 'III'
|
||||
bucket_size = struct.calcsize(bucket_fmt)
|
||||
buckets_data = f.read(num_buckets * bucket_size)
|
||||
if len(buckets_data) != num_buckets * bucket_size:
|
||||
raise SystemExit("error: %s: truncated headermap buckets" % (
|
||||
path,))
|
||||
buckets = [struct.unpack(bucket_fmt,
|
||||
buckets_data[i*bucket_size:(i+1)*bucket_size])
|
||||
for i in range(num_buckets)]
|
||||
|
||||
# Read the string table; the format doesn't explicitly communicate the
|
||||
# size of the string table (which is dumb), so assume it is the rest of
|
||||
# the file.
|
||||
f.seek(0, 2)
|
||||
strtable_size = f.tell() - strtable_offset
|
||||
f.seek(strtable_offset)
|
||||
|
||||
if strtable_size == 0:
|
||||
raise SystemExit("error: %s: unable to read zero-sized string table"%(
|
||||
path,))
|
||||
strtable = f.read(strtable_size)
|
||||
|
||||
if len(strtable) != strtable_size:
|
||||
raise SystemExit("error: %s: unable to read complete string table"%(
|
||||
path,))
|
||||
if strtable[-1] != 0:
|
||||
raise SystemExit("error: %s: invalid string table in headermap" % (
|
||||
path,))
|
||||
|
||||
return HeaderMap(num_entries, buckets, strtable)
|
||||
|
||||
def __init__(self, num_entries, buckets, strtable):
|
||||
self.num_entries = num_entries
|
||||
self.buckets = buckets
|
||||
self.strtable = strtable
|
||||
|
||||
def get_string(self, idx):
|
||||
if idx >= len(self.strtable):
|
||||
raise SystemExit("error: %s: invalid string index" % (
|
||||
idx,))
|
||||
end_idx = self.strtable.index(0, idx)
|
||||
return self.strtable[idx:end_idx].decode()
|
||||
|
||||
@property
|
||||
def mappings(self):
|
||||
for key_idx,prefix_idx,suffix_idx in self.buckets:
|
||||
if key_idx == 0:
|
||||
continue
|
||||
yield (self.get_string(key_idx),
|
||||
self.get_string(prefix_idx) + self.get_string(suffix_idx))
|
||||
|
||||
###
|
||||
|
||||
def action_dump(name, args):
|
||||
"dump a headermap file"
|
||||
|
||||
parser = optparse.OptionParser("%%prog %s [options] <headermap path>" % (
|
||||
name,))
|
||||
parser.add_option("-v", "--verbose", dest="verbose",
|
||||
help="show more verbose output [%default]",
|
||||
action="store_true", default=False)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("invalid number of arguments")
|
||||
|
||||
path, = args
|
||||
|
||||
hmap = HeaderMap.frompath(path)
|
||||
|
||||
# Dump all of the buckets.
|
||||
print ('Header Map: %s' % (path,))
|
||||
if opts.verbose:
|
||||
print ('headermap: %r' % (path,))
|
||||
print (' num entries: %d' % (hmap.num_entries,))
|
||||
print (' num buckets: %d' % (len(hmap.buckets),))
|
||||
print (' string table size: %d' % (len(hmap.strtable),))
|
||||
for i,bucket in enumerate(hmap.buckets):
|
||||
key_idx,prefix_idx,suffix_idx = bucket
|
||||
|
||||
if key_idx == 0:
|
||||
continue
|
||||
|
||||
# Get the strings.
|
||||
key = hmap.get_string(key_idx)
|
||||
prefix = hmap.get_string(prefix_idx)
|
||||
suffix = hmap.get_string(suffix_idx)
|
||||
|
||||
print (" bucket[%d]: %r -> (%r, %r) -- %d" % (
|
||||
i, key, prefix, suffix, (hmap_hash(key) & (len(hmap.buckets) - 1))))
|
||||
else:
|
||||
mappings = sorted(hmap.mappings)
|
||||
for key,value in mappings:
|
||||
print ("%s -> %s" % (key, value))
|
||||
print ()
|
||||
|
||||
def next_power_of_two(value):
|
||||
if value < 0:
|
||||
raise ArgumentError
|
||||
return 1 if value == 0 else 2**(value - 1).bit_length()
|
||||
|
||||
def action_write(name, args):
|
||||
"write a headermap file from a JSON definition"
|
||||
|
||||
parser = optparse.OptionParser("%%prog %s [options] <input path> <output path>" % (
|
||||
name,))
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) != 2:
|
||||
parser.error("invalid number of arguments")
|
||||
|
||||
input_path,output_path = args
|
||||
|
||||
with open(input_path, "r") as f:
|
||||
input_data = json.load(f)
|
||||
|
||||
# Compute the headermap contents, we make a table that is 1/3 full.
|
||||
mappings = input_data['mappings']
|
||||
num_buckets = next_power_of_two(len(mappings) * 3)
|
||||
|
||||
table = [(0, 0, 0)
|
||||
for i in range(num_buckets)]
|
||||
max_value_len = 0
|
||||
strtable = "\0"
|
||||
for key,value in mappings.items():
|
||||
if not isinstance(key, str):
|
||||
key = key.decode('utf-8')
|
||||
if not isinstance(value, str):
|
||||
value = value.decode('utf-8')
|
||||
max_value_len = max(max_value_len, len(value))
|
||||
|
||||
key_idx = len(strtable)
|
||||
strtable += key + '\0'
|
||||
prefix = os.path.dirname(value) + '/'
|
||||
suffix = os.path.basename(value)
|
||||
prefix_idx = len(strtable)
|
||||
strtable += prefix + '\0'
|
||||
suffix_idx = len(strtable)
|
||||
strtable += suffix + '\0'
|
||||
|
||||
hash = hmap_hash(key)
|
||||
for i in range(num_buckets):
|
||||
idx = (hash + i) % num_buckets
|
||||
if table[idx][0] == 0:
|
||||
table[idx] = (key_idx, prefix_idx, suffix_idx)
|
||||
break
|
||||
else:
|
||||
raise RuntimeError
|
||||
|
||||
endian_code = '<'
|
||||
magic = k_header_magic_LE
|
||||
magic_size = 4
|
||||
header_fmt = endian_code + 'HHIIII'
|
||||
header_size = struct.calcsize(header_fmt)
|
||||
bucket_fmt = endian_code + 'III'
|
||||
bucket_size = struct.calcsize(bucket_fmt)
|
||||
strtable_offset = magic_size + header_size + num_buckets * bucket_size
|
||||
header = (1, 0, strtable_offset, len(mappings),
|
||||
num_buckets, max_value_len)
|
||||
|
||||
# Write out the headermap.
|
||||
with open(output_path, 'wb') as f:
|
||||
f.write(magic)
|
||||
f.write(struct.pack(header_fmt, *header))
|
||||
for bucket in table:
|
||||
f.write(struct.pack(bucket_fmt, *bucket))
|
||||
f.write(strtable.encode())
|
||||
|
||||
def action_tovfs(name, args):
|
||||
"convert a headermap to a VFS layout"
|
||||
|
||||
parser = optparse.OptionParser("%%prog %s [options] <headermap path>" % (
|
||||
name,))
|
||||
parser.add_option("", "--build-path", dest="build_path",
|
||||
help="build path prefix",
|
||||
action="store", type=str)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) != 2:
|
||||
parser.error("invalid number of arguments")
|
||||
if opts.build_path is None:
|
||||
parser.error("--build-path is required")
|
||||
|
||||
input_path,output_path = args
|
||||
|
||||
hmap = HeaderMap.frompath(input_path)
|
||||
|
||||
# Create the table for all the objects.
|
||||
vfs = {}
|
||||
vfs['version'] = 0
|
||||
build_dir_contents = []
|
||||
vfs['roots'] = [{
|
||||
'name' : opts.build_path,
|
||||
'type' : 'directory',
|
||||
'contents' : build_dir_contents }]
|
||||
|
||||
# We assume we are mapping framework paths, so a key of "Foo/Bar.h" maps to
|
||||
# "<build path>/Foo.framework/Headers/Bar.h".
|
||||
for key,value in hmap.mappings:
|
||||
# If this isn't a framework style mapping, ignore it.
|
||||
components = key.split('/')
|
||||
if len(components) != 2:
|
||||
continue
|
||||
framework_name,header_name = components
|
||||
build_dir_contents.append({
|
||||
'name' : '%s.framework/Headers/%s' % (framework_name,
|
||||
header_name),
|
||||
'type' : 'file',
|
||||
'external-contents' : value })
|
||||
|
||||
with open(output_path, 'w') as f:
|
||||
json.dump(vfs, f, indent=2)
|
||||
|
||||
commands = dict((name[7:].replace("_","-"), f)
|
||||
for name,f in locals().items()
|
||||
if name.startswith('action_'))
|
||||
|
||||
def usage():
|
||||
print ("Usage: %s command [options]" % (
|
||||
os.path.basename(sys.argv[0])), file=sys.stderr)
|
||||
print (file=sys.stderr)
|
||||
print ("Available commands:", file=sys.stderr)
|
||||
cmds_width = max(map(len, commands))
|
||||
for name,func in sorted(commands.items()):
|
||||
print (" %-*s - %s" % (cmds_width, name, func.__doc__), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2 or sys.argv[1] not in commands:
|
||||
usage()
|
||||
|
||||
cmd = sys.argv[1]
|
||||
commands[cmd](cmd, sys.argv[2:])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import os.path
|
||||
this_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
|
||||
|
||||
from libscanbuild.intercept import intercept_build
|
||||
|
||||
if __name__ == '__main__':
|
||||
multiprocessing.freeze_support()
|
||||
sys.exit(intercept_build())
|
||||
@@ -0,0 +1 @@
|
||||
lld
|
||||
@@ -0,0 +1 @@
|
||||
lld
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llc.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.lld.bin" "$@"
|
||||
@@ -0,0 +1 @@
|
||||
lld
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-ar.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-as.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-dis.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-link.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-nm.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-objcopy.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.llvm-objdump.bin" "$@"
|
||||
@@ -0,0 +1 @@
|
||||
llvm-ar
|
||||
@@ -0,0 +1 @@
|
||||
llvm-objcopy
|
||||
@@ -0,0 +1 @@
|
||||
offload-arch
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.offload-arch.bin" "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
dir="$(dirname "$0")"
|
||||
export RUNAS_ARG0="$0"
|
||||
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$dir/../../lib/runas.so"
|
||||
exec "$dir/../../lib/ld-linux-x86-64.so.2" --library-path "$dir/../../lib/" "$dir/.opt.bin" "$@"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
import multiprocessing
|
||||
import sys
|
||||
import os.path
|
||||
this_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
sys.path.append(os.path.join(os.path.dirname(this_dir), 'lib'))
|
||||
|
||||
from libscanbuild.analyze import scan_build
|
||||
|
||||
if __name__ == '__main__':
|
||||
multiprocessing.freeze_support()
|
||||
sys.exit(scan_build())
|
||||
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
"""The clang static analyzer results viewer.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import posixpath
|
||||
import threading
|
||||
import time
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
import webbrowser
|
||||
|
||||
# How long to wait for server to start.
|
||||
kSleepTimeout = .05
|
||||
kMaxSleeps = int(60 / kSleepTimeout)
|
||||
|
||||
# Default server parameters
|
||||
|
||||
kDefaultHost = '127.0.0.1'
|
||||
kDefaultPort = 8181
|
||||
kMaxPortsToTry = 100
|
||||
|
||||
###
|
||||
|
||||
|
||||
def url_is_up(url):
|
||||
try:
|
||||
o = urlopen(url)
|
||||
except IOError:
|
||||
return False
|
||||
o.close()
|
||||
return True
|
||||
|
||||
|
||||
def start_browser(port, options):
|
||||
import webbrowser
|
||||
|
||||
url = 'http://%s:%d' % (options.host, port)
|
||||
|
||||
# Wait for server to start...
|
||||
if options.debug:
|
||||
sys.stderr.write('%s: Waiting for server.' % sys.argv[0])
|
||||
sys.stderr.flush()
|
||||
for i in range(kMaxSleeps):
|
||||
if url_is_up(url):
|
||||
break
|
||||
if options.debug:
|
||||
sys.stderr.write('.')
|
||||
sys.stderr.flush()
|
||||
time.sleep(kSleepTimeout)
|
||||
else:
|
||||
print('WARNING: Unable to detect that server started.', file=sys.stderr)
|
||||
|
||||
if options.debug:
|
||||
print('%s: Starting webbrowser...' % sys.argv[0], file=sys.stderr)
|
||||
webbrowser.open(url)
|
||||
|
||||
|
||||
def run(port, options, root):
|
||||
# Prefer to look relative to the installed binary
|
||||
share = os.path.dirname(__file__) + "/../share/scan-view"
|
||||
if not os.path.isdir(share):
|
||||
# Otherwise look relative to the source
|
||||
share = os.path.dirname(__file__) + "/../../scan-view/share"
|
||||
sys.path.append(share)
|
||||
|
||||
import ScanView
|
||||
try:
|
||||
print('Starting scan-view at: http://%s:%d' % (options.host,
|
||||
port))
|
||||
print(' Use Ctrl-C to exit.')
|
||||
httpd = ScanView.create_server((options.host, port),
|
||||
options, root)
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
def port_is_open(port):
|
||||
try:
|
||||
import socketserver
|
||||
except ImportError:
|
||||
import SocketServer as socketserver
|
||||
try:
|
||||
t = socketserver.TCPServer((kDefaultHost, port), None)
|
||||
except:
|
||||
return False
|
||||
t.server_close()
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description="The clang static analyzer "
|
||||
"results viewer.")
|
||||
parser.add_argument("root", metavar="<results directory>", type=str)
|
||||
parser.add_argument(
|
||||
'--host', dest="host", default=kDefaultHost, type=str,
|
||||
help="Host interface to listen on. (default=%s)" % kDefaultHost)
|
||||
parser.add_argument('--port', dest="port", default=None, type=int,
|
||||
help="Port to listen on. (default=%s)" % kDefaultPort)
|
||||
parser.add_argument("--debug", dest="debug", default=0,
|
||||
action="count",
|
||||
help="Print additional debugging information.")
|
||||
parser.add_argument("--auto-reload", dest="autoReload", default=False,
|
||||
action="store_true",
|
||||
help="Automatically update module for each request.")
|
||||
parser.add_argument("--no-browser", dest="startBrowser", default=True,
|
||||
action="store_false",
|
||||
help="Don't open a webbrowser on startup.")
|
||||
parser.add_argument("--allow-all-hosts", dest="onlyServeLocal",
|
||||
default=True, action="store_false",
|
||||
help='Allow connections from any host (access '
|
||||
'restricted to "127.0.0.1" by default)')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Make sure this directory is in a reasonable state to view.
|
||||
if not posixpath.exists(posixpath.join(args.root, 'index.html')):
|
||||
parser.error('Invalid directory, analysis results not found!')
|
||||
|
||||
# Find an open port. We aren't particularly worried about race
|
||||
# conditions here. Note that if the user specified a port we only
|
||||
# use that one.
|
||||
if args.port is not None:
|
||||
port = args.port
|
||||
else:
|
||||
for i in range(kMaxPortsToTry):
|
||||
if port_is_open(kDefaultPort + i):
|
||||
port = kDefaultPort + i
|
||||
break
|
||||
else:
|
||||
parser.error('Unable to find usable port in [%d,%d)' %
|
||||
(kDefaultPort, kDefaultPort+kMaxPortsToTry))
|
||||
|
||||
# Kick off thread to wait for server and start web browser, if
|
||||
# requested.
|
||||
if args.startBrowser:
|
||||
threading.Thread(target=start_browser, args=(port, args)).start()
|
||||
|
||||
run(port, args, args.root)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1 @@
|
||||
lld
|
||||
@@ -0,0 +1,153 @@
|
||||
/*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides various utilities for use by build systems. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_BUILDSYSTEM_H
|
||||
#define LLVM_CLANG_C_BUILDSYSTEM_H
|
||||
|
||||
#include "clang-c/CXErrorCode.h"
|
||||
#include "clang-c/CXString.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup BUILD_SYSTEM Build system utilities
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the timestamp for use with Clang's
|
||||
* \c -fbuild-session-timestamp= option.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned long long clang_getBuildSessionTimestamp(void);
|
||||
|
||||
/**
|
||||
* Object encapsulating information about overlaying virtual
|
||||
* file/directories over the real file system.
|
||||
*/
|
||||
typedef struct CXVirtualFileOverlayImpl *CXVirtualFileOverlay;
|
||||
|
||||
/**
|
||||
* Create a \c CXVirtualFileOverlay object.
|
||||
* Must be disposed with \c clang_VirtualFileOverlay_dispose().
|
||||
*
|
||||
* \param options is reserved, always pass 0.
|
||||
*/
|
||||
CINDEX_LINKAGE CXVirtualFileOverlay
|
||||
clang_VirtualFileOverlay_create(unsigned options);
|
||||
|
||||
/**
|
||||
* Map an absolute virtual file path to an absolute real one.
|
||||
* The virtual path must be canonicalized (not contain "."/"..").
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay,
|
||||
const char *virtualPath,
|
||||
const char *realPath);
|
||||
|
||||
/**
|
||||
* Set the case sensitivity for the \c CXVirtualFileOverlay object.
|
||||
* The \c CXVirtualFileOverlay object is case-sensitive by default, this
|
||||
* option can be used to override the default.
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay,
|
||||
int caseSensitive);
|
||||
|
||||
/**
|
||||
* Write out the \c CXVirtualFileOverlay object to a char buffer.
|
||||
*
|
||||
* \param options is reserved, always pass 0.
|
||||
* \param out_buffer_ptr pointer to receive the buffer pointer, which should be
|
||||
* disposed using \c clang_free().
|
||||
* \param out_buffer_size pointer to receive the buffer size.
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options,
|
||||
char **out_buffer_ptr,
|
||||
unsigned *out_buffer_size);
|
||||
|
||||
/**
|
||||
* free memory allocated by libclang, such as the buffer returned by
|
||||
* \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer().
|
||||
*
|
||||
* \param buffer memory pointer to free.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_free(void *buffer);
|
||||
|
||||
/**
|
||||
* Dispose a \c CXVirtualFileOverlay object.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay);
|
||||
|
||||
/**
|
||||
* Object encapsulating information about a module.modulemap file.
|
||||
*/
|
||||
typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor;
|
||||
|
||||
/**
|
||||
* Create a \c CXModuleMapDescriptor object.
|
||||
* Must be disposed with \c clang_ModuleMapDescriptor_dispose().
|
||||
*
|
||||
* \param options is reserved, always pass 0.
|
||||
*/
|
||||
CINDEX_LINKAGE CXModuleMapDescriptor
|
||||
clang_ModuleMapDescriptor_create(unsigned options);
|
||||
|
||||
/**
|
||||
* Sets the framework module name that the module.modulemap describes.
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Sets the umbrella header name that the module.modulemap describes.
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* Write out the \c CXModuleMapDescriptor object to a char buffer.
|
||||
*
|
||||
* \param options is reserved, always pass 0.
|
||||
* \param out_buffer_ptr pointer to receive the buffer pointer, which should be
|
||||
* disposed using \c clang_free().
|
||||
* \param out_buffer_size pointer to receive the buffer size.
|
||||
* \returns 0 for success, non-zero to indicate an error.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode
|
||||
clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options,
|
||||
char **out_buffer_ptr,
|
||||
unsigned *out_buffer_size);
|
||||
|
||||
/**
|
||||
* Dispose a \c CXModuleMapDescriptor object.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif /* CLANG_C_BUILD_SYSTEM_H */
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides a public interface to use CompilationDatabase without *|
|
||||
|* the full Clang C++ API. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
|
||||
#define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
|
||||
|
||||
#include "clang-c/CXString.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/** \defgroup COMPILATIONDB CompilationDatabase functions
|
||||
* \ingroup CINDEX
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A compilation database holds all information used to compile files in a
|
||||
* project. For each file in the database, it can be queried for the working
|
||||
* directory or the command line used for the compiler invocation.
|
||||
*
|
||||
* Must be freed by \c clang_CompilationDatabase_dispose
|
||||
*/
|
||||
typedef void * CXCompilationDatabase;
|
||||
|
||||
/**
|
||||
* Contains the results of a search in the compilation database
|
||||
*
|
||||
* When searching for the compile command for a file, the compilation db can
|
||||
* return several commands, as the file may have been compiled with
|
||||
* different options in different places of the project. This choice of compile
|
||||
* commands is wrapped in this opaque data structure. It must be freed by
|
||||
* \c clang_CompileCommands_dispose.
|
||||
*/
|
||||
typedef void * CXCompileCommands;
|
||||
|
||||
/**
|
||||
* Represents the command line invocation to compile a specific file.
|
||||
*/
|
||||
typedef void * CXCompileCommand;
|
||||
|
||||
/**
|
||||
* Error codes for Compilation Database
|
||||
*/
|
||||
typedef enum {
|
||||
/*
|
||||
* No error occurred
|
||||
*/
|
||||
CXCompilationDatabase_NoError = 0,
|
||||
|
||||
/*
|
||||
* Database can not be loaded
|
||||
*/
|
||||
CXCompilationDatabase_CanNotLoadDatabase = 1
|
||||
|
||||
} CXCompilationDatabase_Error;
|
||||
|
||||
/**
|
||||
* Creates a compilation database from the database found in directory
|
||||
* buildDir. For example, CMake can output a compile_commands.json which can
|
||||
* be used to build the database.
|
||||
*
|
||||
* It must be freed by \c clang_CompilationDatabase_dispose.
|
||||
*/
|
||||
CINDEX_LINKAGE CXCompilationDatabase
|
||||
clang_CompilationDatabase_fromDirectory(const char *BuildDir,
|
||||
CXCompilationDatabase_Error *ErrorCode);
|
||||
|
||||
/**
|
||||
* Free the given compilation database
|
||||
*/
|
||||
CINDEX_LINKAGE void
|
||||
clang_CompilationDatabase_dispose(CXCompilationDatabase);
|
||||
|
||||
/**
|
||||
* Find the compile commands used for a file. The compile commands
|
||||
* must be freed by \c clang_CompileCommands_dispose.
|
||||
*/
|
||||
CINDEX_LINKAGE CXCompileCommands
|
||||
clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
|
||||
const char *CompleteFileName);
|
||||
|
||||
/**
|
||||
* Get all the compile commands in the given compilation database.
|
||||
*/
|
||||
CINDEX_LINKAGE CXCompileCommands
|
||||
clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
|
||||
|
||||
/**
|
||||
* Free the given CompileCommands
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
|
||||
|
||||
/**
|
||||
* Get the number of CompileCommand we have for a file
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned
|
||||
clang_CompileCommands_getSize(CXCompileCommands);
|
||||
|
||||
/**
|
||||
* Get the I'th CompileCommand for a file
|
||||
*
|
||||
* Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
|
||||
*/
|
||||
CINDEX_LINKAGE CXCompileCommand
|
||||
clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
|
||||
|
||||
/**
|
||||
* Get the working directory where the CompileCommand was executed from
|
||||
*/
|
||||
CINDEX_LINKAGE CXString
|
||||
clang_CompileCommand_getDirectory(CXCompileCommand);
|
||||
|
||||
/**
|
||||
* Get the filename associated with the CompileCommand.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString
|
||||
clang_CompileCommand_getFilename(CXCompileCommand);
|
||||
|
||||
/**
|
||||
* Get the number of arguments in the compiler invocation.
|
||||
*
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned
|
||||
clang_CompileCommand_getNumArgs(CXCompileCommand);
|
||||
|
||||
/**
|
||||
* Get the I'th argument value in the compiler invocations
|
||||
*
|
||||
* Invariant :
|
||||
* - argument 0 is the compiler executable
|
||||
*/
|
||||
CINDEX_LINKAGE CXString
|
||||
clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
|
||||
|
||||
/**
|
||||
* Get the number of source mappings for the compiler invocation.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned
|
||||
clang_CompileCommand_getNumMappedSources(CXCompileCommand);
|
||||
|
||||
/**
|
||||
* Get the I'th mapped source path for the compiler invocation.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString
|
||||
clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
|
||||
|
||||
/**
|
||||
* Get the I'th mapped source content for the compiler invocation.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString
|
||||
clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
/*===-- clang-c/CXDiagnostic.h - C Index Diagnostics --------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides the interface to C Index diagnostics. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXDIAGNOSTIC_H
|
||||
#define LLVM_CLANG_C_CXDIAGNOSTIC_H
|
||||
|
||||
#include "clang-c/CXSourceLocation.h"
|
||||
#include "clang-c/CXString.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup CINDEX_DIAG Diagnostic reporting
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Describes the severity of a particular diagnostic.
|
||||
*/
|
||||
enum CXDiagnosticSeverity {
|
||||
/**
|
||||
* A diagnostic that has been suppressed, e.g., by a command-line
|
||||
* option.
|
||||
*/
|
||||
CXDiagnostic_Ignored = 0,
|
||||
|
||||
/**
|
||||
* This diagnostic is a note that should be attached to the
|
||||
* previous (non-note) diagnostic.
|
||||
*/
|
||||
CXDiagnostic_Note = 1,
|
||||
|
||||
/**
|
||||
* This diagnostic indicates suspicious code that may not be
|
||||
* wrong.
|
||||
*/
|
||||
CXDiagnostic_Warning = 2,
|
||||
|
||||
/**
|
||||
* This diagnostic indicates that the code is ill-formed.
|
||||
*/
|
||||
CXDiagnostic_Error = 3,
|
||||
|
||||
/**
|
||||
* This diagnostic indicates that the code is ill-formed such
|
||||
* that future parser recovery is unlikely to produce useful
|
||||
* results.
|
||||
*/
|
||||
CXDiagnostic_Fatal = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* A single diagnostic, containing the diagnostic's severity,
|
||||
* location, text, source ranges, and fix-it hints.
|
||||
*/
|
||||
typedef void *CXDiagnostic;
|
||||
|
||||
/**
|
||||
* A group of CXDiagnostics.
|
||||
*/
|
||||
typedef void *CXDiagnosticSet;
|
||||
|
||||
/**
|
||||
* Determine the number of diagnostics in a CXDiagnosticSet.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
|
||||
|
||||
/**
|
||||
* Retrieve a diagnostic associated with the given CXDiagnosticSet.
|
||||
*
|
||||
* \param Diags the CXDiagnosticSet to query.
|
||||
* \param Index the zero-based diagnostic number to retrieve.
|
||||
*
|
||||
* \returns the requested diagnostic. This diagnostic must be freed
|
||||
* via a call to \c clang_disposeDiagnostic().
|
||||
*/
|
||||
CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
|
||||
unsigned Index);
|
||||
|
||||
/**
|
||||
* Describes the kind of error that occurred (if any) in a call to
|
||||
* \c clang_loadDiagnostics.
|
||||
*/
|
||||
enum CXLoadDiag_Error {
|
||||
/**
|
||||
* Indicates that no error occurred.
|
||||
*/
|
||||
CXLoadDiag_None = 0,
|
||||
|
||||
/**
|
||||
* Indicates that an unknown error occurred while attempting to
|
||||
* deserialize diagnostics.
|
||||
*/
|
||||
CXLoadDiag_Unknown = 1,
|
||||
|
||||
/**
|
||||
* Indicates that the file containing the serialized diagnostics
|
||||
* could not be opened.
|
||||
*/
|
||||
CXLoadDiag_CannotLoad = 2,
|
||||
|
||||
/**
|
||||
* Indicates that the serialized diagnostics file is invalid or
|
||||
* corrupt.
|
||||
*/
|
||||
CXLoadDiag_InvalidFile = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Deserialize a set of diagnostics from a Clang diagnostics bitcode
|
||||
* file.
|
||||
*
|
||||
* \param file The name of the file to deserialize.
|
||||
* \param error A pointer to a enum value recording if there was a problem
|
||||
* deserializing the diagnostics.
|
||||
* \param errorString A pointer to a CXString for recording the error string
|
||||
* if the file was not successfully loaded.
|
||||
*
|
||||
* \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
|
||||
* diagnostics should be released using clang_disposeDiagnosticSet().
|
||||
*/
|
||||
CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(
|
||||
const char *file, enum CXLoadDiag_Error *error, CXString *errorString);
|
||||
|
||||
/**
|
||||
* Release a CXDiagnosticSet and all of its contained diagnostics.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
|
||||
|
||||
/**
|
||||
* Retrieve the child diagnostics of a CXDiagnostic.
|
||||
*
|
||||
* This CXDiagnosticSet does not need to be released by
|
||||
* clang_disposeDiagnosticSet.
|
||||
*/
|
||||
CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
|
||||
|
||||
/**
|
||||
* Destroy a diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
|
||||
|
||||
/**
|
||||
* Options to control the display of diagnostics.
|
||||
*
|
||||
* The values in this enum are meant to be combined to customize the
|
||||
* behavior of \c clang_formatDiagnostic().
|
||||
*/
|
||||
enum CXDiagnosticDisplayOptions {
|
||||
/**
|
||||
* Display the source-location information where the
|
||||
* diagnostic was located.
|
||||
*
|
||||
* When set, diagnostics will be prefixed by the file, line, and
|
||||
* (optionally) column to which the diagnostic refers. For example,
|
||||
*
|
||||
* \code
|
||||
* test.c:28: warning: extra tokens at end of #endif directive
|
||||
* \endcode
|
||||
*
|
||||
* This option corresponds to the clang flag \c -fshow-source-location.
|
||||
*/
|
||||
CXDiagnostic_DisplaySourceLocation = 0x01,
|
||||
|
||||
/**
|
||||
* If displaying the source-location information of the
|
||||
* diagnostic, also include the column number.
|
||||
*
|
||||
* This option corresponds to the clang flag \c -fshow-column.
|
||||
*/
|
||||
CXDiagnostic_DisplayColumn = 0x02,
|
||||
|
||||
/**
|
||||
* If displaying the source-location information of the
|
||||
* diagnostic, also include information about source ranges in a
|
||||
* machine-parsable format.
|
||||
*
|
||||
* This option corresponds to the clang flag
|
||||
* \c -fdiagnostics-print-source-range-info.
|
||||
*/
|
||||
CXDiagnostic_DisplaySourceRanges = 0x04,
|
||||
|
||||
/**
|
||||
* Display the option name associated with this diagnostic, if any.
|
||||
*
|
||||
* The option name displayed (e.g., -Wconversion) will be placed in brackets
|
||||
* after the diagnostic text. This option corresponds to the clang flag
|
||||
* \c -fdiagnostics-show-option.
|
||||
*/
|
||||
CXDiagnostic_DisplayOption = 0x08,
|
||||
|
||||
/**
|
||||
* Display the category number associated with this diagnostic, if any.
|
||||
*
|
||||
* The category number is displayed within brackets after the diagnostic text.
|
||||
* This option corresponds to the clang flag
|
||||
* \c -fdiagnostics-show-category=id.
|
||||
*/
|
||||
CXDiagnostic_DisplayCategoryId = 0x10,
|
||||
|
||||
/**
|
||||
* Display the category name associated with this diagnostic, if any.
|
||||
*
|
||||
* The category name is displayed within brackets after the diagnostic text.
|
||||
* This option corresponds to the clang flag
|
||||
* \c -fdiagnostics-show-category=name.
|
||||
*/
|
||||
CXDiagnostic_DisplayCategoryName = 0x20
|
||||
};
|
||||
|
||||
/**
|
||||
* Format the given diagnostic in a manner that is suitable for display.
|
||||
*
|
||||
* This routine will format the given diagnostic to a string, rendering
|
||||
* the diagnostic according to the various options given. The
|
||||
* \c clang_defaultDiagnosticDisplayOptions() function returns the set of
|
||||
* options that most closely mimics the behavior of the clang compiler.
|
||||
*
|
||||
* \param Diagnostic The diagnostic to print.
|
||||
*
|
||||
* \param Options A set of options that control the diagnostic display,
|
||||
* created by combining \c CXDiagnosticDisplayOptions values.
|
||||
*
|
||||
* \returns A new string containing for formatted diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
|
||||
unsigned Options);
|
||||
|
||||
/**
|
||||
* Retrieve the set of display options most similar to the
|
||||
* default behavior of the clang compiler.
|
||||
*
|
||||
* \returns A set of display options suitable for use with \c
|
||||
* clang_formatDiagnostic().
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
|
||||
|
||||
/**
|
||||
* Determine the severity of the given diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXDiagnosticSeverity
|
||||
clang_getDiagnosticSeverity(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve the source location of the given diagnostic.
|
||||
*
|
||||
* This location is where Clang would print the caret ('^') when
|
||||
* displaying the diagnostic on the command line.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve the text of the given diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve the name of the command-line option that enabled this
|
||||
* diagnostic.
|
||||
*
|
||||
* \param Diag The diagnostic to be queried.
|
||||
*
|
||||
* \param Disable If non-NULL, will be set to the option that disables this
|
||||
* diagnostic (if any).
|
||||
*
|
||||
* \returns A string that contains the command-line option used to enable this
|
||||
* warning, such as "-Wconversion" or "-pedantic".
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
|
||||
CXString *Disable);
|
||||
|
||||
/**
|
||||
* Retrieve the category number for this diagnostic.
|
||||
*
|
||||
* Diagnostics can be categorized into groups along with other, related
|
||||
* diagnostics (e.g., diagnostics under the same warning flag). This routine
|
||||
* retrieves the category number for the given diagnostic.
|
||||
*
|
||||
* \returns The number of the category that contains this diagnostic, or zero
|
||||
* if this diagnostic is uncategorized.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve the name of a particular diagnostic category. This
|
||||
* is now deprecated. Use clang_getDiagnosticCategoryText()
|
||||
* instead.
|
||||
*
|
||||
* \param Category A diagnostic category number, as returned by
|
||||
* \c clang_getDiagnosticCategory().
|
||||
*
|
||||
* \returns The name of the given diagnostic category.
|
||||
*/
|
||||
CINDEX_DEPRECATED CINDEX_LINKAGE CXString
|
||||
clang_getDiagnosticCategoryName(unsigned Category);
|
||||
|
||||
/**
|
||||
* Retrieve the diagnostic category text for a given diagnostic.
|
||||
*
|
||||
* \returns The text of the given diagnostic category.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Determine the number of source ranges associated with the given
|
||||
* diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve a source range associated with the diagnostic.
|
||||
*
|
||||
* A diagnostic's source ranges highlight important elements in the source
|
||||
* code. On the command line, Clang displays source ranges by
|
||||
* underlining them with '~' characters.
|
||||
*
|
||||
* \param Diagnostic the diagnostic whose range is being extracted.
|
||||
*
|
||||
* \param Range the zero-based index specifying which range to
|
||||
*
|
||||
* \returns the requested source range.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
|
||||
unsigned Range);
|
||||
|
||||
/**
|
||||
* Determine the number of fix-it hints associated with the
|
||||
* given diagnostic.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
|
||||
|
||||
/**
|
||||
* Retrieve the replacement information for a given fix-it.
|
||||
*
|
||||
* Fix-its are described in terms of a source range whose contents
|
||||
* should be replaced by a string. This approach generalizes over
|
||||
* three kinds of operations: removal of source code (the range covers
|
||||
* the code to be removed and the replacement string is empty),
|
||||
* replacement of source code (the range covers the code to be
|
||||
* replaced and the replacement string provides the new code), and
|
||||
* insertion (both the start and end of the range point at the
|
||||
* insertion location, and the replacement string provides the text to
|
||||
* insert).
|
||||
*
|
||||
* \param Diagnostic The diagnostic whose fix-its are being queried.
|
||||
*
|
||||
* \param FixIt The zero-based index of the fix-it.
|
||||
*
|
||||
* \param ReplacementRange The source range whose contents will be
|
||||
* replaced with the returned replacement string. Note that source
|
||||
* ranges are half-open ranges [a, b), so the source code should be
|
||||
* replaced from a and up to (but not including) b.
|
||||
*
|
||||
* \returns A string containing text that should be replace the source
|
||||
* code indicated by the \c ReplacementRange.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(
|
||||
CXDiagnostic Diagnostic, unsigned FixIt, CXSourceRange *ReplacementRange);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
/*===-- clang-c/CXErrorCode.h - C Index Error Codes --------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides the CXErrorCode enumerators. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXERRORCODE_H
|
||||
#define LLVM_CLANG_C_CXERRORCODE_H
|
||||
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Error codes returned by libclang routines.
|
||||
*
|
||||
* Zero (\c CXError_Success) is the only error code indicating success. Other
|
||||
* error codes, including not yet assigned non-zero values, indicate errors.
|
||||
*/
|
||||
enum CXErrorCode {
|
||||
/**
|
||||
* No error.
|
||||
*/
|
||||
CXError_Success = 0,
|
||||
|
||||
/**
|
||||
* A generic error code, no further details are available.
|
||||
*
|
||||
* Errors of this kind can get their own specific error codes in future
|
||||
* libclang versions.
|
||||
*/
|
||||
CXError_Failure = 1,
|
||||
|
||||
/**
|
||||
* libclang crashed while performing the requested operation.
|
||||
*/
|
||||
CXError_Crashed = 2,
|
||||
|
||||
/**
|
||||
* The function detected that the arguments violate the function
|
||||
* contract.
|
||||
*/
|
||||
CXError_InvalidArguments = 3,
|
||||
|
||||
/**
|
||||
* An AST deserialization error has occurred.
|
||||
*/
|
||||
CXError_ASTReadError = 4
|
||||
};
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*===-- clang-c/CXFile.h - C Index File ---------------------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides the interface to C Index files. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXFILE_H
|
||||
#define LLVM_CLANG_C_CXFILE_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "clang-c/CXString.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup CINDEX_FILES File manipulation routines
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A particular source file that is part of a translation unit.
|
||||
*/
|
||||
typedef void *CXFile;
|
||||
|
||||
/**
|
||||
* Retrieve the complete file and path name of the given file.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
|
||||
|
||||
/**
|
||||
* Retrieve the last modification time of the given file.
|
||||
*/
|
||||
CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
|
||||
|
||||
/**
|
||||
* Uniquely identifies a CXFile, that refers to the same underlying file,
|
||||
* across an indexing session.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned long long data[3];
|
||||
} CXFileUniqueID;
|
||||
|
||||
/**
|
||||
* Retrieve the unique ID for the given \c file.
|
||||
*
|
||||
* \param file the file to get the ID for.
|
||||
* \param outID stores the returned CXFileUniqueID.
|
||||
* \returns If there was a failure getting the unique ID, returns non-zero,
|
||||
* otherwise returns 0.
|
||||
*/
|
||||
CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
|
||||
|
||||
/**
|
||||
* Returns non-zero if the \c file1 and \c file2 point to the same file,
|
||||
* or they are both NULL.
|
||||
*/
|
||||
CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
|
||||
|
||||
/**
|
||||
* Returns the real path name of \c file.
|
||||
*
|
||||
* An empty string may be returned. Use \c clang_getFileName() in that case.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_File_tryGetRealPathName(CXFile file);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,296 @@
|
||||
/*===-- clang-c/CXSourceLocation.h - C Index Source Location ------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides the interface to C Index source locations. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXSOURCE_LOCATION_H
|
||||
#define LLVM_CLANG_C_CXSOURCE_LOCATION_H
|
||||
|
||||
#include "clang-c/CXFile.h"
|
||||
#include "clang-c/CXString.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup CINDEX_LOCATIONS Physical source locations
|
||||
*
|
||||
* Clang represents physical source locations in its abstract syntax tree in
|
||||
* great detail, with file, line, and column information for the majority of
|
||||
* the tokens parsed in the source code. These data types and functions are
|
||||
* used to represent source location information, either for a particular
|
||||
* point in the program or for a range of points in the program, and extract
|
||||
* specific location information from those data types.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Identifies a specific source location within a translation
|
||||
* unit.
|
||||
*
|
||||
* Use clang_getExpansionLocation() or clang_getSpellingLocation()
|
||||
* to map a source location to a particular file, line, and column.
|
||||
*/
|
||||
typedef struct {
|
||||
const void *ptr_data[2];
|
||||
unsigned int_data;
|
||||
} CXSourceLocation;
|
||||
|
||||
/**
|
||||
* Identifies a half-open character range in the source code.
|
||||
*
|
||||
* Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
|
||||
* starting and end locations from a source range, respectively.
|
||||
*/
|
||||
typedef struct {
|
||||
const void *ptr_data[2];
|
||||
unsigned begin_int_data;
|
||||
unsigned end_int_data;
|
||||
} CXSourceRange;
|
||||
|
||||
/**
|
||||
* Retrieve a NULL (invalid) source location.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
|
||||
|
||||
/**
|
||||
* Determine whether two source locations, which must refer into
|
||||
* the same translation unit, refer to exactly the same point in the source
|
||||
* code.
|
||||
*
|
||||
* \returns non-zero if the source locations refer to the same location, zero
|
||||
* if they refer to different locations.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
|
||||
CXSourceLocation loc2);
|
||||
|
||||
/**
|
||||
* Determine for two source locations if the first comes
|
||||
* strictly before the second one in the source code.
|
||||
*
|
||||
* \returns non-zero if the first source location comes
|
||||
* strictly before the second one, zero otherwise.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_isBeforeInTranslationUnit(CXSourceLocation loc1,
|
||||
CXSourceLocation loc2);
|
||||
|
||||
/**
|
||||
* Returns non-zero if the given source location is in a system header.
|
||||
*/
|
||||
CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
|
||||
|
||||
/**
|
||||
* Returns non-zero if the given source location is in the main file of
|
||||
* the corresponding translation unit.
|
||||
*/
|
||||
CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
|
||||
|
||||
/**
|
||||
* Retrieve a NULL (invalid) source range.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
|
||||
|
||||
/**
|
||||
* Retrieve a source range given the beginning and ending source
|
||||
* locations.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
|
||||
CXSourceLocation end);
|
||||
|
||||
/**
|
||||
* Determine whether two ranges are equivalent.
|
||||
*
|
||||
* \returns non-zero if the ranges are the same, zero if they differ.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
|
||||
CXSourceRange range2);
|
||||
|
||||
/**
|
||||
* Returns non-zero if \p range is null.
|
||||
*/
|
||||
CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
|
||||
|
||||
/**
|
||||
* Retrieve the file, line, column, and offset represented by
|
||||
* the given source location.
|
||||
*
|
||||
* If the location refers into a macro expansion, retrieves the
|
||||
* location of the macro expansion.
|
||||
*
|
||||
* \param location the location within a source file that will be decomposed
|
||||
* into its parts.
|
||||
*
|
||||
* \param file [out] if non-NULL, will be set to the file to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param line [out] if non-NULL, will be set to the line to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param column [out] if non-NULL, will be set to the column to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param offset [out] if non-NULL, will be set to the offset into the
|
||||
* buffer to which the given source location points.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
|
||||
CXFile *file, unsigned *line,
|
||||
unsigned *column,
|
||||
unsigned *offset);
|
||||
|
||||
/**
|
||||
* Retrieve the file, line and column represented by the given source
|
||||
* location, as specified in a # line directive.
|
||||
*
|
||||
* Example: given the following source code in a file somefile.c
|
||||
*
|
||||
* \code
|
||||
* #123 "dummy.c" 1
|
||||
*
|
||||
* static int func(void)
|
||||
* {
|
||||
* return 0;
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* the location information returned by this function would be
|
||||
*
|
||||
* File: dummy.c Line: 124 Column: 12
|
||||
*
|
||||
* whereas clang_getExpansionLocation would have returned
|
||||
*
|
||||
* File: somefile.c Line: 3 Column: 12
|
||||
*
|
||||
* \param location the location within a source file that will be decomposed
|
||||
* into its parts.
|
||||
*
|
||||
* \param filename [out] if non-NULL, will be set to the filename of the
|
||||
* source location. Note that filenames returned will be for "virtual" files,
|
||||
* which don't necessarily exist on the machine running clang - e.g. when
|
||||
* parsing preprocessed output obtained from a different environment. If
|
||||
* a non-NULL value is passed in, remember to dispose of the returned value
|
||||
* using \c clang_disposeString() once you've finished with it. For an invalid
|
||||
* source location, an empty string is returned.
|
||||
*
|
||||
* \param line [out] if non-NULL, will be set to the line number of the
|
||||
* source location. For an invalid source location, zero is returned.
|
||||
*
|
||||
* \param column [out] if non-NULL, will be set to the column number of the
|
||||
* source location. For an invalid source location, zero is returned.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
|
||||
CXString *filename,
|
||||
unsigned *line, unsigned *column);
|
||||
|
||||
/**
|
||||
* Legacy API to retrieve the file, line, column, and offset represented
|
||||
* by the given source location.
|
||||
*
|
||||
* This interface has been replaced by the newer interface
|
||||
* #clang_getExpansionLocation(). See that interface's documentation for
|
||||
* details.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
|
||||
CXFile *file, unsigned *line,
|
||||
unsigned *column,
|
||||
unsigned *offset);
|
||||
|
||||
/**
|
||||
* Retrieve the file, line, column, and offset represented by
|
||||
* the given source location.
|
||||
*
|
||||
* If the location refers into a macro instantiation, return where the
|
||||
* location was originally spelled in the source file.
|
||||
*
|
||||
* \param location the location within a source file that will be decomposed
|
||||
* into its parts.
|
||||
*
|
||||
* \param file [out] if non-NULL, will be set to the file to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param line [out] if non-NULL, will be set to the line to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param column [out] if non-NULL, will be set to the column to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param offset [out] if non-NULL, will be set to the offset into the
|
||||
* buffer to which the given source location points.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
|
||||
CXFile *file, unsigned *line,
|
||||
unsigned *column,
|
||||
unsigned *offset);
|
||||
|
||||
/**
|
||||
* Retrieve the file, line, column, and offset represented by
|
||||
* the given source location.
|
||||
*
|
||||
* If the location refers into a macro expansion, return where the macro was
|
||||
* expanded or where the macro argument was written, if the location points at
|
||||
* a macro argument.
|
||||
*
|
||||
* \param location the location within a source file that will be decomposed
|
||||
* into its parts.
|
||||
*
|
||||
* \param file [out] if non-NULL, will be set to the file to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param line [out] if non-NULL, will be set to the line to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param column [out] if non-NULL, will be set to the column to which the given
|
||||
* source location points.
|
||||
*
|
||||
* \param offset [out] if non-NULL, will be set to the offset into the
|
||||
* buffer to which the given source location points.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
|
||||
CXFile *file, unsigned *line,
|
||||
unsigned *column, unsigned *offset);
|
||||
|
||||
/**
|
||||
* Retrieve a source location representing the first character within a
|
||||
* source range.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
|
||||
|
||||
/**
|
||||
* Retrieve a source location representing the last character within a
|
||||
* source range.
|
||||
*/
|
||||
CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
|
||||
|
||||
/**
|
||||
* Identifies an array of ranges.
|
||||
*/
|
||||
typedef struct {
|
||||
/** The number of ranges in the \c ranges array. */
|
||||
unsigned count;
|
||||
/**
|
||||
* An array of \c CXSourceRanges.
|
||||
*/
|
||||
CXSourceRange *ranges;
|
||||
} CXSourceRangeList;
|
||||
|
||||
/**
|
||||
* Destroy the given \c CXSourceRangeList.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
/*===-- clang-c/CXString.h - C Index strings --------------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides the interface to C Index strings. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_CXSTRING_H
|
||||
#define LLVM_CLANG_C_CXSTRING_H
|
||||
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup CINDEX_STRING String manipulation routines
|
||||
* \ingroup CINDEX
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A character string.
|
||||
*
|
||||
* The \c CXString type is used to return strings from the interface when
|
||||
* the ownership of that string might differ from one call to the next.
|
||||
* Use \c clang_getCString() to retrieve the string data and, once finished
|
||||
* with the string data, call \c clang_disposeString() to free the string.
|
||||
*/
|
||||
typedef struct {
|
||||
const void *data;
|
||||
unsigned private_flags;
|
||||
} CXString;
|
||||
|
||||
typedef struct {
|
||||
CXString *Strings;
|
||||
unsigned Count;
|
||||
} CXStringSet;
|
||||
|
||||
/**
|
||||
* Retrieve the character data associated with the given string.
|
||||
*
|
||||
* The returned data is a reference and not owned by the user. This data
|
||||
* is only valid while the `CXString` is valid. This function is similar
|
||||
* to `std::string::c_str()`.
|
||||
*/
|
||||
CINDEX_LINKAGE const char *clang_getCString(CXString string);
|
||||
|
||||
/**
|
||||
* Free the given string.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeString(CXString string);
|
||||
|
||||
/**
|
||||
* Free the given string set.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeStringSet(CXStringSet *set);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,619 @@
|
||||
/*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides a supplementary interface for inspecting *|
|
||||
|* documentation comments. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_DOCUMENTATION_H
|
||||
#define LLVM_CLANG_C_DOCUMENTATION_H
|
||||
|
||||
#include "clang-c/CXErrorCode.h"
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Index.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* \defgroup CINDEX_COMMENT Comment introspection
|
||||
*
|
||||
* The routines in this group provide access to information in documentation
|
||||
* comments. These facilities are distinct from the core and may be subject to
|
||||
* their own schedule of stability and deprecation.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A parsed comment.
|
||||
*/
|
||||
typedef struct {
|
||||
const void *ASTNode;
|
||||
CXTranslationUnit TranslationUnit;
|
||||
} CXComment;
|
||||
|
||||
/**
|
||||
* Given a cursor that represents a documentable entity (e.g.,
|
||||
* declaration), return the associated parsed comment as a
|
||||
* \c CXComment_FullComment AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
|
||||
|
||||
/**
|
||||
* Describes the type of the comment AST node (\c CXComment). A comment
|
||||
* node can be considered block content (e. g., paragraph), inline content
|
||||
* (plain text) or neither (the root AST node).
|
||||
*/
|
||||
enum CXCommentKind {
|
||||
/**
|
||||
* Null comment. No AST node is constructed at the requested location
|
||||
* because there is no text or a syntax error.
|
||||
*/
|
||||
CXComment_Null = 0,
|
||||
|
||||
/**
|
||||
* Plain text. Inline content.
|
||||
*/
|
||||
CXComment_Text = 1,
|
||||
|
||||
/**
|
||||
* A command with word-like arguments that is considered inline content.
|
||||
*
|
||||
* For example: \\c command.
|
||||
*/
|
||||
CXComment_InlineCommand = 2,
|
||||
|
||||
/**
|
||||
* HTML start tag with attributes (name-value pairs). Considered
|
||||
* inline content.
|
||||
*
|
||||
* For example:
|
||||
* \verbatim
|
||||
* <br> <br /> <a href="http://example.org/">
|
||||
* \endverbatim
|
||||
*/
|
||||
CXComment_HTMLStartTag = 3,
|
||||
|
||||
/**
|
||||
* HTML end tag. Considered inline content.
|
||||
*
|
||||
* For example:
|
||||
* \verbatim
|
||||
* </a>
|
||||
* \endverbatim
|
||||
*/
|
||||
CXComment_HTMLEndTag = 4,
|
||||
|
||||
/**
|
||||
* A paragraph, contains inline comment. The paragraph itself is
|
||||
* block content.
|
||||
*/
|
||||
CXComment_Paragraph = 5,
|
||||
|
||||
/**
|
||||
* A command that has zero or more word-like arguments (number of
|
||||
* word-like arguments depends on command name) and a paragraph as an
|
||||
* argument. Block command is block content.
|
||||
*
|
||||
* Paragraph argument is also a child of the block command.
|
||||
*
|
||||
* For example: \has 0 word-like arguments and a paragraph argument.
|
||||
*
|
||||
* AST nodes of special kinds that parser knows about (e. g., \\param
|
||||
* command) have their own node kinds.
|
||||
*/
|
||||
CXComment_BlockCommand = 6,
|
||||
|
||||
/**
|
||||
* A \\param or \\arg command that describes the function parameter
|
||||
* (name, passing direction, description).
|
||||
*
|
||||
* For example: \\param [in] ParamName description.
|
||||
*/
|
||||
CXComment_ParamCommand = 7,
|
||||
|
||||
/**
|
||||
* A \\tparam command that describes a template parameter (name and
|
||||
* description).
|
||||
*
|
||||
* For example: \\tparam T description.
|
||||
*/
|
||||
CXComment_TParamCommand = 8,
|
||||
|
||||
/**
|
||||
* A verbatim block command (e. g., preformatted code). Verbatim
|
||||
* block has an opening and a closing command and contains multiple lines of
|
||||
* text (\c CXComment_VerbatimBlockLine child nodes).
|
||||
*
|
||||
* For example:
|
||||
* \\verbatim
|
||||
* aaa
|
||||
* \\endverbatim
|
||||
*/
|
||||
CXComment_VerbatimBlockCommand = 9,
|
||||
|
||||
/**
|
||||
* A line of text that is contained within a
|
||||
* CXComment_VerbatimBlockCommand node.
|
||||
*/
|
||||
CXComment_VerbatimBlockLine = 10,
|
||||
|
||||
/**
|
||||
* A verbatim line command. Verbatim line has an opening command,
|
||||
* a single line of text (up to the newline after the opening command) and
|
||||
* has no closing command.
|
||||
*/
|
||||
CXComment_VerbatimLine = 11,
|
||||
|
||||
/**
|
||||
* A full comment attached to a declaration, contains block content.
|
||||
*/
|
||||
CXComment_FullComment = 12
|
||||
};
|
||||
|
||||
/**
|
||||
* The most appropriate rendering mode for an inline command, chosen on
|
||||
* command semantics in Doxygen.
|
||||
*/
|
||||
enum CXCommentInlineCommandRenderKind {
|
||||
/**
|
||||
* Command argument should be rendered in a normal font.
|
||||
*/
|
||||
CXCommentInlineCommandRenderKind_Normal,
|
||||
|
||||
/**
|
||||
* Command argument should be rendered in a bold font.
|
||||
*/
|
||||
CXCommentInlineCommandRenderKind_Bold,
|
||||
|
||||
/**
|
||||
* Command argument should be rendered in a monospaced font.
|
||||
*/
|
||||
CXCommentInlineCommandRenderKind_Monospaced,
|
||||
|
||||
/**
|
||||
* Command argument should be rendered emphasized (typically italic
|
||||
* font).
|
||||
*/
|
||||
CXCommentInlineCommandRenderKind_Emphasized,
|
||||
|
||||
/**
|
||||
* Command argument should not be rendered (since it only defines an anchor).
|
||||
*/
|
||||
CXCommentInlineCommandRenderKind_Anchor
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes parameter passing direction for \\param or \\arg command.
|
||||
*/
|
||||
enum CXCommentParamPassDirection {
|
||||
/**
|
||||
* The parameter is an input parameter.
|
||||
*/
|
||||
CXCommentParamPassDirection_In,
|
||||
|
||||
/**
|
||||
* The parameter is an output parameter.
|
||||
*/
|
||||
CXCommentParamPassDirection_Out,
|
||||
|
||||
/**
|
||||
* The parameter is an input and output parameter.
|
||||
*/
|
||||
CXCommentParamPassDirection_InOut
|
||||
};
|
||||
|
||||
/**
|
||||
* \param Comment AST node of any kind.
|
||||
*
|
||||
* \returns the type of the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment AST node of any kind.
|
||||
*
|
||||
* \returns number of children of the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment AST node of any kind.
|
||||
*
|
||||
* \param ChildIdx child index (zero-based).
|
||||
*
|
||||
* \returns the specified child of the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
|
||||
|
||||
/**
|
||||
* A \c CXComment_Paragraph node is considered whitespace if it contains
|
||||
* only \c CXComment_Text nodes that are empty or whitespace.
|
||||
*
|
||||
* Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
|
||||
* never considered whitespace.
|
||||
*
|
||||
* \returns non-zero if \c Comment is whitespace.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \returns non-zero if \c Comment is inline content and has a newline
|
||||
* immediately following it in the comment text. Newlines between paragraphs
|
||||
* do not count.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_Text AST node.
|
||||
*
|
||||
* \returns text contained in the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_InlineCommand AST node.
|
||||
*
|
||||
* \returns name of the inline command.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_InlineCommand AST node.
|
||||
*
|
||||
* \returns the most appropriate rendering mode, chosen on command
|
||||
* semantics in Doxygen.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
|
||||
clang_InlineCommandComment_getRenderKind(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_InlineCommand AST node.
|
||||
*
|
||||
* \returns number of command arguments.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_InlineCommand AST node.
|
||||
*
|
||||
* \param ArgIdx argument index (zero-based).
|
||||
*
|
||||
* \returns text of the specified argument.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_InlineCommandComment_getArgText(CXComment Comment,
|
||||
unsigned ArgIdx);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
|
||||
* node.
|
||||
*
|
||||
* \returns HTML tag name.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_HTMLStartTag AST node.
|
||||
*
|
||||
* \returns non-zero if tag is self-closing (for example, <br />).
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_HTMLStartTag AST node.
|
||||
*
|
||||
* \returns number of attributes (name-value pairs) attached to the start tag.
|
||||
*/
|
||||
CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_HTMLStartTag AST node.
|
||||
*
|
||||
* \param AttrIdx attribute index (zero-based).
|
||||
*
|
||||
* \returns name of the specified attribute.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_HTMLStartTag AST node.
|
||||
*
|
||||
* \param AttrIdx attribute index (zero-based).
|
||||
*
|
||||
* \returns value of the specified attribute.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_BlockCommand AST node.
|
||||
*
|
||||
* \returns name of the block command.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_BlockCommand AST node.
|
||||
*
|
||||
* \returns number of word-like arguments.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_BlockCommand AST node.
|
||||
*
|
||||
* \param ArgIdx argument index (zero-based).
|
||||
*
|
||||
* \returns text of the specified word-like argument.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_BlockCommandComment_getArgText(CXComment Comment,
|
||||
unsigned ArgIdx);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_BlockCommand or
|
||||
* \c CXComment_VerbatimBlockCommand AST node.
|
||||
*
|
||||
* \returns paragraph argument of the block command.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_ParamCommand AST node.
|
||||
*
|
||||
* \returns parameter name.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_ParamCommandComment_getParamName(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_ParamCommand AST node.
|
||||
*
|
||||
* \returns non-zero if the parameter that this AST node represents was found
|
||||
* in the function prototype and \c clang_ParamCommandComment_getParamIndex
|
||||
* function will return a meaningful value.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_ParamCommand AST node.
|
||||
*
|
||||
* \returns zero-based parameter index in function prototype.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_ParamCommand AST node.
|
||||
*
|
||||
* \returns non-zero if parameter passing direction was specified explicitly in
|
||||
* the comment.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_ParamCommand AST node.
|
||||
*
|
||||
* \returns parameter passing direction.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
|
||||
CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_TParamCommand AST node.
|
||||
*
|
||||
* \returns template parameter name.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_TParamCommandComment_getParamName(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_TParamCommand AST node.
|
||||
*
|
||||
* \returns non-zero if the parameter that this AST node represents was found
|
||||
* in the template parameter list and
|
||||
* \c clang_TParamCommandComment_getDepth and
|
||||
* \c clang_TParamCommandComment_getIndex functions will return a meaningful
|
||||
* value.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_TParamCommand AST node.
|
||||
*
|
||||
* \returns zero-based nesting depth of this parameter in the template parameter list.
|
||||
*
|
||||
* For example,
|
||||
* \verbatim
|
||||
* template<typename C, template<typename T> class TT>
|
||||
* void test(TT<int> aaa);
|
||||
* \endverbatim
|
||||
* for C and TT nesting depth is 0,
|
||||
* for T nesting depth is 1.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_TParamCommand AST node.
|
||||
*
|
||||
* \returns zero-based parameter index in the template parameter list at a
|
||||
* given nesting depth.
|
||||
*
|
||||
* For example,
|
||||
* \verbatim
|
||||
* template<typename C, template<typename T> class TT>
|
||||
* void test(TT<int> aaa);
|
||||
* \endverbatim
|
||||
* for C and TT nesting depth is 0, so we can ask for index at depth 0:
|
||||
* at depth 0 C's index is 0, TT's index is 1.
|
||||
*
|
||||
* For T nesting depth is 1, so we can ask for index at depth 0 and 1:
|
||||
* at depth 0 T's index is 1 (same as TT's),
|
||||
* at depth 1 T's index is 0.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_VerbatimBlockLine AST node.
|
||||
*
|
||||
* \returns text contained in the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE
|
||||
CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
|
||||
|
||||
/**
|
||||
* \param Comment a \c CXComment_VerbatimLine AST node.
|
||||
*
|
||||
* \returns text contained in the AST node.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
|
||||
|
||||
/**
|
||||
* Convert an HTML tag AST node to string.
|
||||
*
|
||||
* \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
|
||||
* node.
|
||||
*
|
||||
* \returns string containing an HTML tag.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
|
||||
|
||||
/**
|
||||
* Convert a given full parsed comment to an HTML fragment.
|
||||
*
|
||||
* Specific details of HTML layout are subject to change. Don't try to parse
|
||||
* this HTML back into an AST, use other APIs instead.
|
||||
*
|
||||
* Currently the following CSS classes are used:
|
||||
* \li "para-brief" for \paragraph and equivalent commands;
|
||||
* \li "para-returns" for \\returns paragraph and equivalent commands;
|
||||
* \li "word-returns" for the "Returns" word in \\returns paragraph.
|
||||
*
|
||||
* Function argument documentation is rendered as a \<dl\> list with arguments
|
||||
* sorted in function prototype order. CSS classes used:
|
||||
* \li "param-name-index-NUMBER" for parameter name (\<dt\>);
|
||||
* \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
|
||||
* \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
|
||||
* parameter index is invalid.
|
||||
*
|
||||
* Template parameter documentation is rendered as a \<dl\> list with
|
||||
* parameters sorted in template parameter list order. CSS classes used:
|
||||
* \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
|
||||
* \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
|
||||
* \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
|
||||
* names inside template template parameters;
|
||||
* \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
|
||||
* parameter position is invalid.
|
||||
*
|
||||
* \param Comment a \c CXComment_FullComment AST node.
|
||||
*
|
||||
* \returns string containing an HTML fragment.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
|
||||
|
||||
/**
|
||||
* Convert a given full parsed comment to an XML document.
|
||||
*
|
||||
* A Relax NG schema for the XML can be found in comment-xml-schema.rng file
|
||||
* inside clang source tree.
|
||||
*
|
||||
* \param Comment a \c CXComment_FullComment AST node.
|
||||
*
|
||||
* \returns string containing an XML document.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
|
||||
|
||||
/**
|
||||
* CXAPISet is an opaque type that represents a data structure containing all
|
||||
* the API information for a given translation unit. This can be used for a
|
||||
* single symbol symbol graph for a given symbol.
|
||||
*/
|
||||
typedef struct CXAPISetImpl *CXAPISet;
|
||||
|
||||
/**
|
||||
* Traverses the translation unit to create a \c CXAPISet.
|
||||
*
|
||||
* \param tu is the \c CXTranslationUnit to build the \c CXAPISet for.
|
||||
*
|
||||
* \param out_api is a pointer to the output of this function. It is needs to be
|
||||
* disposed of by calling clang_disposeAPISet.
|
||||
*
|
||||
* \returns Error code indicating success or failure of the APISet creation.
|
||||
*/
|
||||
CINDEX_LINKAGE enum CXErrorCode clang_createAPISet(CXTranslationUnit tu,
|
||||
CXAPISet *out_api);
|
||||
|
||||
/**
|
||||
* Dispose of an APISet.
|
||||
*
|
||||
* The provided \c CXAPISet can not be used after this function is called.
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_disposeAPISet(CXAPISet api);
|
||||
|
||||
/**
|
||||
* Generate a single symbol symbol graph for the given USR. Returns a null
|
||||
* string if the associated symbol can not be found in the provided \c CXAPISet.
|
||||
*
|
||||
* The output contains the symbol graph as well as some additional information
|
||||
* about related symbols.
|
||||
*
|
||||
* \param usr is a string containing the USR of the symbol to generate the
|
||||
* symbol graph for.
|
||||
*
|
||||
* \param api the \c CXAPISet to look for the symbol in.
|
||||
*
|
||||
* \returns a string containing the serialized symbol graph representation for
|
||||
* the symbol being queried or a null string if it can not be found in the
|
||||
* APISet.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getSymbolGraphForUSR(const char *usr,
|
||||
CXAPISet api);
|
||||
|
||||
/**
|
||||
* Generate a single symbol symbol graph for the declaration at the given
|
||||
* cursor. Returns a null string if the AST node for the cursor isn't a
|
||||
* declaration.
|
||||
*
|
||||
* The output contains the symbol graph as well as some additional information
|
||||
* about related symbols.
|
||||
*
|
||||
* \param cursor the declaration for which to generate the single symbol symbol
|
||||
* graph.
|
||||
*
|
||||
* \returns a string containing the serialized symbol graph representation for
|
||||
* the symbol being queried or a null string if it can not be found in the
|
||||
* APISet.
|
||||
*/
|
||||
CINDEX_LINKAGE CXString clang_getSymbolGraphForCursor(CXCursor cursor);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif /* CLANG_C_DOCUMENTATION_H */
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*===- clang-c/ExternC.h - Wrapper for 'extern "C"' ---------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file defines an 'extern "C"' wrapper. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_EXTERN_C_H
|
||||
#define LLVM_CLANG_C_EXTERN_C_H
|
||||
|
||||
#ifdef __clang__
|
||||
#define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic error \"-Wstrict-prototypes\"")
|
||||
#define LLVM_CLANG_C_STRICT_PROTOTYPES_END _Pragma("clang diagnostic pop")
|
||||
#else
|
||||
#define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
|
||||
#define LLVM_CLANG_C_STRICT_PROTOTYPES_END
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define LLVM_CLANG_C_EXTERN_C_BEGIN \
|
||||
extern "C" { \
|
||||
LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
|
||||
#define LLVM_CLANG_C_EXTERN_C_END \
|
||||
LLVM_CLANG_C_STRICT_PROTOTYPES_END \
|
||||
}
|
||||
#else
|
||||
#define LLVM_CLANG_C_EXTERN_C_BEGIN LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
|
||||
#define LLVM_CLANG_C_EXTERN_C_END LLVM_CLANG_C_STRICT_PROTOTYPES_END
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*===-- clang-c/FatalErrorHandler.h - Fatal Error Handling --------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
|
||||
#define LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
|
||||
|
||||
#include "clang-c/ExternC.h"
|
||||
#include "clang-c/Platform.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/**
|
||||
* Installs error handler that prints error message to stderr and calls abort().
|
||||
* Replaces currently installed error handler (if any).
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_install_aborting_llvm_fatal_error_handler(void);
|
||||
|
||||
/**
|
||||
* Removes currently installed error handler (if any).
|
||||
* If no error handler is intalled, the default strategy is to print error
|
||||
* message to stderr and call exit(1).
|
||||
*/
|
||||
CINDEX_LINKAGE void clang_uninstall_llvm_fatal_error_handler(void);
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
/*===-- clang-c/Platform.h - C Index platform decls -------------*- C -*-===*\
|
||||
|* *|
|
||||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
||||
|* Exceptions. *|
|
||||
|* See https://llvm.org/LICENSE.txt for license information. *|
|
||||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This header provides platform specific macros (dllimport, deprecated, ...) *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef LLVM_CLANG_C_PLATFORM_H
|
||||
#define LLVM_CLANG_C_PLATFORM_H
|
||||
|
||||
#include "clang-c/ExternC.h"
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_BEGIN
|
||||
|
||||
/* Windows DLL import/export. */
|
||||
#ifndef CINDEX_NO_EXPORTS
|
||||
#define CINDEX_EXPORTS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#ifdef CINDEX_EXPORTS
|
||||
#ifdef _CINDEX_LIB_
|
||||
#define CINDEX_LINKAGE __declspec(dllexport)
|
||||
#else
|
||||
#define CINDEX_LINKAGE __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
|
||||
#define CINDEX_LINKAGE __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#ifndef CINDEX_LINKAGE
|
||||
#define CINDEX_LINKAGE
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define CINDEX_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#define CINDEX_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define CINDEX_DEPRECATED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
LLVM_CLANG_C_EXTERN_C_END
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user