2012-04-14 08:33:13 +08:00
|
|
|
//===--- SemaStmtAttr.cpp - Statement Attribute Handling ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements stmt-related attribute processing.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Sema/SemaInternal.h"
|
|
|
|
#include "TargetAttributesSema.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
2012-05-04 02:27:39 +08:00
|
|
|
#include "clang/Lex/Lexer.h"
|
2012-04-14 08:33:13 +08:00
|
|
|
#include "clang/Sema/DelayedDiagnostic.h"
|
|
|
|
#include "clang/Sema/Lookup.h"
|
2012-05-04 02:27:39 +08:00
|
|
|
#include "clang/Sema/ScopeInfo.h"
|
2012-04-14 08:33:13 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2012-05-04 02:27:39 +08:00
|
|
|
|
2012-04-14 08:33:13 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace sema;
|
|
|
|
|
2012-05-04 02:27:39 +08:00
|
|
|
static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const AttributeList &A,
|
|
|
|
SourceRange Range) {
|
|
|
|
if (!isa<NullStmt>(St)) {
|
|
|
|
S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
|
|
|
|
<< St->getLocStart();
|
|
|
|
if (isa<SwitchCase>(St)) {
|
|
|
|
SourceLocation L = Lexer::getLocForEndOfToken(Range.getEnd(), 0,
|
|
|
|
S.getSourceManager(), S.getLangOpts());
|
|
|
|
S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
|
|
|
|
<< FixItHint::CreateInsertion(L, ";");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (S.getCurFunction()->SwitchStack.empty()) {
|
|
|
|
S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ::new (S.Context) FallThroughAttr(A.getRange(), S.Context);
|
|
|
|
}
|
|
|
|
|
2012-04-14 08:33:13 +08:00
|
|
|
|
2012-05-04 02:27:39 +08:00
|
|
|
static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A,
|
|
|
|
SourceRange Range) {
|
2012-04-14 08:33:13 +08:00
|
|
|
switch (A.getKind()) {
|
2012-10-03 09:56:22 +08:00
|
|
|
case AttributeList::UnknownAttribute:
|
|
|
|
S.Diag(A.getLoc(), A.isDeclspecAttribute() ?
|
|
|
|
diag::warn_unhandled_ms_attribute_ignored :
|
|
|
|
diag::warn_unknown_attribute_ignored) << A.getName();
|
|
|
|
return 0;
|
2012-06-20 07:57:03 +08:00
|
|
|
case AttributeList::AT_FallThrough:
|
2012-05-04 02:27:39 +08:00
|
|
|
return handleFallThroughAttr(S, St, A, Range);
|
2012-04-14 08:33:13 +08:00
|
|
|
default:
|
2012-10-03 09:56:22 +08:00
|
|
|
// if we're here, then we parsed a known attribute, but didn't recognize
|
|
|
|
// it as a statement attribute => it is declaration attribute
|
2012-05-04 02:27:39 +08:00
|
|
|
S.Diag(A.getRange().getBegin(), diag::warn_attribute_invalid_on_stmt)
|
|
|
|
<< A.getName()->getName() << St->getLocStart();
|
2012-04-14 08:33:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StmtResult Sema::ProcessStmtAttributes(Stmt *S, AttributeList *AttrList,
|
|
|
|
SourceRange Range) {
|
2012-07-09 18:04:07 +08:00
|
|
|
SmallVector<const Attr*, 8> Attrs;
|
2012-04-14 08:33:13 +08:00
|
|
|
for (const AttributeList* l = AttrList; l; l = l->getNext()) {
|
2012-05-04 02:27:39 +08:00
|
|
|
if (Attr *a = ProcessStmtAttribute(*this, S, *l, Range))
|
2012-04-14 08:33:13 +08:00
|
|
|
Attrs.push_back(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Attrs.empty())
|
|
|
|
return S;
|
|
|
|
|
|
|
|
return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
|
|
|
|
}
|