[cfe-commits] r39374 - in /cfe/cfe/trunk: AST/ASTContext.cpp AST/SemaExpr.cpp AST/Stmt.cpp Sema/SemaExpr.cpp include/clang/AST/ASTContext.h include/clang/AST/Expr.h include/clang/Basic/DiagnosticKinds.def
Steve Naroff
snaroff at apple.com
Wed Jul 11 09:43:44 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:43:44 2007
New Revision: 39374
URL: http://llvm.org/viewvc/llvm-project?rev=39374&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Incorporate code review feedback from Chris...
- minor restructure of ParseMemberReferenceExpr logic. The last statement
is now the instantiation of the AST node (which I like a lot and will conform
to throughout Sema).
- declare StmtClassNameTable const.
- reword an error diagnostic.
- install the correct type for ParseSizeOfAlignOfTypeExpr. Added hook in
ASTContext. For now, simply return Context.UnsignedLongTy. Added a FIXME
to revisit (i.e. compute using TargetInfo).
Modified:
cfe/cfe/trunk/AST/ASTContext.cpp
cfe/cfe/trunk/AST/SemaExpr.cpp
cfe/cfe/trunk/AST/Stmt.cpp
cfe/cfe/trunk/Sema/SemaExpr.cpp
cfe/cfe/trunk/include/clang/AST/ASTContext.h
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:43:44 2007
@@ -286,4 +286,12 @@
return Decl->TypeForDecl;
}
+/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result
+/// of the sizeof operator (C99 6.5.3.4p4). The value to target dependent and
+/// needs to agree with the definition in <stddef.h>.
+TypeRef ASTContext::getSizeType() {
+ // On Darwin, size_t is defined as a "long unsigned int".
+ // FIXME: should derive from "Target".
+ return UnsignedLongTy;
+}
Modified: cfe/cfe/trunk/AST/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaExpr.cpp?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/AST/SemaExpr.cpp Wed Jul 11 11:43:44 2007
@@ -68,10 +68,11 @@
// Not in C++.
!getLangOptions().CPlusPlus)
D = ImplicitlyDefineFunction(Loc, II, S);
- else
+ else {
// If this name wasn't predeclared and if this is not a function call,
// diagnose the problem.
return Diag(Loc, diag::err_undeclared_var_use, II.getName());
+ }
}
if (ObjectDecl *OD = dyn_cast<ObjectDecl>(D)) {
@@ -203,8 +204,8 @@
diag::err_alignof_incomplete_type, TypeName);
return new IntegerLiteral(0, Context.IntTy);
}
-
- return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, Context.IntTy);
+ // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+ return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, Context.getSizeType());
}
@@ -275,23 +276,24 @@
if (OpKind == tok::arrow) {
if (PointerType *PT = dyn_cast<PointerType>(canonType)) {
qualifiedType = PT->getPointeeType();
- canonType = qualifiedType->getCanonicalType();
+ canonType = qualifiedType->getCanonicalType();
} else
return Diag(OpLoc, diag::err_typecheck_member_reference_arrow);
}
- if (isa<RecordType>(canonType)) {
- // get the struct/union definition from the type.
- RecordDecl *RD = cast<RecordType>(canonType)->getDecl();
+ if (!isa<RecordType>(canonType))
+ return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion);
+
+ // get the struct/union definition from the type.
+ RecordDecl *RD = cast<RecordType>(canonType)->getDecl();
- if (canonType->isIncompleteType())
- return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RD->getName());
+ if (canonType->isIncompleteType())
+ return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RD->getName());
- if (FieldDecl *MemberDecl = RD->getMember(&Member))
- return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
- else
- return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName());
- }
- return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion);
+ FieldDecl *MemberDecl = RD->getMember(&Member);
+ if (!MemberDecl)
+ return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName());
+
+ return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
}
/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
Modified: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:43:44 2007
@@ -24,7 +24,7 @@
STMT(0, Stmt, )
#include "clang/AST/StmtNodes.def"
-static struct StmtClassNameTable {
+static const struct StmtClassNameTable {
int enumValue;
const char *className;
} sNames[] = {
Modified: cfe/cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaExpr.cpp?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:43:44 2007
@@ -68,10 +68,11 @@
// Not in C++.
!getLangOptions().CPlusPlus)
D = ImplicitlyDefineFunction(Loc, II, S);
- else
+ else {
// If this name wasn't predeclared and if this is not a function call,
// diagnose the problem.
return Diag(Loc, diag::err_undeclared_var_use, II.getName());
+ }
}
if (ObjectDecl *OD = dyn_cast<ObjectDecl>(D)) {
@@ -203,8 +204,8 @@
diag::err_alignof_incomplete_type, TypeName);
return new IntegerLiteral(0, Context.IntTy);
}
-
- return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, Context.IntTy);
+ // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+ return new SizeOfAlignOfTypeExpr(isSizeof, ArgTy, Context.getSizeType());
}
@@ -275,23 +276,24 @@
if (OpKind == tok::arrow) {
if (PointerType *PT = dyn_cast<PointerType>(canonType)) {
qualifiedType = PT->getPointeeType();
- canonType = qualifiedType->getCanonicalType();
+ canonType = qualifiedType->getCanonicalType();
} else
return Diag(OpLoc, diag::err_typecheck_member_reference_arrow);
}
- if (isa<RecordType>(canonType)) {
- // get the struct/union definition from the type.
- RecordDecl *RD = cast<RecordType>(canonType)->getDecl();
+ if (!isa<RecordType>(canonType))
+ return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion);
+
+ // get the struct/union definition from the type.
+ RecordDecl *RD = cast<RecordType>(canonType)->getDecl();
- if (canonType->isIncompleteType())
- return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RD->getName());
+ if (canonType->isIncompleteType())
+ return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RD->getName());
- if (FieldDecl *MemberDecl = RD->getMember(&Member))
- return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
- else
- return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName());
- }
- return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion);
+ FieldDecl *MemberDecl = RD->getMember(&Member);
+ if (!MemberDecl)
+ return Diag(OpLoc, diag::err_typecheck_no_member, Member.getName());
+
+ return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
}
/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
Modified: cfe/cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ASTContext.h?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:43:44 2007
@@ -53,7 +53,6 @@
void PrintStats() const;
-
/// getPointerType - Return the uniqued reference to the type for a pointer to
/// the specified type.
TypeRef getPointerType(TypeRef T);
@@ -80,6 +79,9 @@
/// specified TagDecl (struct/union/class/enum) decl.
TypeRef getTagDeclType(TagDecl *Decl);
+ /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
+ /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4).
+ TypeRef getSizeType();
private:
void InitBuiltinTypes();
void InitBuiltinType(TypeRef &R, BuiltinType::Kind K);
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:43:44 2007
@@ -57,7 +57,7 @@
public:
DeclRefExpr(ObjectDecl *d) : Expr(DeclRefExprClass, d->getType()), D(d) {}
- Decl *getDecl() const { return D; }
+ ObjectDecl *getDecl() const { return D; }
virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39374&r1=39373&r2=39374&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:43:44 2007
@@ -491,7 +491,7 @@
DIAG(err_typecheck_subscript_not_object, ERROR,
"illegal subscript of non-object type '%s'")
DIAG(err_typecheck_member_reference_structUnion, ERROR,
- "member reference is not a structure or union")
+ "member reference is not to a structure or union")
DIAG(err_typecheck_member_reference_arrow, ERROR,
"member reference is not a pointer")
DIAG(err_typecheck_incomplete_tag, ERROR,
More information about the cfe-commits
mailing list