2006-11-10 04:58:55 +00:00
|
|
|
//===--- Sema.cpp - AST Builder and Semantic Analysis Implementation ------===//
|
2006-08-17 05:51:27 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-11-10 04:58:55 +00:00
|
|
|
// This file implements the actions class which performs semantic analysis and
|
|
|
|
// builds an AST out of a parse stream.
|
2006-08-17 05:51:27 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-11-10 04:58:55 +00:00
|
|
|
#include "Sema.h"
|
2006-11-10 06:20:45 +00:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2006-10-06 05:22:26 +00:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2007-05-16 17:56:50 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2006-08-18 05:17:52 +00:00
|
|
|
using namespace clang;
|
|
|
|
|
2007-02-28 19:32:13 +00:00
|
|
|
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
|
|
|
|
: PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
|
2007-02-28 01:22:02 +00:00
|
|
|
}
|
2006-11-10 06:20:45 +00:00
|
|
|
|
2006-11-10 05:17:58 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helper functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-05-16 17:56:50 +00:00
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-23 22:27:02 +00:00
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
|
2007-05-16 17:56:50 +00:00
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
|
|
|
|
const std::string &Msg2) {
|
|
|
|
std::string MsgArr[] = { Msg1, Msg2 };
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2);
|
2007-03-23 22:27:02 +00:00
|
|
|
return true;
|
2006-11-10 05:17:58 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 22:53:50 +00:00
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
|
2007-03-30 20:09:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-18 22:53:50 +00:00
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
|
|
|
|
SourceRange Range) {
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, &Range, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
|
|
|
|
const std::string &Msg2, SourceRange Range) {
|
|
|
|
std::string MsgArr[] = { Msg1, Msg2 };
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2, &Range, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
|
|
|
|
SourceRange R1, SourceRange R2) {
|
|
|
|
SourceRange RangeArr[] = { R1, R2 };
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, 0, 0, RangeArr, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
|
|
|
|
SourceRange R1, SourceRange R2) {
|
|
|
|
SourceRange RangeArr[] = { R1, R2 };
|
|
|
|
PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, RangeArr, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
|
|
|
|
const std::string &Msg2, SourceRange R1, SourceRange R2) {
|
|
|
|
std::string MsgArr[] = { Msg1, Msg2 };
|
|
|
|
SourceRange RangeArr[] = { R1, R2 };
|
|
|
|
PP.getDiagnostics().Report(Range, DiagID, MsgArr, 2, RangeArr, 2);
|
2007-03-23 22:27:02 +00:00
|
|
|
return true;
|
2007-03-06 01:09:46 +00:00
|
|
|
}
|
|
|
|
|
2006-11-20 06:49:47 +00:00
|
|
|
const LangOptions &Sema::getLangOptions() const {
|
2007-02-28 01:22:02 +00:00
|
|
|
return PP.getLangOptions();
|
2006-11-20 06:49:47 +00:00
|
|
|
}
|