antlr / antlr/antlr4-cpp

Apply const to generated parser code

Open
#11 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
80
Forks
33
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.