7

Consider the following code

int function()
{
  unknownType variable;
}

In the above code snippet, "unknownType" is not resolved at compile time, so clang will put default type as int in the AST and mark the declaration as invalid.

Now the question is while traversing the AST, how to get the name "unknownType". Getting the type name with existing API will give int, and its source range is also invalid.

Does anybody encounter such problem? Please help?

Thanks, Hemant

Hemant
  • 767
  • 6
  • 20
  • Did you manage to find a solution or a workaround? – maddouri Nov 20 '18 at 22:56
  • 1
    Yes, using the lexer API. I fetched the raw code at that location and extracted the text before identifier. This workaround works most of the time. But not elegant. – Hemant Nov 30 '18 at 09:05
  • Having found a solution, I suggest posting it as an answer so the question is removed from the unanswered questions list (it has 7 upvotes, so clearly others are interested). Otherwise, it would help to know a little more about why you want to obtain the name "unknownType", because potential ways to get it may work better or worse depending on the purpose. – Scott McPeak Jul 23 '23 at 12:27

0 Answers0