antlr4-cpp icon indicating copy to clipboard operation
antlr4-cpp copied to clipboard

Apply const to generated parser code

Open obiwanjacobi opened this issue 6 years ago • 0 comments

Hi,

I'm using references to the generated parser contexts in my AST implementation. I find that I have a tendency to want to return const pointers from getter functions.

class AstExpression
{
public:
    const MyParser::ExpressionContext* getContext() const;
};

However calling any function on that return value to further navigate the parse-tree complains about the const because these functions are not declared as const (not changing the instance).

Would it be possible to generate const aware code? This would make it more correct (and strict).

Another one to consider is noexcept. Also seen virtual and override being used together. MSVC 'complains' that only one is needed. Not sure if other compilers feel the same.

obiwanjacobi avatar Jan 01 '20 10:01 obiwanjacobi