[PATCH] Remove template instantiations of std::list<Matcher<T>> and std::vector<Matcher<T>*> for each node T.
Samuel Benzaquen
sbenza at google.com
Mon Jun 10 11:27:13 PDT 2013
Hi klimek,
Replace std::list<> and std::vector<> with plain arrays to reduce the number of symbols in the object file for Registry.cpp.
Some compilers where failing with this file because the number of symbols was above 2**15.
http://llvm-reviews.chandlerc.com/D948
Files:
lib/ASTMatchers/Dynamic/Marshallers.h
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===================================================================
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -20,9 +20,7 @@
#ifndef LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H
#define LLVM_CLANG_AST_MATCHERS_DYNAMIC_MARSHALLERS_H
-#include <list>
#include <string>
-#include <vector>
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
@@ -158,6 +156,9 @@
ArgTypeTraits<ArgType2>::get(Args[1].Value)).clone();
}
+#undef CHECK_ARG_COUNT
+#undef CHECK_ARG_TYPE
+
/// \brief Variadic marshaller function.
template <typename BaseType, typename DerivedType>
class VariadicMatcherCreateCallback : public MatcherCreateCallback {
@@ -169,25 +170,37 @@
DynTypedMatcher *run(const SourceRange &NameRange, ArrayRef<ParserValue> Args,
Diagnostics *Error) const {
- std::list<DerivedMatcherType> References;
- std::vector<const DerivedMatcherType *> InnerArgs(Args.size());
- for (size_t i = 0, e = Args.size(); i != e; ++i) {
- CHECK_ARG_TYPE(i, DerivedMatcherType);
- References.push_back(
- ArgTypeTraits<DerivedMatcherType>::get(Args[i].Value));
- InnerArgs[i] = &References.back();
+ DerivedMatcherType **InnerArgs = new DerivedMatcherType *[Args.size()]();
+
+ bool HasError = false;
+ for (size_t I = 0, E = Args.size(); I != E; ++I) {
+ if (!Args[I].Value.isTypedMatcher<DerivedType>()) {
+ Error->pushErrorFrame(Args[I].Range, Error->ET_RegistryWrongArgType)
+ << MatcherName << (I + 1);
+ HasError = true;
+ break;
+ }
+ InnerArgs[I] =
+ new DerivedMatcherType(Args[I].Value.getTypedMatcher<DerivedType>());
+ }
+
+ DynTypedMatcher *Out = NULL;
+ if (!HasError) {
+ Out = ast_matchers::internal::makeDynCastAllOfComposite<BaseType>(
+ ArrayRef<const DerivedMatcherType *>(InnerArgs, Args.size())).clone();
}
- return ast_matchers::internal::makeDynCastAllOfComposite<BaseType>(
- ArrayRef<const DerivedMatcherType *>(InnerArgs)).clone();
+
+ for (size_t I = 0, E = Args.size(); I != E; ++I) {
+ delete InnerArgs[I];
+ }
+ delete[] InnerArgs;
+ return Out;
}
private:
const std::string MatcherName;
};
-#undef CHECK_ARG_COUNT
-#undef CHECK_ARG_TYPE
-
/// Helper functions to select the appropriate marshaller functions.
/// They detects the number of arguments, arguments types and return type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D948.1.patch
Type: text/x-patch
Size: 2554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130610/260eea3b/attachment.bin>
More information about the cfe-commits
mailing list