├── .gitignore
├── CMakeLists.txt
├── LICENSE.TXT
├── README.md
├── include
└── clang-c
│ ├── BuildSystem.h
│ ├── CXCompilationDatabase.h
│ ├── CXErrorCode.h
│ ├── CXString.h
│ ├── Documentation.h
│ ├── ExternC.h
│ ├── FatalErrorHandler.h
│ ├── Index.h
│ ├── Makefile
│ ├── Platform.h
│ └── module.modulemap
├── scread.c
└── test
├── HelloWorld.cpp
├── Node.h
├── Variable.h
└── VariableAdd.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 | *.ko
4 | *.obj
5 | *.elf
6 |
7 | # Libraries
8 | *.lib
9 | *.a
10 |
11 | # Shared objects (inc. Windows DLLs)
12 | *.dll
13 | *.so
14 | *.so.*
15 | *.dylib
16 |
17 | # Executables
18 | *.exe
19 | *.out
20 | *.app
21 | *.i*86
22 | *.x86_64
23 | *.hex
24 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2 | PROJECT(scread)
3 |
4 | ADD_EXECUTABLE(scread scread.c)
5 | INCLUDE_DIRECTORIES(./include/)
6 |
7 | #Need to do more about find library#
8 | FIND_LIBRARY(LIBCLANG_PATH clang HINTS /usr/local/lib/)
9 |
10 | TARGET_LINK_LIBRARIES(scread ${LIBCLANG_PATH})
11 |
--------------------------------------------------------------------------------
/LICENSE.TXT:
--------------------------------------------------------------------------------
1 | ==============================================================================
2 | scread Release License
3 | ==============================================================================
4 | University of Illinois/NCSA
5 | Open Source License
6 |
7 | Copyright (c) 2007-2014 University of Illinois at Urbana-Champaign.
8 | All rights reserved.
9 |
10 | Developed by:
11 |
12 | Shining
13 | shiningning1984@gmail.com
14 |
15 |
16 | Permission is hereby granted, free of charge, to any person obtaining a copy of
17 | this software and associated documentation files (the "Software"), to deal with
18 | the Software without restriction, including without limitation the rights to
19 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
20 | of the Software, and to permit persons to whom the Software is furnished to do
21 | so, subject to the following conditions:
22 |
23 | * Redistributions of source code must retain the above copyright notice,
24 | this list of conditions and the following disclaimers.
25 |
26 | * Redistributions in binary form must reproduce the above copyright notice,
27 | this list of conditions and the following disclaimers in the
28 | documentation and/or other materials provided with the distribution.
29 |
30 | * Neither the names of the LLVM Team, University of Illinois at
31 | Urbana-Champaign, nor the names of its contributors may be used to
32 | endorse or promote products derived from this Software without specific
33 | prior written permission.
34 |
35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
37 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
41 | SOFTWARE.
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | screader
2 | ========
3 |
4 | The screader is a soure code reading tool based the libclang. It is implemented by the C.
5 | The screader can work on the clang-10.0.0 now.
6 |
7 |
8 | How to build the scread:
9 | ---------------------------------------------------------
10 | 1. You must install the clang on your computer.
11 | You can follow the doc: http://clang.llvm.org/get_started.html.
12 | But after you "make", you must "make install".
13 |
14 | 2. After you install the clang, you can use "clang -v" to check your clang version.
15 |
16 | 3. Find the clanglib-10.so.1 in the usr/lib/x86_64-linux-gnu dir; if you can't find it, you
17 | can use the "sudo apt-get install libclang1" to install the libclang.
18 |
19 | 4. Use the cmd to create a link to libclang.so:
20 |
21 | sudo ln -s libclang-10.so.1 libclang.so
22 |
23 | 5. Use git clone the source code of scread to you computer.
24 |
25 | 6. Create directory build under the scread directory.
26 |
27 | 7. Under the build directory, use the cmd:
28 |
29 | cmake ../
30 |
31 | make
32 |
33 | 6. Then you can get the scread under the build directory.
34 |
35 |
36 | How to use the scread:
37 | ------------------------------------------------------------
38 |
39 | You must come to the directory of the scread.
40 |
41 | 1. If you want to use the scread to output all the informations of ast nodes:
42 | You can use it like that: ./scread xxx.cpp(or xxx.c, xxx.h)
43 |
44 | 2. If you just want to get the keyword information, you can use it like this:
45 | ./scread xxx.cpp keyword
46 |
47 | 3. We store some testcase under the scread/test/. So, you can use the scread like this:
48 | ./scread ../test/Node.h
49 | ./scread ../test/HelloWorld.cpp printf
50 |
51 | Update:
52 | -----------------------------------------------
53 | 1. The files in include/clang-c dir is copy from the clang-10.0.0/include/clang-c.
54 |
--------------------------------------------------------------------------------
/include/clang-c/BuildSystem.h:
--------------------------------------------------------------------------------
1 | /*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides various utilities for use by build systems. *|
11 | |* *|
12 | \*===----------------------------------------------------------------------===*/
13 |
14 | #ifndef LLVM_CLANG_C_BUILDSYSTEM_H
15 | #define LLVM_CLANG_C_BUILDSYSTEM_H
16 |
17 | #include "clang-c/CXErrorCode.h"
18 | #include "clang-c/CXString.h"
19 | #include "clang-c/ExternC.h"
20 | #include "clang-c/Platform.h"
21 |
22 | LLVM_CLANG_C_EXTERN_C_BEGIN
23 |
24 | /**
25 | * \defgroup BUILD_SYSTEM Build system utilities
26 | * @{
27 | */
28 |
29 | /**
30 | * Return the timestamp for use with Clang's
31 | * \c -fbuild-session-timestamp= option.
32 | */
33 | CINDEX_LINKAGE unsigned long long clang_getBuildSessionTimestamp(void);
34 |
35 | /**
36 | * Object encapsulating information about overlaying virtual
37 | * file/directories over the real file system.
38 | */
39 | typedef struct CXVirtualFileOverlayImpl *CXVirtualFileOverlay;
40 |
41 | /**
42 | * Create a \c CXVirtualFileOverlay object.
43 | * Must be disposed with \c clang_VirtualFileOverlay_dispose().
44 | *
45 | * \param options is reserved, always pass 0.
46 | */
47 | CINDEX_LINKAGE CXVirtualFileOverlay
48 | clang_VirtualFileOverlay_create(unsigned options);
49 |
50 | /**
51 | * Map an absolute virtual file path to an absolute real one.
52 | * The virtual path must be canonicalized (not contain "."/"..").
53 | * \returns 0 for success, non-zero to indicate an error.
54 | */
55 | CINDEX_LINKAGE enum CXErrorCode
56 | clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay,
57 | const char *virtualPath,
58 | const char *realPath);
59 |
60 | /**
61 | * Set the case sensitivity for the \c CXVirtualFileOverlay object.
62 | * The \c CXVirtualFileOverlay object is case-sensitive by default, this
63 | * option can be used to override the default.
64 | * \returns 0 for success, non-zero to indicate an error.
65 | */
66 | CINDEX_LINKAGE enum CXErrorCode
67 | clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay,
68 | int caseSensitive);
69 |
70 | /**
71 | * Write out the \c CXVirtualFileOverlay object to a char buffer.
72 | *
73 | * \param options is reserved, always pass 0.
74 | * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
75 | * disposed using \c clang_free().
76 | * \param out_buffer_size pointer to receive the buffer size.
77 | * \returns 0 for success, non-zero to indicate an error.
78 | */
79 | CINDEX_LINKAGE enum CXErrorCode
80 | clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options,
81 | char **out_buffer_ptr,
82 | unsigned *out_buffer_size);
83 |
84 | /**
85 | * free memory allocated by libclang, such as the buffer returned by
86 | * \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer().
87 | *
88 | * \param buffer memory pointer to free.
89 | */
90 | CINDEX_LINKAGE void clang_free(void *buffer);
91 |
92 | /**
93 | * Dispose a \c CXVirtualFileOverlay object.
94 | */
95 | CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay);
96 |
97 | /**
98 | * Object encapsulating information about a module.map file.
99 | */
100 | typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor;
101 |
102 | /**
103 | * Create a \c CXModuleMapDescriptor object.
104 | * Must be disposed with \c clang_ModuleMapDescriptor_dispose().
105 | *
106 | * \param options is reserved, always pass 0.
107 | */
108 | CINDEX_LINKAGE CXModuleMapDescriptor
109 | clang_ModuleMapDescriptor_create(unsigned options);
110 |
111 | /**
112 | * Sets the framework module name that the module.map describes.
113 | * \returns 0 for success, non-zero to indicate an error.
114 | */
115 | CINDEX_LINKAGE enum CXErrorCode
116 | clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor,
117 | const char *name);
118 |
119 | /**
120 | * Sets the umbrealla header name that the module.map describes.
121 | * \returns 0 for success, non-zero to indicate an error.
122 | */
123 | CINDEX_LINKAGE enum CXErrorCode
124 | clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor,
125 | const char *name);
126 |
127 | /**
128 | * Write out the \c CXModuleMapDescriptor object to a char buffer.
129 | *
130 | * \param options is reserved, always pass 0.
131 | * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
132 | * disposed using \c clang_free().
133 | * \param out_buffer_size pointer to receive the buffer size.
134 | * \returns 0 for success, non-zero to indicate an error.
135 | */
136 | CINDEX_LINKAGE enum CXErrorCode
137 | clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options,
138 | char **out_buffer_ptr,
139 | unsigned *out_buffer_size);
140 |
141 | /**
142 | * Dispose a \c CXModuleMapDescriptor object.
143 | */
144 | CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor);
145 |
146 | /**
147 | * @}
148 | */
149 |
150 | LLVM_CLANG_C_EXTERN_C_END
151 |
152 | #endif /* CLANG_C_BUILD_SYSTEM_H */
153 |
154 |
--------------------------------------------------------------------------------
/include/clang-c/CXCompilationDatabase.h:
--------------------------------------------------------------------------------
1 | /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides a public interface to use CompilationDatabase without *|
11 | |* the full Clang C++ API. *|
12 | |* *|
13 | \*===----------------------------------------------------------------------===*/
14 |
15 | #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
16 | #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
17 |
18 | #include "clang-c/CXString.h"
19 | #include "clang-c/ExternC.h"
20 | #include "clang-c/Platform.h"
21 |
22 | LLVM_CLANG_C_EXTERN_C_BEGIN
23 |
24 | /** \defgroup COMPILATIONDB CompilationDatabase functions
25 | * \ingroup CINDEX
26 | *
27 | * @{
28 | */
29 |
30 | /**
31 | * A compilation database holds all information used to compile files in a
32 | * project. For each file in the database, it can be queried for the working
33 | * directory or the command line used for the compiler invocation.
34 | *
35 | * Must be freed by \c clang_CompilationDatabase_dispose
36 | */
37 | typedef void * CXCompilationDatabase;
38 |
39 | /**
40 | * Contains the results of a search in the compilation database
41 | *
42 | * When searching for the compile command for a file, the compilation db can
43 | * return several commands, as the file may have been compiled with
44 | * different options in different places of the project. This choice of compile
45 | * commands is wrapped in this opaque data structure. It must be freed by
46 | * \c clang_CompileCommands_dispose.
47 | */
48 | typedef void * CXCompileCommands;
49 |
50 | /**
51 | * Represents the command line invocation to compile a specific file.
52 | */
53 | typedef void * CXCompileCommand;
54 |
55 | /**
56 | * Error codes for Compilation Database
57 | */
58 | typedef enum {
59 | /*
60 | * No error occurred
61 | */
62 | CXCompilationDatabase_NoError = 0,
63 |
64 | /*
65 | * Database can not be loaded
66 | */
67 | CXCompilationDatabase_CanNotLoadDatabase = 1
68 |
69 | } CXCompilationDatabase_Error;
70 |
71 | /**
72 | * Creates a compilation database from the database found in directory
73 | * buildDir. For example, CMake can output a compile_commands.json which can
74 | * be used to build the database.
75 | *
76 | * It must be freed by \c clang_CompilationDatabase_dispose.
77 | */
78 | CINDEX_LINKAGE CXCompilationDatabase
79 | clang_CompilationDatabase_fromDirectory(const char *BuildDir,
80 | CXCompilationDatabase_Error *ErrorCode);
81 |
82 | /**
83 | * Free the given compilation database
84 | */
85 | CINDEX_LINKAGE void
86 | clang_CompilationDatabase_dispose(CXCompilationDatabase);
87 |
88 | /**
89 | * Find the compile commands used for a file. The compile commands
90 | * must be freed by \c clang_CompileCommands_dispose.
91 | */
92 | CINDEX_LINKAGE CXCompileCommands
93 | clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
94 | const char *CompleteFileName);
95 |
96 | /**
97 | * Get all the compile commands in the given compilation database.
98 | */
99 | CINDEX_LINKAGE CXCompileCommands
100 | clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
101 |
102 | /**
103 | * Free the given CompileCommands
104 | */
105 | CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
106 |
107 | /**
108 | * Get the number of CompileCommand we have for a file
109 | */
110 | CINDEX_LINKAGE unsigned
111 | clang_CompileCommands_getSize(CXCompileCommands);
112 |
113 | /**
114 | * Get the I'th CompileCommand for a file
115 | *
116 | * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
117 | */
118 | CINDEX_LINKAGE CXCompileCommand
119 | clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
120 |
121 | /**
122 | * Get the working directory where the CompileCommand was executed from
123 | */
124 | CINDEX_LINKAGE CXString
125 | clang_CompileCommand_getDirectory(CXCompileCommand);
126 |
127 | /**
128 | * Get the filename associated with the CompileCommand.
129 | */
130 | CINDEX_LINKAGE CXString
131 | clang_CompileCommand_getFilename(CXCompileCommand);
132 |
133 | /**
134 | * Get the number of arguments in the compiler invocation.
135 | *
136 | */
137 | CINDEX_LINKAGE unsigned
138 | clang_CompileCommand_getNumArgs(CXCompileCommand);
139 |
140 | /**
141 | * Get the I'th argument value in the compiler invocations
142 | *
143 | * Invariant :
144 | * - argument 0 is the compiler executable
145 | */
146 | CINDEX_LINKAGE CXString
147 | clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
148 |
149 | /**
150 | * Get the number of source mappings for the compiler invocation.
151 | */
152 | CINDEX_LINKAGE unsigned
153 | clang_CompileCommand_getNumMappedSources(CXCompileCommand);
154 |
155 | /**
156 | * Get the I'th mapped source path for the compiler invocation.
157 | */
158 | CINDEX_LINKAGE CXString
159 | clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
160 |
161 | /**
162 | * Get the I'th mapped source content for the compiler invocation.
163 | */
164 | CINDEX_LINKAGE CXString
165 | clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
166 |
167 | /**
168 | * @}
169 | */
170 |
171 | LLVM_CLANG_C_EXTERN_C_END
172 |
173 | #endif
174 |
175 |
--------------------------------------------------------------------------------
/include/clang-c/CXErrorCode.h:
--------------------------------------------------------------------------------
1 | /*===-- clang-c/CXErrorCode.h - C Index Error Codes --------------*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides the CXErrorCode enumerators. *|
11 | |* *|
12 | \*===----------------------------------------------------------------------===*/
13 |
14 | #ifndef LLVM_CLANG_C_CXERRORCODE_H
15 | #define LLVM_CLANG_C_CXERRORCODE_H
16 |
17 | #include "clang-c/ExternC.h"
18 | #include "clang-c/Platform.h"
19 |
20 | LLVM_CLANG_C_EXTERN_C_BEGIN
21 |
22 | /**
23 | * Error codes returned by libclang routines.
24 | *
25 | * Zero (\c CXError_Success) is the only error code indicating success. Other
26 | * error codes, including not yet assigned non-zero values, indicate errors.
27 | */
28 | enum CXErrorCode {
29 | /**
30 | * No error.
31 | */
32 | CXError_Success = 0,
33 |
34 | /**
35 | * A generic error code, no further details are available.
36 | *
37 | * Errors of this kind can get their own specific error codes in future
38 | * libclang versions.
39 | */
40 | CXError_Failure = 1,
41 |
42 | /**
43 | * libclang crashed while performing the requested operation.
44 | */
45 | CXError_Crashed = 2,
46 |
47 | /**
48 | * The function detected that the arguments violate the function
49 | * contract.
50 | */
51 | CXError_InvalidArguments = 3,
52 |
53 | /**
54 | * An AST deserialization error has occurred.
55 | */
56 | CXError_ASTReadError = 4
57 | };
58 |
59 | LLVM_CLANG_C_EXTERN_C_END
60 |
61 | #endif
62 |
63 |
--------------------------------------------------------------------------------
/include/clang-c/CXString.h:
--------------------------------------------------------------------------------
1 | /*===-- clang-c/CXString.h - C Index strings --------------------*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides the interface to C Index strings. *|
11 | |* *|
12 | \*===----------------------------------------------------------------------===*/
13 |
14 | #ifndef LLVM_CLANG_C_CXSTRING_H
15 | #define LLVM_CLANG_C_CXSTRING_H
16 |
17 | #include "clang-c/ExternC.h"
18 | #include "clang-c/Platform.h"
19 |
20 | LLVM_CLANG_C_EXTERN_C_BEGIN
21 |
22 | /**
23 | * \defgroup CINDEX_STRING String manipulation routines
24 | * \ingroup CINDEX
25 | *
26 | * @{
27 | */
28 |
29 | /**
30 | * A character string.
31 | *
32 | * The \c CXString type is used to return strings from the interface when
33 | * the ownership of that string might differ from one call to the next.
34 | * Use \c clang_getCString() to retrieve the string data and, once finished
35 | * with the string data, call \c clang_disposeString() to free the string.
36 | */
37 | typedef struct {
38 | const void *data;
39 | unsigned private_flags;
40 | } CXString;
41 |
42 | typedef struct {
43 | CXString *Strings;
44 | unsigned Count;
45 | } CXStringSet;
46 |
47 | /**
48 | * Retrieve the character data associated with the given string.
49 | */
50 | CINDEX_LINKAGE const char *clang_getCString(CXString string);
51 |
52 | /**
53 | * Free the given string.
54 | */
55 | CINDEX_LINKAGE void clang_disposeString(CXString string);
56 |
57 | /**
58 | * Free the given string set.
59 | */
60 | CINDEX_LINKAGE void clang_disposeStringSet(CXStringSet *set);
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | LLVM_CLANG_C_EXTERN_C_END
67 |
68 | #endif
69 |
70 |
--------------------------------------------------------------------------------
/include/clang-c/Documentation.h:
--------------------------------------------------------------------------------
1 | /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides a supplementary interface for inspecting *|
11 | |* documentation comments. *|
12 | |* *|
13 | \*===----------------------------------------------------------------------===*/
14 |
15 | #ifndef LLVM_CLANG_C_DOCUMENTATION_H
16 | #define LLVM_CLANG_C_DOCUMENTATION_H
17 |
18 | #include "clang-c/ExternC.h"
19 | #include "clang-c/Index.h"
20 |
21 | LLVM_CLANG_C_EXTERN_C_BEGIN
22 |
23 | /**
24 | * \defgroup CINDEX_COMMENT Comment introspection
25 | *
26 | * The routines in this group provide access to information in documentation
27 | * comments. These facilities are distinct from the core and may be subject to
28 | * their own schedule of stability and deprecation.
29 | *
30 | * @{
31 | */
32 |
33 | /**
34 | * A parsed comment.
35 | */
36 | typedef struct {
37 | const void *ASTNode;
38 | CXTranslationUnit TranslationUnit;
39 | } CXComment;
40 |
41 | /**
42 | * Given a cursor that represents a documentable entity (e.g.,
43 | * declaration), return the associated parsed comment as a
44 | * \c CXComment_FullComment AST node.
45 | */
46 | CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
47 |
48 | /**
49 | * Describes the type of the comment AST node (\c CXComment). A comment
50 | * node can be considered block content (e. g., paragraph), inline content
51 | * (plain text) or neither (the root AST node).
52 | */
53 | enum CXCommentKind {
54 | /**
55 | * Null comment. No AST node is constructed at the requested location
56 | * because there is no text or a syntax error.
57 | */
58 | CXComment_Null = 0,
59 |
60 | /**
61 | * Plain text. Inline content.
62 | */
63 | CXComment_Text = 1,
64 |
65 | /**
66 | * A command with word-like arguments that is considered inline content.
67 | *
68 | * For example: \\c command.
69 | */
70 | CXComment_InlineCommand = 2,
71 |
72 | /**
73 | * HTML start tag with attributes (name-value pairs). Considered
74 | * inline content.
75 | *
76 | * For example:
77 | * \verbatim
78 | *
79 | * \endverbatim
80 | */
81 | CXComment_HTMLStartTag = 3,
82 |
83 | /**
84 | * HTML end tag. Considered inline content.
85 | *
86 | * For example:
87 | * \verbatim
88 | *
89 | * \endverbatim
90 | */
91 | CXComment_HTMLEndTag = 4,
92 |
93 | /**
94 | * A paragraph, contains inline comment. The paragraph itself is
95 | * block content.
96 | */
97 | CXComment_Paragraph = 5,
98 |
99 | /**
100 | * A command that has zero or more word-like arguments (number of
101 | * word-like arguments depends on command name) and a paragraph as an
102 | * argument. Block command is block content.
103 | *
104 | * Paragraph argument is also a child of the block command.
105 | *
106 | * For example: \has 0 word-like arguments and a paragraph argument.
107 | *
108 | * AST nodes of special kinds that parser knows about (e. g., \\param
109 | * command) have their own node kinds.
110 | */
111 | CXComment_BlockCommand = 6,
112 |
113 | /**
114 | * A \\param or \\arg command that describes the function parameter
115 | * (name, passing direction, description).
116 | *
117 | * For example: \\param [in] ParamName description.
118 | */
119 | CXComment_ParamCommand = 7,
120 |
121 | /**
122 | * A \\tparam command that describes a template parameter (name and
123 | * description).
124 | *
125 | * For example: \\tparam T description.
126 | */
127 | CXComment_TParamCommand = 8,
128 |
129 | /**
130 | * A verbatim block command (e. g., preformatted code). Verbatim
131 | * block has an opening and a closing command and contains multiple lines of
132 | * text (\c CXComment_VerbatimBlockLine child nodes).
133 | *
134 | * For example:
135 | * \\verbatim
136 | * aaa
137 | * \\endverbatim
138 | */
139 | CXComment_VerbatimBlockCommand = 9,
140 |
141 | /**
142 | * A line of text that is contained within a
143 | * CXComment_VerbatimBlockCommand node.
144 | */
145 | CXComment_VerbatimBlockLine = 10,
146 |
147 | /**
148 | * A verbatim line command. Verbatim line has an opening command,
149 | * a single line of text (up to the newline after the opening command) and
150 | * has no closing command.
151 | */
152 | CXComment_VerbatimLine = 11,
153 |
154 | /**
155 | * A full comment attached to a declaration, contains block content.
156 | */
157 | CXComment_FullComment = 12
158 | };
159 |
160 | /**
161 | * The most appropriate rendering mode for an inline command, chosen on
162 | * command semantics in Doxygen.
163 | */
164 | enum CXCommentInlineCommandRenderKind {
165 | /**
166 | * Command argument should be rendered in a normal font.
167 | */
168 | CXCommentInlineCommandRenderKind_Normal,
169 |
170 | /**
171 | * Command argument should be rendered in a bold font.
172 | */
173 | CXCommentInlineCommandRenderKind_Bold,
174 |
175 | /**
176 | * Command argument should be rendered in a monospaced font.
177 | */
178 | CXCommentInlineCommandRenderKind_Monospaced,
179 |
180 | /**
181 | * Command argument should be rendered emphasized (typically italic
182 | * font).
183 | */
184 | CXCommentInlineCommandRenderKind_Emphasized,
185 |
186 | /**
187 | * Command argument should not be rendered (since it only defines an anchor).
188 | */
189 | CXCommentInlineCommandRenderKind_Anchor
190 | };
191 |
192 | /**
193 | * Describes parameter passing direction for \\param or \\arg command.
194 | */
195 | enum CXCommentParamPassDirection {
196 | /**
197 | * The parameter is an input parameter.
198 | */
199 | CXCommentParamPassDirection_In,
200 |
201 | /**
202 | * The parameter is an output parameter.
203 | */
204 | CXCommentParamPassDirection_Out,
205 |
206 | /**
207 | * The parameter is an input and output parameter.
208 | */
209 | CXCommentParamPassDirection_InOut
210 | };
211 |
212 | /**
213 | * \param Comment AST node of any kind.
214 | *
215 | * \returns the type of the AST node.
216 | */
217 | CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
218 |
219 | /**
220 | * \param Comment AST node of any kind.
221 | *
222 | * \returns number of children of the AST node.
223 | */
224 | CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
225 |
226 | /**
227 | * \param Comment AST node of any kind.
228 | *
229 | * \param ChildIdx child index (zero-based).
230 | *
231 | * \returns the specified child of the AST node.
232 | */
233 | CINDEX_LINKAGE
234 | CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
235 |
236 | /**
237 | * A \c CXComment_Paragraph node is considered whitespace if it contains
238 | * only \c CXComment_Text nodes that are empty or whitespace.
239 | *
240 | * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
241 | * never considered whitespace.
242 | *
243 | * \returns non-zero if \c Comment is whitespace.
244 | */
245 | CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
246 |
247 | /**
248 | * \returns non-zero if \c Comment is inline content and has a newline
249 | * immediately following it in the comment text. Newlines between paragraphs
250 | * do not count.
251 | */
252 | CINDEX_LINKAGE
253 | unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
254 |
255 | /**
256 | * \param Comment a \c CXComment_Text AST node.
257 | *
258 | * \returns text contained in the AST node.
259 | */
260 | CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
261 |
262 | /**
263 | * \param Comment a \c CXComment_InlineCommand AST node.
264 | *
265 | * \returns name of the inline command.
266 | */
267 | CINDEX_LINKAGE
268 | CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
269 |
270 | /**
271 | * \param Comment a \c CXComment_InlineCommand AST node.
272 | *
273 | * \returns the most appropriate rendering mode, chosen on command
274 | * semantics in Doxygen.
275 | */
276 | CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
277 | clang_InlineCommandComment_getRenderKind(CXComment Comment);
278 |
279 | /**
280 | * \param Comment a \c CXComment_InlineCommand AST node.
281 | *
282 | * \returns number of command arguments.
283 | */
284 | CINDEX_LINKAGE
285 | unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
286 |
287 | /**
288 | * \param Comment a \c CXComment_InlineCommand AST node.
289 | *
290 | * \param ArgIdx argument index (zero-based).
291 | *
292 | * \returns text of the specified argument.
293 | */
294 | CINDEX_LINKAGE
295 | CXString clang_InlineCommandComment_getArgText(CXComment Comment,
296 | unsigned ArgIdx);
297 |
298 | /**
299 | * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
300 | * node.
301 | *
302 | * \returns HTML tag name.
303 | */
304 | CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
305 |
306 | /**
307 | * \param Comment a \c CXComment_HTMLStartTag AST node.
308 | *
309 | * \returns non-zero if tag is self-closing (for example, <br />).
310 | */
311 | CINDEX_LINKAGE
312 | unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
313 |
314 | /**
315 | * \param Comment a \c CXComment_HTMLStartTag AST node.
316 | *
317 | * \returns number of attributes (name-value pairs) attached to the start tag.
318 | */
319 | CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
320 |
321 | /**
322 | * \param Comment a \c CXComment_HTMLStartTag AST node.
323 | *
324 | * \param AttrIdx attribute index (zero-based).
325 | *
326 | * \returns name of the specified attribute.
327 | */
328 | CINDEX_LINKAGE
329 | CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
330 |
331 | /**
332 | * \param Comment a \c CXComment_HTMLStartTag AST node.
333 | *
334 | * \param AttrIdx attribute index (zero-based).
335 | *
336 | * \returns value of the specified attribute.
337 | */
338 | CINDEX_LINKAGE
339 | CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
340 |
341 | /**
342 | * \param Comment a \c CXComment_BlockCommand AST node.
343 | *
344 | * \returns name of the block command.
345 | */
346 | CINDEX_LINKAGE
347 | CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
348 |
349 | /**
350 | * \param Comment a \c CXComment_BlockCommand AST node.
351 | *
352 | * \returns number of word-like arguments.
353 | */
354 | CINDEX_LINKAGE
355 | unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
356 |
357 | /**
358 | * \param Comment a \c CXComment_BlockCommand AST node.
359 | *
360 | * \param ArgIdx argument index (zero-based).
361 | *
362 | * \returns text of the specified word-like argument.
363 | */
364 | CINDEX_LINKAGE
365 | CXString clang_BlockCommandComment_getArgText(CXComment Comment,
366 | unsigned ArgIdx);
367 |
368 | /**
369 | * \param Comment a \c CXComment_BlockCommand or
370 | * \c CXComment_VerbatimBlockCommand AST node.
371 | *
372 | * \returns paragraph argument of the block command.
373 | */
374 | CINDEX_LINKAGE
375 | CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
376 |
377 | /**
378 | * \param Comment a \c CXComment_ParamCommand AST node.
379 | *
380 | * \returns parameter name.
381 | */
382 | CINDEX_LINKAGE
383 | CXString clang_ParamCommandComment_getParamName(CXComment Comment);
384 |
385 | /**
386 | * \param Comment a \c CXComment_ParamCommand AST node.
387 | *
388 | * \returns non-zero if the parameter that this AST node represents was found
389 | * in the function prototype and \c clang_ParamCommandComment_getParamIndex
390 | * function will return a meaningful value.
391 | */
392 | CINDEX_LINKAGE
393 | unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
394 |
395 | /**
396 | * \param Comment a \c CXComment_ParamCommand AST node.
397 | *
398 | * \returns zero-based parameter index in function prototype.
399 | */
400 | CINDEX_LINKAGE
401 | unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
402 |
403 | /**
404 | * \param Comment a \c CXComment_ParamCommand AST node.
405 | *
406 | * \returns non-zero if parameter passing direction was specified explicitly in
407 | * the comment.
408 | */
409 | CINDEX_LINKAGE
410 | unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
411 |
412 | /**
413 | * \param Comment a \c CXComment_ParamCommand AST node.
414 | *
415 | * \returns parameter passing direction.
416 | */
417 | CINDEX_LINKAGE
418 | enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
419 | CXComment Comment);
420 |
421 | /**
422 | * \param Comment a \c CXComment_TParamCommand AST node.
423 | *
424 | * \returns template parameter name.
425 | */
426 | CINDEX_LINKAGE
427 | CXString clang_TParamCommandComment_getParamName(CXComment Comment);
428 |
429 | /**
430 | * \param Comment a \c CXComment_TParamCommand AST node.
431 | *
432 | * \returns non-zero if the parameter that this AST node represents was found
433 | * in the template parameter list and
434 | * \c clang_TParamCommandComment_getDepth and
435 | * \c clang_TParamCommandComment_getIndex functions will return a meaningful
436 | * value.
437 | */
438 | CINDEX_LINKAGE
439 | unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
440 |
441 | /**
442 | * \param Comment a \c CXComment_TParamCommand AST node.
443 | *
444 | * \returns zero-based nesting depth of this parameter in the template parameter list.
445 | *
446 | * For example,
447 | * \verbatim
448 | * template class TT>
449 | * void test(TT aaa);
450 | * \endverbatim
451 | * for C and TT nesting depth is 0,
452 | * for T nesting depth is 1.
453 | */
454 | CINDEX_LINKAGE
455 | unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
456 |
457 | /**
458 | * \param Comment a \c CXComment_TParamCommand AST node.
459 | *
460 | * \returns zero-based parameter index in the template parameter list at a
461 | * given nesting depth.
462 | *
463 | * For example,
464 | * \verbatim
465 | * template class TT>
466 | * void test(TT aaa);
467 | * \endverbatim
468 | * for C and TT nesting depth is 0, so we can ask for index at depth 0:
469 | * at depth 0 C's index is 0, TT's index is 1.
470 | *
471 | * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
472 | * at depth 0 T's index is 1 (same as TT's),
473 | * at depth 1 T's index is 0.
474 | */
475 | CINDEX_LINKAGE
476 | unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
477 |
478 | /**
479 | * \param Comment a \c CXComment_VerbatimBlockLine AST node.
480 | *
481 | * \returns text contained in the AST node.
482 | */
483 | CINDEX_LINKAGE
484 | CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
485 |
486 | /**
487 | * \param Comment a \c CXComment_VerbatimLine AST node.
488 | *
489 | * \returns text contained in the AST node.
490 | */
491 | CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
492 |
493 | /**
494 | * Convert an HTML tag AST node to string.
495 | *
496 | * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
497 | * node.
498 | *
499 | * \returns string containing an HTML tag.
500 | */
501 | CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
502 |
503 | /**
504 | * Convert a given full parsed comment to an HTML fragment.
505 | *
506 | * Specific details of HTML layout are subject to change. Don't try to parse
507 | * this HTML back into an AST, use other APIs instead.
508 | *
509 | * Currently the following CSS classes are used:
510 | * \li "para-brief" for \paragraph and equivalent commands;
511 | * \li "para-returns" for \\returns paragraph and equivalent commands;
512 | * \li "word-returns" for the "Returns" word in \\returns paragraph.
513 | *
514 | * Function argument documentation is rendered as a \ list with arguments
515 | * sorted in function prototype order. CSS classes used:
516 | * \li "param-name-index-NUMBER" for parameter name (\- );
517 | * \li "param-descr-index-NUMBER" for parameter description (\
- );
518 | * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
519 | * parameter index is invalid.
520 | *
521 | * Template parameter documentation is rendered as a \
list with
522 | * parameters sorted in template parameter list order. CSS classes used:
523 | * \li "tparam-name-index-NUMBER" for parameter name (\- );
524 | * \li "tparam-descr-index-NUMBER" for parameter description (\
- );
525 | * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
526 | * names inside template template parameters;
527 | * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
528 | * parameter position is invalid.
529 | *
530 | * \param Comment a \c CXComment_FullComment AST node.
531 | *
532 | * \returns string containing an HTML fragment.
533 | */
534 | CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
535 |
536 | /**
537 | * Convert a given full parsed comment to an XML document.
538 | *
539 | * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
540 | * inside clang source tree.
541 | *
542 | * \param Comment a \c CXComment_FullComment AST node.
543 | *
544 | * \returns string containing an XML document.
545 | */
546 | CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
547 |
548 | /**
549 | * @}
550 | */
551 |
552 | LLVM_CLANG_C_EXTERN_C_END
553 |
554 | #endif /* CLANG_C_DOCUMENTATION_H */
555 |
556 |
--------------------------------------------------------------------------------
/include/clang-c/ExternC.h:
--------------------------------------------------------------------------------
1 | /*===- clang-c/ExternC.h - Wrapper for 'extern "C"' ---------------*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This file defines an 'extern "C"' wrapper. *|
11 | |* *|
12 | \*===----------------------------------------------------------------------===*/
13 |
14 | #ifndef LLVM_CLANG_C_EXTERN_C_H
15 | #define LLVM_CLANG_C_EXTERN_C_H
16 |
17 | #ifdef __clang__
18 | #define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN \
19 | _Pragma("clang diagnostic push") \
20 | _Pragma("clang diagnostic error \"-Wstrict-prototypes\"")
21 | #define LLVM_CLANG_C_STRICT_PROTOTYPES_END _Pragma("clang diagnostic pop")
22 | #else
23 | #define LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
24 | #define LLVM_CLANG_C_STRICT_PROTOTYPES_END
25 | #endif
26 |
27 | #ifdef __cplusplus
28 | #define LLVM_CLANG_C_EXTERN_C_BEGIN \
29 | extern "C" { \
30 | LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
31 | #define LLVM_CLANG_C_EXTERN_C_END \
32 | LLVM_CLANG_C_STRICT_PROTOTYPES_END \
33 | }
34 | #else
35 | #define LLVM_CLANG_C_EXTERN_C_BEGIN LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN
36 | #define LLVM_CLANG_C_EXTERN_C_END LLVM_CLANG_C_STRICT_PROTOTYPES_END
37 | #endif
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/include/clang-c/FatalErrorHandler.h:
--------------------------------------------------------------------------------
1 | /*===-- clang-c/FatalErrorHandler.h - Fatal Error Handling --------*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | \*===----------------------------------------------------------------------===*/
9 |
10 | #ifndef LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
11 | #define LLVM_CLANG_C_FATAL_ERROR_HANDLER_H
12 |
13 | #include "clang-c/ExternC.h"
14 |
15 | LLVM_CLANG_C_EXTERN_C_BEGIN
16 |
17 | /**
18 | * Installs error handler that prints error message to stderr and calls abort().
19 | * Replaces currently installed error handler (if any).
20 | */
21 | void clang_install_aborting_llvm_fatal_error_handler(void);
22 |
23 | /**
24 | * Removes currently installed error handler (if any).
25 | * If no error handler is intalled, the default strategy is to print error
26 | * message to stderr and call exit(1).
27 | */
28 | void clang_uninstall_llvm_fatal_error_handler(void);
29 |
30 | LLVM_CLANG_C_EXTERN_C_END
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/clang-c/Makefile:
--------------------------------------------------------------------------------
1 | CLANG_LEVEL := ../..
2 | DIRS :=
3 |
4 | include $(CLANG_LEVEL)/Makefile
5 |
6 | IntIncludeDir = $(DESTDIR)$(PROJ_internal_prefix)/include
7 |
8 | install-local::
9 | $(Echo) Installing Clang C API include files
10 | $(Verb) $(MKDIR) $(IntIncludeDir)
11 | $(Verb) if test -d "$(PROJ_SRC_DIR)" ; then \
12 | cd $(PROJ_SRC_DIR)/.. && \
13 | for hdr in `find clang-c -type f '!' '(' -name '*~' \
14 | -o -name '.#*' -o -name '*.in' -o -name '*.txt' \
15 | -o -name 'Makefile' -o -name '*.td' ')' -print \
16 | | grep -v CVS | grep -v .svn | grep -v .dir` ; do \
17 | instdir=`dirname "$(IntIncludeDir)/$$hdr"` ; \
18 | if test \! -d "$$instdir" ; then \
19 | $(EchoCmd) Making install directory $$instdir ; \
20 | $(MKDIR) $$instdir ;\
21 | fi ; \
22 | $(DataInstall) $$hdr $(IntIncludeDir)/$$hdr ; \
23 | done ; \
24 | fi
25 | ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
26 | $(Verb) if test -d "$(PROJ_OBJ_ROOT)/tools/clang/include/clang-c" ; then \
27 | cd $(PROJ_OBJ_ROOT)/tools/clang/include && \
28 | for hdr in `find clang-c -type f '!' '(' -name 'Makefile' ')' -print \
29 | | grep -v CVS | grep -v .tmp | grep -v .dir` ; do \
30 | instdir=`dirname "$(IntIncludeDir)/$$hdr"` ; \
31 | if test \! -d "$$instdir" ; then \
32 | $(EchoCmd) Making install directory $$instdir ; \
33 | $(MKDIR) $$instdir ;\
34 | fi ; \
35 | $(DataInstall) $$hdr $(IntIncludeDir)/$$hdr ; \
36 | done ; \
37 | fi
38 | endif
39 |
--------------------------------------------------------------------------------
/include/clang-c/Platform.h:
--------------------------------------------------------------------------------
1 | /*===-- clang-c/Platform.h - C Index platform decls -------------*- C -*-===*\
2 | |* *|
3 | |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 | |* Exceptions. *|
5 | |* See https://llvm.org/LICENSE.txt for license information. *|
6 | |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 | |* *|
8 | |*===----------------------------------------------------------------------===*|
9 | |* *|
10 | |* This header provides platform specific macros (dllimport, deprecated, ...) *|
11 | |* *|
12 | \*===----------------------------------------------------------------------===*/
13 |
14 | #ifndef LLVM_CLANG_C_PLATFORM_H
15 | #define LLVM_CLANG_C_PLATFORM_H
16 |
17 | #include "clang-c/ExternC.h"
18 |
19 | LLVM_CLANG_C_EXTERN_C_BEGIN
20 |
21 | /* MSVC DLL import/export. */
22 | #ifdef _MSC_VER
23 | #ifdef _CINDEX_LIB_
24 | #define CINDEX_LINKAGE __declspec(dllexport)
25 | #else
26 | #define CINDEX_LINKAGE __declspec(dllimport)
27 | #endif
28 | #else
29 | #define CINDEX_LINKAGE
30 | #endif
31 |
32 | #ifdef __GNUC__
33 | #define CINDEX_DEPRECATED __attribute__((deprecated))
34 | #else
35 | #ifdef _MSC_VER
36 | #define CINDEX_DEPRECATED __declspec(deprecated)
37 | #else
38 | #define CINDEX_DEPRECATED
39 | #endif
40 | #endif
41 |
42 | LLVM_CLANG_C_EXTERN_C_END
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/include/clang-c/module.modulemap:
--------------------------------------------------------------------------------
1 | module Clang_C {
2 | umbrella "."
3 | module * { export * }
4 | }
5 |
--------------------------------------------------------------------------------
/scread.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "clang-c/Index.h"
5 |
6 | char* findingString = "Init";
7 | int numOfArgc = 0;
8 |
9 | bool printKindSpelling(CXCursor cursor) {
10 | enum CXCursorKind curKind = clang_getCursorKind(cursor);
11 | const char *curkindSpelling = clang_getCString(
12 | clang_getCursorKindSpelling(curKind));
13 | printf("The AST node kind spelling is:%s\n", curkindSpelling);
14 | return true;
15 | }
16 |
17 | bool printSpelling(CXCursor cursor) {
18 | const char *astSpelling = clang_getCString(clang_getCursorSpelling(cursor));
19 | printf("The AST node spelling is:%s\n", astSpelling);
20 | return true;
21 | }
22 |
23 | bool printLocation(CXCursor cursor) {
24 | CXSourceRange range = clang_getCursorExtent(cursor);
25 | CXSourceLocation startLocation = clang_getRangeStart(range);
26 | CXSourceLocation endLocation = clang_getRangeEnd(range);
27 |
28 | CXFile file;
29 | unsigned int line, column, offset;
30 | clang_getInstantiationLocation(startLocation, &file, &line, &column, &offset);
31 | printf("Start: Line: %u Column: %u Offset: %u\n", line, column, offset);
32 | clang_getInstantiationLocation(endLocation, &file, &line, &column, &offset);
33 | printf("End: Line: %u Column: %u Offset: %u\n", line, column, offset);
34 |
35 | return true;
36 | }
37 |
38 | enum CXChildVisitResult printVisitor(CXCursor cursor, CXCursor parent,
39 | CXClientData client_data) {
40 | char *astSpelling = clang_getCString(clang_getCursorSpelling(cursor));
41 | if (numOfArgc == 3) {
42 | if (strcmp(astSpelling, findingString) == 0) {
43 | printSpelling(cursor);
44 | printKindSpelling(cursor);
45 | printLocation(cursor);
46 | }
47 | } else {
48 | printSpelling(cursor);
49 | printKindSpelling(cursor);
50 | printLocation(cursor);
51 | }
52 | return CXChildVisit_Recurse;
53 | }
54 |
55 | int main(int argc, char *argv[]) {
56 | if ((argc > 3) || (argc < 2)) {
57 | printf("You input wrong number arguments!\n");
58 | return -1;
59 | }
60 |
61 | if ((strcmp(argv[1],"-v")) == 0) {
62 | printf("scread version:0.1\n");
63 | printf("Author shining\n");
64 | printf("Mail:shiningning1984@gmail.com\n");
65 | return 0;
66 | }else if ((strcmp(argv[1],"-help")) == 0) {
67 | printf("scread The scread will output all the AST nodes' information\n");
68 | printf("scread The scread will output the AST nodes' matched the keyword.\n");
69 | printf("scread -v The scread will output the version information.\n");
70 | printf("scread -help The scread will output the help information.\n");
71 | return 0;
72 | }else {
73 | int result = open(argv[1], O_RDONLY);
74 | if (result == -1) {
75 | printf("Can't open the file: %s.\n", argv[1]);
76 | return -1;
77 | }
78 | }
79 |
80 | numOfArgc = argc;
81 | if (numOfArgc == 3) {
82 | findingString = argv[2];
83 | }
84 |
85 | CXIndex Index = clang_createIndex(0,0);
86 | CXTranslationUnit TU = clang_parseTranslationUnit(Index, 0, argv, argc,
87 | 0, 0,
88 | CXTranslationUnit_None);
89 | CXCursor C = clang_getTranslationUnitCursor(TU);
90 |
91 | printSpelling(C);
92 | printKindSpelling(C);
93 | printLocation(C);
94 |
95 | clang_visitChildren(C, printVisitor, NULL);
96 |
97 | clang_disposeTranslationUnit(TU);
98 | clang_disposeIndex(Index);
99 | return 0;
100 | }
101 |
--------------------------------------------------------------------------------
/test/HelloWorld.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | printf("Hello world.\n");
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/test/Node.h:
--------------------------------------------------------------------------------
1 | struct Node {
2 | int value;
3 | struct Node *next;
4 | };
5 |
--------------------------------------------------------------------------------
/test/Variable.h:
--------------------------------------------------------------------------------
1 | int a = 0;
2 |
--------------------------------------------------------------------------------
/test/VariableAdd.h:
--------------------------------------------------------------------------------
1 | int a = 1, b = 2, c;
2 | c = a + b;
3 |
4 |
--------------------------------------------------------------------------------