Sema.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file was developed by Chris Lattner and is distributed under
  6. // the University of Illinois Open Source License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the actions class which performs semantic analysis and
  11. // builds an AST out of a parse stream.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "Sema.h"
  15. #include "clang/AST/ASTContext.h"
  16. #include "clang/Lex/Preprocessor.h"
  17. #include "clang/Basic/Diagnostic.h"
  18. using namespace clang;
  19. Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
  20. : PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
  21. }
  22. //===----------------------------------------------------------------------===//
  23. // Helper functions.
  24. //===----------------------------------------------------------------------===//
  25. bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
  26. PP.getDiagnostics().Report(Loc, DiagID);
  27. return true;
  28. }
  29. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
  30. PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1);
  31. return true;
  32. }
  33. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
  34. const std::string &Msg2) {
  35. std::string MsgArr[] = { Msg1, Msg2 };
  36. PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2);
  37. return true;
  38. }
  39. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
  40. PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
  41. return true;
  42. }
  43. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
  44. SourceRange Range) {
  45. PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, &Range, 1);
  46. return true;
  47. }
  48. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
  49. const std::string &Msg2, SourceRange Range) {
  50. std::string MsgArr[] = { Msg1, Msg2 };
  51. PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2, &Range, 1);
  52. return true;
  53. }
  54. bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
  55. SourceRange R1, SourceRange R2) {
  56. SourceRange RangeArr[] = { R1, R2 };
  57. PP.getDiagnostics().Report(Loc, DiagID, 0, 0, RangeArr, 2);
  58. return true;
  59. }
  60. bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
  61. SourceRange R1, SourceRange R2) {
  62. SourceRange RangeArr[] = { R1, R2 };
  63. PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, RangeArr, 2);
  64. return true;
  65. }
  66. bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
  67. const std::string &Msg2, SourceRange R1, SourceRange R2) {
  68. std::string MsgArr[] = { Msg1, Msg2 };
  69. SourceRange RangeArr[] = { R1, R2 };
  70. PP.getDiagnostics().Report(Range, DiagID, MsgArr, 2, RangeArr, 2);
  71. return true;
  72. }
  73. const LangOptions &Sema::getLangOptions() const {
  74. return PP.getLangOptions();
  75. }