N
N
Noortvel2017-03-07 15:46:28
C++ / C#
Noortvel, 2017-03-07 15:46:28

Is there a parser for header files (C++)?

Is there a ready-made parser for header files in C ++? (Alya Reflection in C #)
That is, I fed the file to the parser, and it returns the class, all its members (functions, variables, etc.)?
PS probably you can just from headra (raw) to a text file.
Alya:

//SomeHeader.h
class someclass
{
private:
   int somevar;
public:
   void someFunc(float a);
   int someFunc2();
   bool s;
}

And in a text file
someclass:
    public:
    name : "someFunc"{
    type: "func"{
    varType: "void"
    argCount: "1"
    argType: "float"
    argName: "a"
   }
   }
   name:"s"{
   type:"var" {
   varType:"bool"
   }
   }
    // И т.д

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Adamos, 2017-03-07
@Adamos

An optimizing compiler can turn what is written in this header file into a 100% fiction that has no representation at all in the program. What are you going to address if the function, for example, is expanded in inline and does not have a call point at all?

F
Fat Lorrie, 2017-03-07
@Free_ze

Now a popular approach is to collect the types themselves already with metadata using preprocessing (Qt with its plugins) or templates (mushroom fantasies, like this one ). Something can be learned from the type traits of modern standards.
But somehow loading something in runtime that is obviously unknown (not having a known interface), especially with virtual functions, is unlikely.

R
Rou1997, 2017-03-07
@Rou1997

Ie fed the file to the parser, and it returns the class, all its members (functions, variables, etc.)?

It cannot just load a file and return exactly the class, since C / C ++ is a compiled language, moreover, even in C # and Java, you can only load compiled byte code, there is no full-fledged one evalthere either, it turns out that you must first programmatically compile the code, while "deceiving" the compiler so as not to "swear" on dependencies, most likely by generating "stubs", but no one has carried out work on such a "partial" compilation, especially for C ++ with its complex syntax, which is a pity, a good tool for reverse engineering would be turned out.
If you are satisfied with simply getting information about the class and members, then usually such a structure is called an AST tree, there are different parsers for this, it is obvious that this is in compilers and IDEs, but nothing of the kind is included in the STL and the "C" standard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question