You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Programming Guide For CppAst.Net.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,15 +192,15 @@ From the above example, we can already see some advantages of CppAst.Net:
192
192
2. It supports building Compilation directly from a string, which also facilitates the implementation of unit tests.
193
193
194
194
### 3.1 Easy to Start with Simple Configuration
195
-
  CppAst.Net fundamentally relies on ClangSharp. Those who have experience with ClangSharp might be aware that the compilation and execution experience may not be very smooth. After adding the ClangSharp package from NuGet, attempting to run related examples and test codes might still prompt issues such as the absence of `libclang.dll/ligclang.so`, leading to a less than ideal experience. This situation can't be entirely blamed on ClangSharp, as it mainly stems from NuGet's limitations on the size of native binaries that a package can depend on. Since this issue might be encountered by many, let's first share a workaround to facilitate easier running of your own test codes:
195
+
  CppAst.Net fundamentally relies on ClangSharpand its native libclang binaries. After adding the CppAst package from NuGet, projects should still select a runtime identifier so the correct native asset can be restored and loaded. A common project-file configuration is:
196
196
```xml
197
197
<PropertyGroup>
198
198
<!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 -->
199
199
<RuntimeIdentifierCondition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
200
200
</PropertyGroup>
201
201
```
202
202
203
-
For the official sample codes mentioned earlier, we can try to start from scratch and create a `C# .netcore 3.1` Console App, and step by step get it to run:
203
+
For the official sample code mentioned earlier, we can start from scratch with a modern `.NET 8` console app and get it running step by step:
204
204
205
205
#### 3.1.1 Creating a Project
206
206
**Open Visual Studio and create a C# Console App (the environment used by the author is VS 2022):**
@@ -209,7 +209,7 @@ For the official sample codes mentioned earlier, we can try to start from scratc
209
209
**Configure the project name:**
210
210

211
211
212
-
**Select the .net version (here we directly use .net core 3.1):**
212
+
**Select the .NET version (the current package targets .NET 8):**
213
213

214
214
215
215
#### 3.1.2 Adding `CppAst.Net` Package via NuGet
@@ -229,26 +229,26 @@ For the official sample codes mentioned earlier, we can try to start from scratc
229
229
230
230
<PropertyGroup>
231
231
<OutputType>Exe</OutputType>
232
-
<TargetFramework>netcoreapp3.1</TargetFramework>
232
+
<TargetFramework>net8.0</TargetFramework>
233
233
234
234
<!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 -->
235
235
<RuntimeIdentifierCondition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
The `RuntimeIdentifier` entry is essential, as omitting it could lead to runtime errors due to missing libclang native dlls.
244
+
Replace `LATEST_VERSION` with the current NuGet version. The `RuntimeIdentifier` entry is recommended so restore selects the native libclang asset for the current platform.
245
245
246
246
#### 3.1.4 Adding Sample Code and Testing the App
247
247
**Add test code in the Main() function of Program.cs:**
248
248
```cs
249
249
staticvoidMain(string[] args)
250
250
{
251
-
// Parse a C++ files
251
+
// Parse C++ files
252
252
varcompilation=CppParser.Parse(@"
253
253
enum MyEnum { MyEnum_0, MyEnum_1 };
254
254
void function0(int a, int b);
@@ -455,7 +455,7 @@ foo<int, int> foobar;
455
455
456
456
### 4.2 Support for `meta attribute`
457
457
  In this section, we added a specific document [attributes.md](https://github.com/xoofx/CppAst.NET/blob/main/doc/attributes.md) to the CppAst.Net code repository. Interested readers can consult it on their own. It mainly addresses the issue mentioned above about needing to configure certain exported items without wanting to separate the code items from the configuration information. Originally, CppAst.Net also had its own implementation of token attributes based on token parsing, but when used in projects, it encountered some issues frequently mentioned by the community:
458
-
1.`ParseAttributes()`was time-consuming, leading to the introduction of the `ParseAttributes` parameter in later versions to control whether to parse `attributes`. However, in some cases, we rely on `attributes` to implement certain functionalities, which obviously was inconvenient.
458
+
1.Token-based attribute parsing was time-consuming, so current versions keep that compatibility path opt-in through `CppParserOptions.ParseTokenAttributes`.
459
459
460
460
2. There were flaws in parsing `meta attribute` - `[[]]`. `meta attribute` defined above `Function` and `Field` is semantically legal, but `cppast.net` could not properly support such `meta attribute` defined above objects (with some exceptions, like `namespace`, `class`, `enum`, where the attribute declaration itself cannot be placed above, as the compiler would directly report errors for such usages, it can only be placed after the related keywords, like `class [[deprecated]] Abc{};`).
Copy file name to clipboardExpand all lines: doc/attributes.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## 1. `cppast.net 0.12` Support for `attributes`
2
2
The original support of `cppast.net` for various types of `attributes`, including the `meta attribute` of `c++17`, is restricted due to the limitation of `libclang` itself `Api`. We need to rely on token-level parsing to implement related functions. In the implementation of `cppast.net 0.12` and previous versions, we used parsing `token` to implement related functions. Even some `attributes` that `libclang` supports well, such as `dllexport`, `dllimport`, etc., `cppast.net` most of the time also uses token parsing. Although this approach is flexible and we can always try to parse the related `attributes` from the `token` level, it also brings some problems and restrictions, including:
3
-
1.`ParseAttributes()`is extremely time-consuming, which led to the addition of the `ParseAttributes` parameter in later versions to control whether to parse `attributes`. However, in some cases, we need to rely on `attributes` to complete the related functions, which is obviously inconvenient.
3
+
1.Token-based attribute parsing is comparatively expensive, which led to parser options that make fallback token parsing opt-in. In current CppAst versions, this compatibility path is controlled by `CppParserOptions.ParseTokenAttributes`.
4
4
2. There are defects in the parsing of `meta attribute` - `[[]]`. For `meta attribute` defined above `Function` and `Field`, it is obviously legal at the semantic level, but `cppast.net` does not support this type of `meta attribute` defined above the object very well (there are some exceptions here, like `namespace`, `class`, `enum` these `attribute` declarations, the attribute definition itself cannot be at the top, the compiler will report an error directly for the related usage, it can only be after the related keywords, such as `class [[deprecated]] Abc{};`).
5
5
3. Individual parameters of `meta attribute` use macros. Because our original implementation is based on `token` parsing, macros during compilation obviously cannot be correctly handled in this case.
6
6
@@ -17,7 +17,7 @@ Taking the code segment in the `cppast.net` test case as an example:
For `attributes` like `dllexport` and `visibility` that control interface visibility, we definitely use them more often, not only when `ParseAttributes` is turned on to make it work. We need to provide a high-performance solution for these basic system attributes, and the implementation should not be affected by the switch.
20
+
For attributes like `dllexport` and `visibility` that control interface visibility, we need them more often than an opt-in token parser would allow. Current CppAst exposes supported system attributes through `Attributes` without requiring `ParseTokenAttributes`.
21
21
22
22
---
23
23
### 2.2 Injection of Additional Information by Export Tools and Other Tools
0 commit comments