How to get actual name of invalid/unresolved type in clang AST
Asked Answered
T

0

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

Twinkle answered 31/12, 2016 at 10:16 Comment(3)
Did you manage to find a solution or a workaround?Stria
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.Twinkle
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.Hydrostat

© 2022 - 2024 — McMap. All rights reserved.