[cfe-commits] r63258 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp SemaInit.cpp
Douglas Gregor
dgregor at apple.com
Wed Jan 28 16:45:40 PST 2009
Author: dgregor
Date: Wed Jan 28 18:45:39 2009
New Revision: 63258
URL: http://llvm.org/viewvc/llvm-project?rev=63258&view=rev
Log:
Move InitListChecker out of Sema.h
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=63258&r1=63257&r2=63258&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Jan 28 18:45:39 2009
@@ -19,7 +19,6 @@
#include "CXXFieldCollector.h"
#include "SemaOverload.h"
#include "clang/AST/DeclBase.h"
-#include "clang/AST/Expr.h"
#include "clang/Parse/Action.h"
#include "clang/Basic/DiagnosticSema.h"
#include "llvm/ADT/SmallVector.h"
@@ -28,7 +27,6 @@
#include "llvm/ADT/OwningPtr.h"
#include <string>
#include <vector>
-#include <map>
namespace llvm {
class APSInt;
@@ -1720,6 +1718,7 @@
bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
SourceLocation InitLoc,DeclarationName InitEntity,
bool DirectInit);
+ bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
bool CheckSingleInitializer(Expr *&simpleInit, QualType declType,
bool DirectInit);
bool CheckForConstantInitializer(Expr *e, QualType t);
@@ -1835,73 +1834,6 @@
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
};
-class InitListChecker {
- Sema *SemaRef;
- bool hadError;
- std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
- InitListExpr *FullyStructuredList;
-
- void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
- unsigned &Index, InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckExplicitInitList(InitListExpr *IList, QualType &T,
- unsigned &Index, InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
- bool SubobjectIsDesignatorContext,
- unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckSubElementType(InitListExpr *IList, QualType ElemType,
- unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- // FIXME: Does DeclType need to be a reference type?
- void CheckScalarType(InitListExpr *IList, QualType &DeclType,
- unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
- RecordDecl::field_iterator Field,
- bool SubobjectIsDesignatorContext, unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- void CheckArrayType(InitListExpr *IList, QualType &DeclType,
- llvm::APSInt elementIndex,
- bool SubobjectIsDesignatorContext, unsigned &Index,
- InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex);
- bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE,
- DesignatedInitExpr::designators_iterator D,
- QualType &CurrentObjectType,
- RecordDecl::field_iterator *NextField,
- llvm::APSInt *NextElementIndex,
- unsigned &Index,
- InitListExpr *StructuredList,
- unsigned &StructuredIndex,
- bool FinishSubobjectInit = true);
- InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
- QualType CurrentObjectType,
- InitListExpr *StructuredList,
- unsigned StructuredIndex,
- SourceRange InitRange);
- void UpdateStructuredListElement(InitListExpr *StructuredInitList,
- unsigned &StructuredInitIndex,
- Expr *expr);
- int numArrayElements(QualType DeclType);
- int numStructUnionElements(QualType DeclType);
-public:
- InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
- bool HadError() { return hadError; }
-
- // @brief Retrieves the fully-structured initializer list used for
- // semantic analysis and code generation.
- InitListExpr *getFullyStructuredList() const { return FullyStructuredList; }
-};
-
/// BlockSemaInfo - When a block is being parsed, this contains information
/// about the block. It is pointed to from Sema::CurBlock.
struct BlockSemaInfo {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=63258&r1=63257&r2=63258&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan 28 18:45:39 2009
@@ -1150,11 +1150,9 @@
}
}
- InitListChecker CheckInitList(this, InitList, DeclType);
- if (!CheckInitList.HadError())
- Init = CheckInitList.getFullyStructuredList();
-
- return CheckInitList.HadError();
+ bool hadError = CheckInitList(InitList, DeclType);
+ Init = InitList;
+ return hadError;
}
/// GetNameForDeclarator - Determine the full declaration name for the
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=63258&r1=63257&r2=63258&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jan 28 18:45:39 2009
@@ -17,8 +17,76 @@
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/DiagnosticSema.h"
+#include <map>
using namespace clang;
+class InitListChecker {
+ Sema *SemaRef;
+ bool hadError;
+ std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
+ InitListExpr *FullyStructuredList;
+
+ void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
+ unsigned &Index, InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckExplicitInitList(InitListExpr *IList, QualType &T,
+ unsigned &Index, InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
+ bool SubobjectIsDesignatorContext,
+ unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckSubElementType(InitListExpr *IList, QualType ElemType,
+ unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ // FIXME: Does DeclType need to be a reference type?
+ void CheckScalarType(InitListExpr *IList, QualType &DeclType,
+ unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
+ RecordDecl::field_iterator Field,
+ bool SubobjectIsDesignatorContext, unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ void CheckArrayType(InitListExpr *IList, QualType &DeclType,
+ llvm::APSInt elementIndex,
+ bool SubobjectIsDesignatorContext, unsigned &Index,
+ InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex);
+ bool CheckDesignatedInitializer(InitListExpr *IList, DesignatedInitExpr *DIE,
+ DesignatedInitExpr::designators_iterator D,
+ QualType &CurrentObjectType,
+ RecordDecl::field_iterator *NextField,
+ llvm::APSInt *NextElementIndex,
+ unsigned &Index,
+ InitListExpr *StructuredList,
+ unsigned &StructuredIndex,
+ bool FinishSubobjectInit = true);
+ InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
+ QualType CurrentObjectType,
+ InitListExpr *StructuredList,
+ unsigned StructuredIndex,
+ SourceRange InitRange);
+ void UpdateStructuredListElement(InitListExpr *StructuredInitList,
+ unsigned &StructuredInitIndex,
+ Expr *expr);
+ int numArrayElements(QualType DeclType);
+ int numStructUnionElements(QualType DeclType);
+public:
+ InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
+ bool HadError() { return hadError; }
+
+ // @brief Retrieves the fully-structured initializer list used for
+ // semantic analysis and code generation.
+ InitListExpr *getFullyStructuredList() const { return FullyStructuredList; }
+};
+
/// Recursively replaces NULL values within the given initializer list
/// with expressions that perform value-initialization of the
/// appropriate type.
@@ -1003,3 +1071,11 @@
static_cast<Expr *>(Init.release()));
return Owned(DIE);
}
+
+bool Sema::CheckInitList(InitListExpr *&InitList, QualType &DeclType) {
+ InitListChecker CheckInitList(this, InitList, DeclType);
+ if (!CheckInitList.HadError())
+ InitList = CheckInitList.getFullyStructuredList();
+
+ return CheckInitList.HadError();
+}
More information about the cfe-commits
mailing list