Update of /cvsroot/boost/boost/boost/xpressive/proto/v1_/compiler
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13713/proto/v1_/compiler
Added Files:
Tag: PROTO2
branch.hpp conditional.hpp error.hpp fold.hpp switch.hpp
transform.hpp
Log Message:
make proto 2 the default, major refactorization, result_of integration
--- NEW FILE: branch.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file branch.hpp
/// A special-purpose proto1 compiler for compiling one branch of the expression
/// tree separately from the rest. Given an expression and a proto1 lambda, it
/// compiles the expression using an initial state determined by the lambda.
/// It then passes the result along with the current state and the visitor
/// to the lambda for further processing.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_BRANCH_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_BRANCH_HPP_EAN_04_01_2005
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// branch_compiler
template<typename Lambda, typename DomainTag>
struct branch_compiler
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef proto1::compiler<typename tag_type<Op>::type, DomainTag>
compiler_type;
// Compile the branch
typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply
<
Op
, typename Lambda::state_type
, Visitor
>::type branch_type;
// Pass the branch, state and visitor to the lambda
typedef typename Lambda::BOOST_NESTED_TEMPLATE apply
<
branch_type
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return Lambda::call
(
proto1::compile(op, typename Lambda::state_type(), visitor,
DomainTag())
, state
, visitor
);
}
};
}}
#endif
--- NEW FILE: conditional.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file conditional.hpp
/// A special-purpose proto1 compiler for compiling an expression either one
/// way or another depending on the properties of the expression.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_CONDITIONAL_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_CONDITIONAL_HPP_EAN_04_01_2005
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// conditional_compiler
template<typename Predicate, typename IfCompiler, typename ElseCompiler>
struct conditional_compiler
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename boost::mpl::if_
<
typename Predicate::BOOST_NESTED_TEMPLATE apply<Op, State,
Visitor>::type
, IfCompiler
, ElseCompiler
>::type compiler_type;
typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply
<
Op
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
typedef typename apply<Op, State, Visitor>::compiler_type
compiler_type;
return compiler_type::call(op, state, visitor);
}
};
}}
#endif
--- NEW FILE: error.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file error.hpp
/// A special-purpose proto1 compiler that simply generates an error. Useful for
/// flagging certain constructs as illegal.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_ERROR_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_ERROR_HPP_EAN_04_01_2005
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// error_compiler
struct error_compiler
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef void type;
};
};
}}
#endif
--- NEW FILE: fold.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file fold.hpp
/// A special-purpose proto1 compiler for merging sequences of binary
operations.
/// It compiles the right operand and passes the result as state while compiling
/// the left. Or, it might do the left first, if you choose.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_FOLD_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_FOLD_HPP_EAN_04_01_2005
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// fold_compiler
// Compiles the right side and passes the result as state while compiling
the left.
// This is useful for serializing a tree.
template<typename OpTag, typename DomainTag, bool RightFirst>
struct fold_compiler
{
// sample compiler implementation for sequencing
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename right_type<Op>::type right_type;
typedef typename left_type<Op>::type left_type;
// compile the right branch
typedef typename compiler<typename tag_type<right_type>::type,
DomainTag>::
BOOST_NESTED_TEMPLATE apply
<
right_type
, State
, Visitor
>::type right_compiled_type;
// forward the result of the right branch to the left
typedef typename compiler<typename tag_type<left_type>::type,
DomainTag>::
BOOST_NESTED_TEMPLATE apply
<
left_type
, right_compiled_type
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return proto1::compile(
proto1::left(op)
, proto1::compile(proto1::right(op), state, visitor, DomainTag())
, visitor
, DomainTag()
);
}
};
///////////////////////////////////////////////////////////////////////////////
// fold_compiler
// Compiles the left side and passes the result as state while compiling
the right.
// This is useful for serializing a tree.
template<typename OpTag, typename DomainTag>
struct fold_compiler<OpTag, DomainTag, false>
{
// sample compiler implementation for sequencing
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename right_type<Op>::type right_type;
typedef typename left_type<Op>::type left_type;
// compile the right branch
typedef typename compiler<typename tag_type<left_type>::type,
DomainTag>::
BOOST_NESTED_TEMPLATE apply
<
left_type
, State
, Visitor
>::type left_compiled_type;
// forward the result of the right branch to the left
typedef typename compiler<typename tag_type<right_type>::type,
DomainTag>::
BOOST_NESTED_TEMPLATE apply
<
right_type
, left_compiled_type
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return proto1::compile(
proto1::right(op)
, proto1::compile(proto1::left(op), state, visitor, DomainTag())
, visitor
, DomainTag()
);
}
};
}}
#endif
--- NEW FILE: switch.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file switch.hpp
/// A generalization of the conditional_compiler. Given N different compilers
/// in a MPL-style map and a lambda that generates a key from an expression,
/// find the compiler in the map corresponding to the key and use that compiler
/// to compile the expression.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_SWITCH_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_SWITCH_HPP_EAN_04_01_2005
#include <boost/mpl/at.hpp>
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// switch_compiler
// applies a transform, then looks up the appropriate compiler in a map
template<typename Lambda, typename Map>
struct switch_compiler
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename boost::mpl::at
<
Map
, typename Lambda::BOOST_NESTED_TEMPLATE apply<Op, State,
Visitor>::type
>::type compiler_type;
typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply
<
Op
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
typedef typename apply<Op, State, Visitor>::compiler_type
compiler_type;
return compiler_type::call(op, state, visitor);
}
};
}}
#endif
--- NEW FILE: transform.hpp ---
///////////////////////////////////////////////////////////////////////////////
/// \file transform.hpp
/// A special-purpose proto1 compiler for applying a transformation to an
/// expression. The transformation is a proto1 lambda. The result of the
/// transformation is forwarded to the specified compiler, or to the
/// default compiler for the resulting expression is no compiler is
/// specified. Also included are some basic transforms, such as one that
/// extracts the operand of a unary op, the left and right operands of
/// a binary op, and a way to compose multiple transforms into one.
//
// Copyright 2004 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROTO_V1_COMPILER_TRANSFORM_HPP_EAN_04_01_2005
#define BOOST_PROTO_V1_COMPILER_TRANSFORM_HPP_EAN_04_01_2005
#include <boost/xpressive/proto/v1_/proto_fwd.hpp>
#include <boost/xpressive/proto/v1_/arg_traits.hpp>
namespace boost { namespace proto1
{
///////////////////////////////////////////////////////////////////////////////
// transform_compiler
// accepts a transformation as a lambda, applies the transformation to any
// parse tree passed in, and then compiles the result using the specified
// compiler
template<typename Lambda, typename DomainTag, typename Compiler>
struct transform_compiler
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename Compiler::BOOST_NESTED_TEMPLATE apply
<
typename Lambda::BOOST_NESTED_TEMPLATE apply<Op, State,
Visitor>::type
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return Compiler::call(Lambda::call(op, state, visitor), state,
visitor);
}
};
///////////////////////////////////////////////////////////////////////////////
// if no compiler is specified, the transform_compiler forwards to the
default
// compiler
template<typename Lambda, typename DomainTag>
struct transform_compiler<Lambda, DomainTag, void>
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename Lambda::BOOST_NESTED_TEMPLATE apply
<
Op
, State
, Visitor
>::type trans_type;
typedef proto1::compiler<typename tag_type<trans_type>::type,
DomainTag> compiler_type;
typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply
<
trans_type
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return proto1::compile(Lambda::call(op, state, visitor), state,
visitor, DomainTag());
}
};
///////////////////////////////////////////////////////////////////////////////
// identity_transform
// pass through without doing a transform
struct identity_transform
{
template<typename Op, typename, typename>
struct apply
{
typedef Op type;
};
template<typename Op, typename State, typename Visitor>
static Op const &call(Op const &op, State const &, Visitor &)
{
return op;
}
};
///////////////////////////////////////////////////////////////////////////////
// arg_transform
struct arg_transform
{
template<typename Op, typename, typename>
struct apply
{
typedef typename arg_type<Op>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename arg_type<Op>::const_reference
call(Op const &op, State const &, Visitor &)
{
return proto1::arg(op);
}
};
///////////////////////////////////////////////////////////////////////////////
// left_transform
struct left_transform
{
template<typename Op, typename, typename>
struct apply
{
typedef typename left_type<Op>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename left_type<Op>::const_reference
call(Op const &op, State const &, Visitor &)
{
return proto1::left(op);
}
};
///////////////////////////////////////////////////////////////////////////////
// right_transform
struct right_transform
{
template<typename Op, typename, typename>
struct apply
{
typedef typename right_type<Op>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename right_type<Op>::const_reference
call(Op const &op, State const &, Visitor &)
{
return proto1::right(op);
}
};
///////////////////////////////////////////////////////////////////////////////
// unary_op_transform
// insert a unary operation
template<typename Tag>
struct unary_op_transform
{
template<typename Op, typename, typename>
struct apply
{
typedef unary_op<Op, Tag> type;
};
template<typename Op, typename State, typename Visitor>
static unary_op<Op, Tag>
call(Op const &op, State const &, Visitor &)
{
return proto1::make_op<Tag>(op);
}
};
///////////////////////////////////////////////////////////////////////////////
// compose_transforms
// execute two transforms in succession
template<typename First, typename Second>
struct compose_transforms
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename Second::BOOST_NESTED_TEMPLATE apply
<
typename First::BOOST_NESTED_TEMPLATE apply<Op, State,
Visitor>::type
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return Second::call(First::call(op, state, visitor), state,
visitor);
}
};
///////////////////////////////////////////////////////////////////////////////
// conditional_transform
// Conditionally execute a transform
template<typename Predicate, typename IfTransform, typename ElseTransform>
struct conditional_transform
{
template<typename Op, typename State, typename Visitor>
struct apply
{
typedef typename boost::mpl::if_
<
typename Predicate::BOOST_NESTED_TEMPLATE apply<Op, State,
Visitor>::type
, IfTransform
, ElseTransform
>::type transform_type;
typedef typename transform_type::BOOST_NESTED_TEMPLATE apply
<
Op
, State
, Visitor
>::type type;
};
template<typename Op, typename State, typename Visitor>
static typename apply<Op, State, Visitor>::type
call(Op const &op, State const &state, Visitor &visitor)
{
return apply<Op, State, Visitor>::transform_type::call(op, state,
visitor);
}
};
template<typename Always>
struct always_transform
{
template<typename, typename, typename>
struct apply
{
typedef Always type;
};
template<typename Op, typename State, typename Visitor>
static Always
call(Op const &, State const &, Visitor &)
{
return Always();
}
};
}}
#endif
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
|