This is an archive of the discontinued LLVM Phabricator instance.

[libclang] check that the cursor is declaration before trying to evaluate the cursor like a declaration
ClosedPublic

Authored by arphaman on Jul 6 2018, 7:11 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman created this revision.Jul 6 2018, 7:11 PM
dexonsmith accepted this revision.Jul 9 2018, 8:25 AM

LGTM.

tools/libclang/CIndex.cpp
3892–3922 ↗(On Diff #154479)

There's unfortunate nesting here. It would be nice if, either pre-commit or post-commit, you could refactor this to be more straightline using early returns. E.g.:

static CXEvalResult evaluateDeclExpr(const Decl *D) {
  if (!D)
    return nullptr;
  // ...
}
static CXEvalResult evaluateCompoundStmtExpr(const CompoundStmt *CS) {
  if (!CS)
    return nullptr;
  // ...
}
CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
  if (clang_isDeclaration(C.kind)) {
    return evaluateDeclExpr(getCursorDecl(C));
  return evaluateCompoundStmtExpr(
      dyn_cast_or_null<CompoundStmt>(getCursorStmt(C)));
}
This revision is now accepted and ready to land.Jul 9 2018, 8:25 AM
arphaman marked an inline comment as done.Jul 9 2018, 11:41 AM
arphaman added inline comments.
tools/libclang/CIndex.cpp
3892–3922 ↗(On Diff #154479)

Thanks, will do post commit.

This revision was automatically updated to reflect the committed changes.
arphaman marked an inline comment as done.