Adding annotation syntax to C ++ source

I want to create my own annotation (same as Java style annotation) in my C ++ source. Since the standard C ++ syntax does not allow annotation, I would like to modify / improve the compiler for my own needs.

But does Visual Studio make an internal compiler environment for users to modify (for example, outputting its lexer, abstract syntax tree, etc.)? If not, are there any third party tools for C ++ syntax syntax and let me fix my own custom C ++ database in my own annotation?

+3
source share
2 answers

The standard solution to this problem, if it is associated with a programming language, and not with C ++, is to write a custom preprocessor that understands a subset of the language in question and your annotation, rewrites the code with annotations deleted, which is then passed to a real language compiler.

This is the standard method when it comes to expanding languages: adding a preprocessing step to the compiler.

Unfortunately, it is almost impossible to simply parse a C ++ function; C ++ source code processing almost always ends with the creation of a full AST generator, due to the fact that some of them are tedious for analyzing language features.

Take a look at these ads:

template<bool b, class T> void foo(T &t){if(b) T.do_this(); else T.do_that();}
class foobar { public: virtual void do_this(); virtual void do_that(); };
class barfoo : public foobar { public: virtual void do_this(); virtual void do_that(); };

and now this function

void bar(float l){ barfoo t; foo<fsqrt(l) > 1, foobar>(t); }

, , . , , .

, : MOC Qt, , : ++, . Qt , MOC.

++ .

+6

Visual Studio (, , ..)?

++ ++ ?

Clang

+9

Source: https://habr.com/ru/post/1780609/


All Articles