Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cling] Properly split input line in top-level declaration/statements #9171

Open
jalopezg-git opened this issue Oct 22, 2021 · 2 comments
Open

Comments

@jalopezg-git
Copy link
Contributor

jalopezg-git commented Oct 22, 2021

Explain what you would like to see improved

Currently, cling uses cling::utils::getWrapPoint() to cut the input line in two parts: one that will become part of an internal wrapper function (i.e., __cling_Un1Qu3xxx) and the other that will not.
This mechanism is overly simplistic and cannot correctly handle some cases, e.g. users would expect that the excerpts below are equivalent, however,

root [0] namespace foo { int i; }
root [1] using namespace foo; std::cout << "hello\n";
hello
root [2] i
(int) 0

translates into do not wrap using namespace foo; and wrap std::cout << "hello\n";, while

root [0] namespace foo { int i; }
root [1] std::cout << "hello\n"; using namespace foo;
hello
root [2] i
input_line_11:2:3: error: use of undeclared identifier 'i'
 (i)
  ^

will wrap all the input. Therefore, the using directive is not parsed at the TU level.

Also, this function adds missing ; for some cases, but the current support is somewhat limited (see related issue #8064).

Optional: share how it could be improved

Cling should cut the input line in several independent fragments that will be either wrapped or directly parsed by clang. Additionally, these fragments shall incorporate some marks, such as "needs wrapper" or "needs terminating semicolon". The proposed solution might also add the terminating ; where required, if requested.

@jalopezg-git
Copy link
Contributor Author

jalopezg-git commented Oct 22, 2021

For reference, another obvious case of this issue:

root [0] void f() {} std::cout << "hello\n";
root [1] std::cout << "hello\n"; void g() {}
ROOT_prompt_1:1:34: error: function definition is not allowed here
std::cout << "hello\n"; void g() {}
                                 ^

@guitargeek
Copy link
Contributor

Another case originally reported in #8064:

root [0] using namespace ROOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants