blob: 64c18a80c0e41f34e98ca2de0cc8c7b349689715 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- 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
15#include "Sema.h"
16#include "clang/AST/ASTContext.h"
17#include "clang/Lex/Preprocessor.h"
18#include "clang/Basic/Diagnostic.h"
19using namespace clang;
20
21Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
22 : PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
23}
24
25//===----------------------------------------------------------------------===//
26// Helper functions.
27//===----------------------------------------------------------------------===//
28
29bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
30 PP.getDiagnostics().Report(Loc, DiagID);
31 return true;
32}
33
34bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
35 PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1);
36 return true;
37}
38
39bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
40 const std::string &Msg2) {
41 std::string MsgArr[] = { Msg1, Msg2 };
42 PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2);
43 return true;
44}
45
46bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
47 PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
48 return true;
49}
50
51bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
52 SourceRange Range) {
53 PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, &Range, 1);
54 return true;
55}
56
57bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
58 const std::string &Msg2, SourceRange Range) {
59 std::string MsgArr[] = { Msg1, Msg2 };
60 PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2, &Range, 1);
61 return true;
62}
63
64bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
65 SourceRange R1, SourceRange R2) {
66 SourceRange RangeArr[] = { R1, R2 };
67 PP.getDiagnostics().Report(Loc, DiagID, 0, 0, RangeArr, 2);
68 return true;
69}
70
71bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
72 SourceRange R1, SourceRange R2) {
73 SourceRange RangeArr[] = { R1, R2 };
74 PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, RangeArr, 2);
75 return true;
76}
77
78bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
79 const std::string &Msg2, SourceRange R1, SourceRange R2) {
80 std::string MsgArr[] = { Msg1, Msg2 };
81 SourceRange RangeArr[] = { R1, R2 };
82 PP.getDiagnostics().Report(Range, DiagID, MsgArr, 2, RangeArr, 2);
83 return true;
84}
85
86const LangOptions &Sema::getLangOptions() const {
87 return PP.getLangOptions();
88}