Makes Google Mock compile much faster and use much less memory; reviewed by Nico Weber. This fixes issue 68.

This commit is contained in:
zhanyong.wan
2011-02-23 19:39:27 +00:00
parent b3e904227f
commit ed6c9277bb
8 changed files with 818 additions and 575 deletions

View File

@@ -59,9 +59,6 @@ namespace testing {
namespace internal {
template <typename F>
class MonomorphicDoDefaultActionImpl;
template <typename F1, typename F2>
class ActionAdaptor;
@@ -255,8 +252,7 @@ class ActionInterface {
typedef typename internal::Function<F>::Result Result;
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
ActionInterface() : is_do_default_(false) {}
ActionInterface() {}
virtual ~ActionInterface() {}
// Performs the action. This method is not const, as in general an
@@ -265,21 +261,7 @@ class ActionInterface {
// remember the current element.
virtual Result Perform(const ArgumentTuple& args) = 0;
// Returns true iff this is the DoDefault() action.
bool IsDoDefault() const { return is_do_default_; }
private:
template <typename Function>
friend class internal::MonomorphicDoDefaultActionImpl;
// This private constructor is reserved for implementing
// DoDefault(), the default action for a given mock function.
explicit ActionInterface(bool is_do_default)
: is_do_default_(is_do_default) {}
// True iff this action is DoDefault().
const bool is_do_default_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
};
@@ -302,7 +284,8 @@ class Action {
// STL containers.
Action() : impl_(NULL) {}
// Constructs an Action from its implementation.
// Constructs an Action from its implementation. A NULL impl is
// used to represent the "do-default" action.
explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
// Copy constructor.
@@ -316,7 +299,7 @@ class Action {
explicit Action(const Action<Func>& action);
// Returns true iff this is the DoDefault() action.
bool IsDoDefault() const { return impl_->IsDoDefault(); }
bool IsDoDefault() const { return impl_.get() == NULL; }
// Performs the action. Note that this method is const even though
// the corresponding method in ActionInterface is not. The reason
@@ -325,6 +308,13 @@ class Action {
// cannot change state. (Think of the difference between a const
// pointer and a pointer to const.)
Result Perform(const ArgumentTuple& args) const {
internal::Assert(
!IsDoDefault(), __FILE__, __LINE__,
"You are using DoDefault() inside a composite action like "
"DoAll() or WithArgs(). This is not supported for technical "
"reasons. Please instead spell out the default action, or "
"assign the default action to an Action variable and use "
"the variable in various places.");
return impl_->Perform(args);
}
@@ -633,42 +623,13 @@ class ReturnRefOfCopyAction {
GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
};
// Implements the DoDefault() action for a particular function type F.
template <typename F>
class MonomorphicDoDefaultActionImpl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
MonomorphicDoDefaultActionImpl() : ActionInterface<F>(true) {}
// For technical reasons, DoDefault() cannot be used inside a
// composite action (e.g. DoAll(...)). It can only be used at the
// top level in an EXPECT_CALL(). If this function is called, the
// user must be using DoDefault() inside a composite action, and we
// have to generate a run-time error.
virtual Result Perform(const ArgumentTuple&) {
Assert(false, __FILE__, __LINE__,
"You are using DoDefault() inside a composite action like "
"DoAll() or WithArgs(). This is not supported for technical "
"reasons. Please instead spell out the default action, or "
"assign the default action to an Action variable and use "
"the variable in various places.");
return internal::Invalid<Result>();
// The above statement will never be reached, but is required in
// order for this function to compile.
}
};
// Implements the polymorphic DoDefault() action.
class DoDefaultAction {
public:
// This template type conversion operator allows DoDefault() to be
// used in any function.
template <typename F>
operator Action<F>() const {
return Action<F>(new MonomorphicDoDefaultActionImpl<F>);
}
operator Action<F>() const { return Action<F>(NULL); }
};
// Implements the Assign action to set a given pointer referent to a

View File

@@ -1,4 +1,6 @@
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
// This file was GENERATED by command:
// pump.py gmock-generated-function-mockers.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2007, Google Inc.
// All rights reserved.
@@ -352,7 +354,8 @@ using internal::FunctionMocker;
} \
::testing::MockSpec<F>& \
gmock_##Method() constness { \
return GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this).With(); \
GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(0, constness, Method).With(); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(0, constness, Method)
@@ -367,8 +370,8 @@ using internal::FunctionMocker;
} \
::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1) constness { \
return GMOCK_MOCKER_(1, constness, \
Method).RegisterOwner(this).With(gmock_a1); \
GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(1, constness, Method)
@@ -385,8 +388,8 @@ using internal::FunctionMocker;
::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2) constness { \
return GMOCK_MOCKER_(2, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2); \
GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(2, constness, Method)
@@ -406,8 +409,9 @@ using internal::FunctionMocker;
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3) constness { \
return GMOCK_MOCKER_(3, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3); \
GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(3, constness, Method)
@@ -429,9 +433,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4) constness { \
return GMOCK_MOCKER_(4, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4); \
GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(4, constness, Method)
@@ -455,9 +459,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5) constness { \
return GMOCK_MOCKER_(5, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5); \
GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(5, constness, Method)
@@ -483,9 +487,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6) constness { \
return GMOCK_MOCKER_(6, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5, gmock_a6); \
GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(6, constness, Method)
@@ -513,9 +517,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7) constness { \
return GMOCK_MOCKER_(7, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(7, constness, Method)
@@ -545,9 +549,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7, \
GMOCK_MATCHER_(tn, F, 8) gmock_a8) constness { \
return GMOCK_MOCKER_(8, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(8, constness, Method)
@@ -580,9 +584,10 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 7) gmock_a7, \
GMOCK_MATCHER_(tn, F, 8) gmock_a8, \
GMOCK_MATCHER_(tn, F, 9) gmock_a9) constness { \
return GMOCK_MOCKER_(9, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9); \
GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
gmock_a9); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(9, constness, Method)
@@ -617,9 +622,9 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, F, 8) gmock_a8, \
GMOCK_MATCHER_(tn, F, 9) gmock_a9, \
GMOCK_MATCHER_(tn, F, 10) gmock_a10) constness { \
return GMOCK_MOCKER_(10, constness, \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \
gmock_a10); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(10, constness, Method)

View File

@@ -140,7 +140,8 @@ $var matcher_as = [[$for j, \
} \
::testing::MockSpec<F>& \
gmock_##Method($matcher_as) constness { \
return GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this).With($as); \
GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_($i, constness, Method).With($as); \
} \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_($i, constness, Method)

File diff suppressed because it is too large Load Diff