blob: 64c18a80c0e41f34e98ca2de0cc8c7b349689715 [file] [log] [blame]
Chris Lattnerddd6fc82006-11-10 04:58:55 +00001//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===//
Chris Lattner3e7bd4e2006-08-17 05:51:27 +00002//
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//
Chris Lattnerddd6fc82006-11-10 04:58:55 +000010// This file implements the actions class which performs semantic analysis and
11// builds an AST out of a parse stream.
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnerddd6fc82006-11-10 04:58:55 +000015#include "Sema.h"
Chris Lattnercb6a3822006-11-10 06:20:45 +000016#include "clang/AST/ASTContext.h"
Chris Lattnerd3e98952006-10-06 05:22:26 +000017#include "clang/Lex/Preprocessor.h"
Chris Lattnerd6647d32007-05-16 17:56:50 +000018#include "clang/Basic/Diagnostic.h"
Chris Lattnerc11438c2006-08-18 05:17:52 +000019using namespace clang;
20
Steve Naroff2c055d22007-02-28 19:32:13 +000021Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
22 : PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
Steve Naroff38d31b42007-02-28 01:22:02 +000023}
Chris Lattnercb6a3822006-11-10 06:20:45 +000024
Chris Lattnerc11438c2006-08-18 05:17:52 +000025//===----------------------------------------------------------------------===//
Chris Lattnereaafe1222006-11-10 05:17:58 +000026// Helper functions.
27//===----------------------------------------------------------------------===//
28
Chris Lattnerd6647d32007-05-16 17:56:50 +000029bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
30 PP.getDiagnostics().Report(Loc, DiagID);
31 return true;
32}
33
Steve Narofff1e53692007-03-23 22:27:02 +000034bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
Chris Lattnerd6647d32007-05-16 17:56:50 +000035 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);
Steve Narofff1e53692007-03-23 22:27:02 +000043 return true;
Chris Lattnereaafe1222006-11-10 05:17:58 +000044}
45
Steve Naroff71ce2e02007-05-18 22:53:50 +000046bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
47 PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
Steve Naroffbc2f0992007-03-30 20:09:34 +000048 return true;
49}
50
Steve Naroff71ce2e02007-05-18 22:53:50 +000051bool 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);
Steve Narofff1e53692007-03-23 22:27:02 +000083 return true;
Steve Naroff8160ea22007-03-06 01:09:46 +000084}
85
Chris Lattnerac18be92006-11-20 06:49:47 +000086const LangOptions &Sema::getLangOptions() const {
Steve Naroff38d31b42007-02-28 01:22:02 +000087 return PP.getLangOptions();
Chris Lattnerac18be92006-11-20 06:49:47 +000088}