[cfe-commits] r39456 - in /cfe/cfe/trunk: AST/Sema.cpp AST/Sema.h AST/SemaExpr.cpp Basic/Diagnostic.cpp Driver/clang.cpp Sema/Sema.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/Basic/Diagnostic.h include/clang/Basic/SourceLocation.h
Steve Naroff
snaroff at apple.com
Wed Jul 11 09:44:38 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:44:38 2007
New Revision: 39456
URL: http://llvm.org/viewvc/llvm-project?rev=39456&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
An important, but truly mind numbing change.
Added 6 flavors of Sema::Diag() that take 1 or two SourceRanges. Considered
adding 3 flavors (using default args), however this wasn't as clear.
Removed 2 flavors of Sema::Diag() that took LexerToken's (they weren't used).
Changed all the typechecking routines to pass the appropriate range(s).
Hacked the diagnostic machinery and driver to acccommodate the new data.
What's left? A FIXME in clang.c to use the ranges. Chris offered to do the
honors:-) Which includes taking us to the end of an identifier:-)
Modified:
cfe/cfe/trunk/AST/Sema.cpp
cfe/cfe/trunk/AST/Sema.h
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/Basic/Diagnostic.cpp
cfe/cfe/trunk/Driver/clang.cpp
cfe/cfe/trunk/Sema/Sema.cpp
cfe/cfe/trunk/Sema/Sema.h
cfe/cfe/trunk/Sema/SemaExpr.cpp
cfe/cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/cfe/trunk/include/clang/Basic/SourceLocation.h
Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:44:38 2007
@@ -44,13 +44,43 @@
return true;
}
-bool Sema::Diag(const LexerToken &Tok, unsigned DiagID) {
- PP.getDiagnostics().Report(Tok.getLocation(), DiagID);
+bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
+ PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
return true;
}
-bool Sema::Diag(const LexerToken &Tok, unsigned DiagID, const std::string &M) {
- PP.getDiagnostics().Report(Tok.getLocation(), DiagID, &M, 1);
+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);
return true;
}
Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:44:38 2007
@@ -55,14 +55,27 @@
const LangOptions &getLangOptions() const;
- /// always returns true, which simplifies error handling (i.e. less code).
+ /// The primitive diagnostic helpers - always returns true, which simplifies
+ /// error handling (i.e. less code).
bool Diag(SourceLocation Loc, unsigned DiagID);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2);
- bool Diag(const LexerToken &Tok, unsigned DiagID);
- bool Diag(const LexerToken &Tok, unsigned DiagID, const std::string &M);
-
+
+ /// More expressive diagnostic helpers for expressions (say that 6 times:-)
+ bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID,
+ SourceRange R1, SourceRange R2);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
+ SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
+ SourceRange R1, SourceRange R2);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
+ const std::string &Msg2, SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID,
+ const std::string &Msg1, const std::string &Msg2,
+ SourceRange R1, SourceRange R2);
+
//===--------------------------------------------------------------------===//
// Type Analysis / Processing: SemaType.cpp.
//
@@ -279,13 +292,12 @@
Expr *cond, Expr *lhs, Expr *rhs, SourceLocation questionLoc);
/// type checking unary operators (subroutines of ParseUnaryOp).
- QualType CheckIncrementDecrementOperand(Expr *op); // C99 6.5.3.1
- QualType CheckAddressOfOperand( // C99 6.5.3.2
- Expr *op, SourceLocation loc);
- QualType CheckIndirectionOperand( // C99 6.5.3.2
- Expr *op, SourceLocation loc);
- QualType CheckSizeOfAlignOfOperand( // C99 6.5.3.4
- QualType type, SourceLocation loc, bool isSizeof);
+ // C99 6.5.3.1, 6.5.3.2, 6.5.3.4
+ QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
+ bool isSizeof);
// C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have
// a constant expression of type int with a value greater than zero.
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:44:38 2007
@@ -26,12 +26,6 @@
using namespace llvm;
using namespace clang;
-// Sema.h avoids including Expr.h. As a result, all the Check* functions take
-// an unsigned which is really an enum. These typedefs provide a short hand
-// notiation for casting (to keep the lines within 80 columns:-)
-typedef BinaryOperator::Opcode BOP;
-typedef UnaryOperator::Opcode UOP;
-
/// ParseStringLiteral - The specified tokens were lexed as pasted string
/// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle string
/// concatenation ([C99 5.1.1.2, translation phase #6]), so it may come from
@@ -220,7 +214,7 @@
case tok::plusplus: Opc = UnaryOperator::PostInc; break;
case tok::minusminus: Opc = UnaryOperator::PostDec; break;
}
- QualType result = CheckIncrementDecrementOperand((Expr *)Input);
+ QualType result = CheckIncrementDecrementOperand((Expr *)Input, OpLoc);
if (result.isNull())
return true;
return new UnaryOperator((Expr *)Input, Opc, result, OpLoc);
@@ -642,7 +636,8 @@
if (resType->isArithmeticType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -654,7 +649,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -672,7 +668,8 @@
(lhsType->isIntegerType() && rhsType->isPointerType()))
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -689,7 +686,8 @@
(lhsType->isPointerType() && rhsType->isPointerType()))
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -701,7 +699,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -721,7 +720,8 @@
return Context.IntTy;
}
Diag(loc, diag::err_typecheck_invalid_operands,
- lType.getAsString(), rType.getAsString());
+ lType.getAsString(), rType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -740,7 +740,8 @@
return Context.IntTy;
}
Diag(loc, diag::err_typecheck_invalid_operands,
- lType.getAsString(), rType.getAsString());
+ lType.getAsString(), rType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -752,7 +753,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -765,7 +767,8 @@
if (lhsType->isScalarType() || rhsType->isScalarType())
return Context.IntTy;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -779,10 +782,10 @@
// this check is done first to give a more precise diagnostic.
// isModifiableLvalue() will also check for "const".
if (lhsType.isConstQualified()) {
- Diag(lex->getLocStart(), diag::err_typecheck_assign_const);
+ Diag(loc, diag::err_typecheck_assign_const, lex->getSourceRange());
hadError = true;
} else if (!lex->isModifiableLvalue()) { // C99 6.5.16p2
- Diag(lex->getLocStart(), diag::err_typecheck_assign_non_lvalue);
+ Diag(loc, diag::err_typecheck_assign_non_lvalue, lex->getSourceRange());
return QualType(); // no need to continue checking...
}
if (lhsType == rhsType) // common case, fast path...
@@ -797,7 +800,8 @@
break;
case Incompatible:
Diag(loc, diag::err_typecheck_assign_incompatible,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
hadError = true;
break;
case PointerFromInt:
@@ -824,27 +828,28 @@
return UsualUnaryConversion(rex->getType());
}
-QualType Sema::CheckIncrementDecrementOperand(Expr *op) {
+QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) {
QualType resType = UsualArithmeticConversions(op->getType(), Context.IntTy);
assert(!resType.isNull() && "no type for increment/decrement expression");
// C99 6.5.2.4p1
if (const PointerType *pt = dyn_cast<PointerType>(resType)) {
if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2
- Diag(op->getLocStart(), diag::err_typecheck_arithmetic_incomplete_type,
- resType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type,
+ resType.getAsString(), op->getSourceRange());
return QualType();
}
} else if (!resType->isRealType()) {
// FIXME: Allow Complex as a GCC extension.
- Diag(op->getLocStart(), diag::err_typecheck_illegal_increment_decrement,
- resType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement,
+ resType.getAsString(), op->getSourceRange());
return QualType();
}
// At this point, we know we have a real or pointer type. Now make sure
// the operand is a modifiable lvalue.
if (!op->isModifiableLvalue()) {
- Diag(op->getLocStart(), diag::err_typecheck_invalid_lvalue_incr_decr);
+ Diag(OpLoc, diag::err_typecheck_invalid_lvalue_incr_decr,
+ op->getSourceRange());
return QualType();
}
return resType;
@@ -885,7 +890,8 @@
if (dcl && isa<FunctionDecl>(dcl)) // allow function designators
;
else {
- Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof);
+ Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof,
+ op->getSourceRange());
return QualType();
}
} else if (dcl) {
@@ -893,7 +899,8 @@
// with the register storage-class specifier.
if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
if (vd->getStorageClass() == VarDecl::Register) {
- Diag(OpLoc, diag::err_typecheck_address_of_register);
+ Diag(OpLoc, diag::err_typecheck_address_of_register,
+ op->getSourceRange());
return QualType();
}
} else
@@ -912,7 +919,8 @@
if (PointerType *PT = dyn_cast<PointerType>(qType))
return PT->getPointeeType();
- Diag(OpLoc, diag::err_typecheck_unary_expr, qType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_unary_expr, qType.getAsString(),
+ op->getSourceRange());
return QualType();
}
@@ -1090,7 +1098,7 @@
assert(0 && "Unimplemented unary expr!");
case UnaryOperator::PreInc:
case UnaryOperator::PreDec:
- resultType = CheckIncrementDecrementOperand((Expr *)Input);
+ resultType = CheckIncrementDecrementOperand((Expr *)Input, OpLoc);
break;
case UnaryOperator::AddrOf:
resultType = CheckAddressOfOperand((Expr *)Input, OpLoc);
Modified: cfe/cfe/trunk/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/Diagnostic.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/cfe/trunk/Basic/Diagnostic.cpp Wed Jul 11 11:44:38 2007
@@ -117,7 +117,8 @@
/// compilation, return true, otherwise return false. DiagID is a member of
/// the diag::kind enum.
void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
- const std::string *Strs, unsigned NumStrs) {
+ const std::string *Strs, unsigned NumStrs,
+ SourceRange *Ranges, unsigned NumRanges) {
// Figure out the diagnostic level of this message.
Diagnostic::Level DiagLevel = getDiagnosticLevel(DiagID);
@@ -126,7 +127,8 @@
return;
// Finally, report it.
- Client.HandleDiagnostic(DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs);
+ Client.HandleDiagnostic(DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs,
+ Ranges, NumRanges);
}
DiagnosticClient::~DiagnosticClient() {}
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:38 2007
@@ -345,10 +345,10 @@
void PrintIncludeStack(SourceLocation Pos);
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
- SourceLocation Pos,
+ virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, SourceLocation Pos,
diag::kind ID, const std::string *Strs,
- unsigned NumStrs);
+ unsigned NumStrs, SourceRange *Ranges,
+ unsigned NumRanges);
};
void DiagnosticPrinterSTDERR::
@@ -371,7 +371,9 @@
SourceLocation Pos,
diag::kind ID,
const std::string *Strs,
- unsigned NumStrs) {
+ unsigned NumStrs,
+ SourceRange *Ranges,
+ unsigned NumRanges) {
unsigned LineNo = 0, FilePos = 0, FileID = 0, ColNo = 0;
unsigned LineStart = 0, LineEnd = 0;
const MemoryBuffer *Buffer = 0;
@@ -457,7 +459,8 @@
for (unsigned i = LineStart; i != FilePos; ++i)
if (Buf[i] == '\t')
Indent[i-LineStart] = '\t';
-
+
+ // FIXME: if (NumRanges) use Ranges to output fancy highlighting
// Print out the caret itself.
std::cerr << Indent << "^\n";
}
@@ -465,7 +468,6 @@
++NumDiagnostics;
}
-
//===----------------------------------------------------------------------===//
// Preprocessor Initialization
//===----------------------------------------------------------------------===//
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:44:38 2007
@@ -44,13 +44,43 @@
return true;
}
-bool Sema::Diag(const LexerToken &Tok, unsigned DiagID) {
- PP.getDiagnostics().Report(Tok.getLocation(), DiagID);
+bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
+ PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
return true;
}
-bool Sema::Diag(const LexerToken &Tok, unsigned DiagID, const std::string &M) {
- PP.getDiagnostics().Report(Tok.getLocation(), DiagID, &M, 1);
+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);
return true;
}
Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:44:38 2007
@@ -55,14 +55,27 @@
const LangOptions &getLangOptions() const;
- /// always returns true, which simplifies error handling (i.e. less code).
+ /// The primitive diagnostic helpers - always returns true, which simplifies
+ /// error handling (i.e. less code).
bool Diag(SourceLocation Loc, unsigned DiagID);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2);
- bool Diag(const LexerToken &Tok, unsigned DiagID);
- bool Diag(const LexerToken &Tok, unsigned DiagID, const std::string &M);
-
+
+ /// More expressive diagnostic helpers for expressions (say that 6 times:-)
+ bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID,
+ SourceRange R1, SourceRange R2);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
+ SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
+ SourceRange R1, SourceRange R2);
+ bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
+ const std::string &Msg2, SourceRange R1);
+ bool Diag(SourceLocation Loc, unsigned DiagID,
+ const std::string &Msg1, const std::string &Msg2,
+ SourceRange R1, SourceRange R2);
+
//===--------------------------------------------------------------------===//
// Type Analysis / Processing: SemaType.cpp.
//
@@ -279,13 +292,12 @@
Expr *cond, Expr *lhs, Expr *rhs, SourceLocation questionLoc);
/// type checking unary operators (subroutines of ParseUnaryOp).
- QualType CheckIncrementDecrementOperand(Expr *op); // C99 6.5.3.1
- QualType CheckAddressOfOperand( // C99 6.5.3.2
- Expr *op, SourceLocation loc);
- QualType CheckIndirectionOperand( // C99 6.5.3.2
- Expr *op, SourceLocation loc);
- QualType CheckSizeOfAlignOfOperand( // C99 6.5.3.4
- QualType type, SourceLocation loc, bool isSizeof);
+ // C99 6.5.3.1, 6.5.3.2, 6.5.3.4
+ QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
+ QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
+ bool isSizeof);
// C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have
// a constant expression of type int with a value greater than zero.
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:44:38 2007
@@ -26,12 +26,6 @@
using namespace llvm;
using namespace clang;
-// Sema.h avoids including Expr.h. As a result, all the Check* functions take
-// an unsigned which is really an enum. These typedefs provide a short hand
-// notiation for casting (to keep the lines within 80 columns:-)
-typedef BinaryOperator::Opcode BOP;
-typedef UnaryOperator::Opcode UOP;
-
/// ParseStringLiteral - The specified tokens were lexed as pasted string
/// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle string
/// concatenation ([C99 5.1.1.2, translation phase #6]), so it may come from
@@ -220,7 +214,7 @@
case tok::plusplus: Opc = UnaryOperator::PostInc; break;
case tok::minusminus: Opc = UnaryOperator::PostDec; break;
}
- QualType result = CheckIncrementDecrementOperand((Expr *)Input);
+ QualType result = CheckIncrementDecrementOperand((Expr *)Input, OpLoc);
if (result.isNull())
return true;
return new UnaryOperator((Expr *)Input, Opc, result, OpLoc);
@@ -642,7 +636,8 @@
if (resType->isArithmeticType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -654,7 +649,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -672,7 +668,8 @@
(lhsType->isIntegerType() && rhsType->isPointerType()))
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -689,7 +686,8 @@
(lhsType->isPointerType() && rhsType->isPointerType()))
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -701,7 +699,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -721,7 +720,8 @@
return Context.IntTy;
}
Diag(loc, diag::err_typecheck_invalid_operands,
- lType.getAsString(), rType.getAsString());
+ lType.getAsString(), rType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -740,7 +740,8 @@
return Context.IntTy;
}
Diag(loc, diag::err_typecheck_invalid_operands,
- lType.getAsString(), rType.getAsString());
+ lType.getAsString(), rType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -752,7 +753,8 @@
if (resType->isIntegerType())
return resType;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -765,7 +767,8 @@
if (lhsType->isScalarType() || rhsType->isScalarType())
return Context.IntTy;
Diag(loc, diag::err_typecheck_invalid_operands,
- lex->getType().getAsString(), rex->getType().getAsString());
+ lex->getType().getAsString(), rex->getType().getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
return QualType();
}
@@ -779,10 +782,10 @@
// this check is done first to give a more precise diagnostic.
// isModifiableLvalue() will also check for "const".
if (lhsType.isConstQualified()) {
- Diag(lex->getLocStart(), diag::err_typecheck_assign_const);
+ Diag(loc, diag::err_typecheck_assign_const, lex->getSourceRange());
hadError = true;
} else if (!lex->isModifiableLvalue()) { // C99 6.5.16p2
- Diag(lex->getLocStart(), diag::err_typecheck_assign_non_lvalue);
+ Diag(loc, diag::err_typecheck_assign_non_lvalue, lex->getSourceRange());
return QualType(); // no need to continue checking...
}
if (lhsType == rhsType) // common case, fast path...
@@ -797,7 +800,8 @@
break;
case Incompatible:
Diag(loc, diag::err_typecheck_assign_incompatible,
- lhsType.getAsString(), rhsType.getAsString());
+ lhsType.getAsString(), rhsType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
hadError = true;
break;
case PointerFromInt:
@@ -824,27 +828,28 @@
return UsualUnaryConversion(rex->getType());
}
-QualType Sema::CheckIncrementDecrementOperand(Expr *op) {
+QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) {
QualType resType = UsualArithmeticConversions(op->getType(), Context.IntTy);
assert(!resType.isNull() && "no type for increment/decrement expression");
// C99 6.5.2.4p1
if (const PointerType *pt = dyn_cast<PointerType>(resType)) {
if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2
- Diag(op->getLocStart(), diag::err_typecheck_arithmetic_incomplete_type,
- resType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type,
+ resType.getAsString(), op->getSourceRange());
return QualType();
}
} else if (!resType->isRealType()) {
// FIXME: Allow Complex as a GCC extension.
- Diag(op->getLocStart(), diag::err_typecheck_illegal_increment_decrement,
- resType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement,
+ resType.getAsString(), op->getSourceRange());
return QualType();
}
// At this point, we know we have a real or pointer type. Now make sure
// the operand is a modifiable lvalue.
if (!op->isModifiableLvalue()) {
- Diag(op->getLocStart(), diag::err_typecheck_invalid_lvalue_incr_decr);
+ Diag(OpLoc, diag::err_typecheck_invalid_lvalue_incr_decr,
+ op->getSourceRange());
return QualType();
}
return resType;
@@ -885,7 +890,8 @@
if (dcl && isa<FunctionDecl>(dcl)) // allow function designators
;
else {
- Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof);
+ Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof,
+ op->getSourceRange());
return QualType();
}
} else if (dcl) {
@@ -893,7 +899,8 @@
// with the register storage-class specifier.
if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
if (vd->getStorageClass() == VarDecl::Register) {
- Diag(OpLoc, diag::err_typecheck_address_of_register);
+ Diag(OpLoc, diag::err_typecheck_address_of_register,
+ op->getSourceRange());
return QualType();
}
} else
@@ -912,7 +919,8 @@
if (PointerType *PT = dyn_cast<PointerType>(qType))
return PT->getPointeeType();
- Diag(OpLoc, diag::err_typecheck_unary_expr, qType.getAsString());
+ Diag(OpLoc, diag::err_typecheck_unary_expr, qType.getAsString(),
+ op->getSourceRange());
return QualType();
}
@@ -1090,7 +1098,7 @@
assert(0 && "Unimplemented unary expr!");
case UnaryOperator::PreInc:
case UnaryOperator::PreDec:
- resultType = CheckIncrementDecrementOperand((Expr *)Input);
+ resultType = CheckIncrementDecrementOperand((Expr *)Input, OpLoc);
break;
case UnaryOperator::AddrOf:
resultType = CheckAddressOfOperand((Expr *)Input, OpLoc);
Modified: cfe/cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jul 11 11:44:38 2007
@@ -20,6 +20,7 @@
namespace clang {
class DiagnosticClient;
class SourceLocation;
+ class SourceRange;
// Import the diagnostic enums themselves.
namespace diag {
@@ -118,7 +119,8 @@
/// Report - Issue the message to the client. DiagID is a member of the
/// diag::kind enum.
void Report(SourceLocation Pos, unsigned DiagID,
- const std::string *Strs = 0, unsigned NumStrs = 0);
+ const std::string *Strs = 0, unsigned NumStrs = 0,
+ SourceRange *Ranges = 0, unsigned NumRanges = 0);
};
/// DiagnosticClient - This is an abstract interface implemented by clients of
@@ -132,7 +134,8 @@
/// capturing it to a log as needed.
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, SourceLocation Pos,
diag::kind ID, const std::string *Strs,
- unsigned NumStrs) = 0;
+ unsigned NumStrs, SourceRange *Ranges,
+ unsigned NumRanges) = 0;
};
} // end namespace clang
Modified: cfe/cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=39456&r1=39455&r2=39456&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceLocation.h Wed Jul 11 11:44:38 2007
@@ -94,11 +94,14 @@
SourceLocation B;
SourceLocation E;
public:
+ SourceRange(): B(SourceLocation()), E(SourceLocation()) {}
SourceRange(SourceLocation loc) : B(loc), E(loc) {}
SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
SourceLocation Begin() const { return B; }
SourceLocation End() const { return E; }
+
+ bool isValid() const { return B.isValid() && E.isValid(); }
};
} // end namespace clang
More information about the cfe-commits
mailing list