Monday 1 June 2020

LLVM/clang

build できるようになったので debug中。いや、あんまり言いたくないけど、

  学生がいないのではかどる

というところがあるかも知れない。

LLVMは C++ で書かれていて、clang はC++のobjectを作っていくわけですが、中身がみれないって問題が。しかし、ぐぐってたら

  std::string get_string(const Expr *expr, const ASTContext &Context) {
   PrintingPolicy print_policy(Context.getLangOpts());
   print_policy.FullyQualifiedName = 1;
   print_policy.SuppressScope = 0;
   print_policy.SuppressUnwrittenScope = 0;
   std::string expr_string;
   llvm::raw_string_ostream stream(expr_string);
   expr->printPretty(stream, nullptr, print_policy);
   stream.flush();
   return expr_string;
  }

とすれば良いと。お、ばっちり。

  (lldb) p get_string(E.get(),Actions.getASTContext())
  (std::__1::string) $2 = "__builtin_longjmp"

どうも、tok::annot_non_type ってのが builtin とか用に追加されたらしく、それは扱いを変えないとだめらしい。

 Sema::NameClassification Classification = Actions.ClassifyName(getCurScope(), SS, II, Loc, Next, &CCCValidator);
 setExprAnnotation(IITok, Classification.getExpression());

ではなくて

 Sema::NameClassification Classification = Actions.ClassifyName(getCurScope(), SS, II, Loc, Next, &CCCValidator);
 setNonTypeAnnotation(IITok, Classification.getNonTypeDecl());
 setExprAnnotation(IITok, Actions.ActOnNameClassifiedAsNonType(getCurScope(), SS, ND, Loc, IITok));

とかするらしい。いろいろ謎だ。

No comments: