Replace Sema::CheckInitializerListTypes() with a helper class (InitListChecker) that synthesizes implicit InitListExpr's when appropriate (see InitListExpr comments in Expr.h for more details). I also moved the code to SemaInit.cpp, to help reduce clutter in SemaDecl.cpp.
NOTE: This work is incomplete and still fails many tests (as a result, it isn't enabled yet). Nevertheless, I wanted to check it in so I can work on it from home.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50544 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 8b85351..1bed03c 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -839,6 +839,7 @@
IdentifierInfo &Comp, SourceLocation CmpLoc);
/// type checking declaration initializers (C99 6.7.8)
+ friend class InitListChecker;
bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType);
bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
@@ -887,6 +888,32 @@
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
};
+class InitListChecker {
+ Sema *SemaRef;
+ bool hadError;
+
+ void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
+ unsigned &Index);
+ void CheckExplicitInitList(InitListExpr *IList, QualType T,
+ unsigned &Index);
+
+ void CheckElementTypes(InitListExpr *IList, QualType &DeclType,
+ unsigned &Index);
+ // FIXME: Does DeclType need to be a reference type?
+ void CheckScalarType(InitListExpr *IList, QualType &DeclType,
+ unsigned &Index);
+ void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
+ void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
+ unsigned &Index);
+ void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index);
+
+ int numArrayElements(QualType DeclType);
+ int numStructUnionElements(QualType DeclType);
+public:
+ InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
+ bool HadError() { return hadError; }
+};
+
} // end namespace clang