Source.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //===--- Source.cpp - Source expression tracking ----------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "Source.h"
  9. #include "clang/AST/Expr.h"
  10. using namespace clang;
  11. using namespace clang::interp;
  12. SourceLocation SourceInfo::getLoc() const {
  13. if (const Expr *E = asExpr())
  14. return E->getExprLoc();
  15. if (const Stmt *S = asStmt())
  16. return S->getBeginLoc();
  17. if (const Decl *D = asDecl())
  18. return D->getBeginLoc();
  19. return SourceLocation();
  20. }
  21. const Expr *SourceInfo::asExpr() const {
  22. if (auto *S = Source.dyn_cast<const Stmt *>())
  23. return dyn_cast<Expr>(S);
  24. return nullptr;
  25. }
  26. const Expr *SourceMapper::getExpr(Function *F, CodePtr PC) const {
  27. if (const Expr *E = getSource(F, PC).asExpr())
  28. return E;
  29. llvm::report_fatal_error("missing source expression");
  30. }
  31. SourceLocation SourceMapper::getLocation(Function *F, CodePtr PC) const {
  32. return getSource(F, PC).getLoc();
  33. }