summaryrefslogtreecommitdiff
path: root/svx/source/customshapes
diff options
context:
space:
mode:
authormb93783 <mb93783@macpro-dev1>2009-11-04 15:39:48 +0100
committermb93783 <mb93783@macpro-dev1>2009-11-04 15:39:48 +0100
commitee680c2c225a7fe2219a47c9c4c325c2f6736c67 (patch)
treed7fa5bb2fbc39dcf6783948db91683037b31c472 /svx/source/customshapes
parent6629d51108b9f030fd41d81edc60a397d9ac7b75 (diff)
#i106432#, #i103496#: some fixes found while building on more platforms
Diffstat (limited to 'svx/source/customshapes')
-rwxr-xr-x[-rw-r--r--]svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx117
1 files changed, 63 insertions, 54 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx b/svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx
index f79658f8f3..9c408f7746 100644..100755
--- a/svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFunctionParser.cxx
@@ -1,7 +1,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -34,10 +34,11 @@
#include <rtl/ustring.hxx>
#include <tools/fract.hxx>
-// Makes parser a static resource,
+// Makes parser a static resource,
// we're synchronized externally.
// But watch out, the parser might have
// state not visible to this code!
+
#define BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE
#if defined(VERBOSE) && defined(DBG_UTIL)
#include <typeinfo>
@@ -159,7 +160,7 @@ public:
AdjustmentExpression( const EnhancedCustomShape2d& rCustoShape, sal_Int32 nIndex )
: mnIndex ( nIndex )
, mrCustoShape( rCustoShape )
-
+
{
}
virtual double operator()() const
@@ -335,7 +336,7 @@ public:
virtual double operator()() const
{
return getValue( meFunct, mpArg );
- }
+ }
virtual bool isConstant() const
{
return mpArg->isConstant();
@@ -506,7 +507,7 @@ public:
virtual double operator()() const
{
return getValue( meFunct, mpFirstArg, mpSecondArg );
- }
+ }
virtual bool isConstant() const
{
return mpFirstArg->isConstant() && mpSecondArg->isConstant();
@@ -558,7 +559,7 @@ public:
FillEquationParameter( mpSecondArg->fillNode( rEquations, NULL, nFlags &~EXPRESSION_FLAG_SUMANGLE_MODE ), 1, aSumangle2 );
aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
aRet.Value <<= (sal_Int32)rEquations.size();
- rEquations.push_back( aSumangle2 );
+ rEquations.push_back( aSumangle2 );
EnhancedCustomShapeEquation aEquation;
aEquation.nOperation |= 0;
@@ -591,7 +592,7 @@ public:
}
}
break;
- case BINARY_FUNC_MINUS:
+ case BINARY_FUNC_MINUS:
{
EnhancedCustomShapeEquation aEquation;
aEquation.nOperation |= 0;
@@ -654,7 +655,7 @@ public:
rEquations.push_back( aEquation );
}
break;
- case BINARY_FUNC_MIN :
+ case BINARY_FUNC_MIN :
{
EnhancedCustomShapeEquation aEquation;
aEquation.nOperation |= 4;
@@ -712,9 +713,9 @@ public:
}
virtual bool isConstant() const
{
- return
- mpFirstArg->isConstant() &&
- mpSecondArg->isConstant() &&
+ return
+ mpFirstArg->isConstant() &&
+ mpSecondArg->isConstant() &&
mpThirdArg->isConstant();
}
virtual double operator()() const
@@ -848,7 +849,7 @@ class UnaryFunctionFunctor
ParserContextSharedPtr mpContext;
public :
-
+
UnaryFunctionFunctor( const ExpressionFunct eFunct, const ParserContextSharedPtr& rContext ) :
meFunct( eFunct ),
mpContext( rContext )
@@ -877,7 +878,7 @@ public :
@tpl Generator
Generator functor, to generate an ExpressionNode of
appropriate type
-
+
*/
class BinaryFunctionFunctor
{
@@ -952,13 +953,13 @@ public :
// Workaround for MSVC compiler anomaly (stack trashing)
//
-// The default ureal_parser_policies implementation of parse_exp
-// triggers a really weird error in MSVC7 (Version 13.00.9466), in
-// that the real_parser_impl::parse_main() call of parse_exp()
+// The default ureal_parser_policies implementation of parse_exp
+// triggers a really weird error in MSVC7 (Version 13.00.9466), in
+// that the real_parser_impl::parse_main() call of parse_exp()
// overwrites the frame pointer _on the stack_ (EBP of the calling
-// function gets overwritten while lying on the stack).
+// function gets overwritten while lying on the stack).
//
-// For the time being, our parser thus can only read the 1.0E10
+// For the time being, our parser thus can only read the 1.0E10
// notation, not the 1.0e10 one.
//
// TODO(F1): Also handle the 1.0e10 case here.
@@ -967,9 +968,9 @@ template< typename T > struct custom_real_parser_policies : public ::boost::spir
template< typename ScannerT >
static typename ::boost::spirit::parser_result< ::boost::spirit::chlit<>, ScannerT >::type
parse_exp(ScannerT& scan)
- {
+ {
// as_lower_d somehow breaks MSVC7
- return ::boost::spirit::ch_p('E').parse(scan);
+ return ::boost::spirit::ch_p('E').parse(scan);
}
};
@@ -977,29 +978,30 @@ template< typename T > struct custom_real_parser_policies : public ::boost::spir
less literally written down below, only slightly
obfuscated by the parser actions):
- identifier = '$'|'pi'|'e'|'X'|'Y'|'Width'|'Height'
-
+ identifier = '$'|'pi'|'e'|'X'|'Y'|'Width'|'Height'
+
function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'|'acos'|'asin'|'exp'|'log'
- basic_expression =
- number |
- identifier |
- function '(' additive_expression ')' |
- '(' additive_expression ')'
-
- unary_expression =
+ basic_expression =
+ number |
+ identifier |
+ function '(' additive_expression ')' |
+ '(' additive_expression ')'
+
+ unary_expression =
'-' basic_expression |
basic_expression
-
- multiplicative_expression =
- unary_expression ( ( '*' unary_expression )* |
+
+ multiplicative_expression =
+ unary_expression ( ( '*' unary_expression )* |
( '/' unary_expression )* )
-
- additive_expression =
- multiplicative_expression ( ( '+' multiplicative_expression )* |
- ( '-' multiplicative_expression )* )
+
+ additive_expression =
+ multiplicative_expression ( ( '+' multiplicative_expression )* |
+ ( '-' multiplicative_expression )* )
*/
+
class ExpressionGrammar : public ::boost::spirit::grammar< ExpressionGrammar >
{
public:
@@ -1041,7 +1043,7 @@ public:
| str_p( "logheight" )[ EnumFunctor(ENUM_FUNC_LOGHEIGHT, self.getContext() ) ]
;
- unaryFunction =
+ unaryFunction =
(str_p( "abs" ) >> '(' >> additiveExpression >> ')' )[ UnaryFunctionFunctor( UNARY_FUNC_ABS, self.getContext()) ]
| (str_p( "sqrt" ) >> '(' >> additiveExpression >> ')' )[ UnaryFunctionFunctor( UNARY_FUNC_SQRT, self.getContext()) ]
| (str_p( "sin" ) >> '(' >> additiveExpression >> ')' )[ UnaryFunctionFunctor( UNARY_FUNC_SIN, self.getContext()) ]
@@ -1050,17 +1052,17 @@ public:
| (str_p( "atan" ) >> '(' >> additiveExpression >> ')' )[ UnaryFunctionFunctor( UNARY_FUNC_ATAN, self.getContext()) ]
;
- binaryFunction =
+ binaryFunction =
(str_p( "min" ) >> '(' >> additiveExpression >> ',' >> additiveExpression >> ')' )[ BinaryFunctionFunctor( BINARY_FUNC_MIN, self.getContext()) ]
| (str_p( "max" ) >> '(' >> additiveExpression >> ',' >> additiveExpression >> ')' )[ BinaryFunctionFunctor( BINARY_FUNC_MAX, self.getContext()) ]
| (str_p( "atan2") >> '(' >> additiveExpression >> ',' >> additiveExpression >> ')' )[ BinaryFunctionFunctor( BINARY_FUNC_ATAN2,self.getContext()) ]
;
- ternaryFunction =
+ ternaryFunction =
(str_p( "if" ) >> '(' >> additiveExpression >> ',' >> additiveExpression >> ',' >> additiveExpression >> ')' )[ IfFunctor( self.getContext() ) ]
;
- funcRef_decl =
+ funcRef_decl =
lexeme_d[ +( range_p('a','z') | range_p('A','Z') | range_p('0','9') ) ];
functionReference =
@@ -1072,7 +1074,7 @@ public:
modifierReference =
(str_p( "$" ) >> modRef_decl )[ EnumFunctor( ENUM_FUNC_ADJUSTMENT, self.getContext() ) ];
- basicExpression =
+ basicExpression =
real_parser<double, custom_real_parser_policies<double> >()[ DoubleConstantFunctor(self.getContext()) ]
| identifier
| functionReference
@@ -1083,19 +1085,19 @@ public:
| '(' >> additiveExpression >> ')'
;
- unaryExpression =
+ unaryExpression =
('-' >> basicExpression)[ UnaryFunctionFunctor( UNARY_FUNC_NEG, self.getContext()) ]
| basicExpression
;
- multiplicativeExpression =
+ multiplicativeExpression =
unaryExpression
>> *( ('*' >> unaryExpression)[ BinaryFunctionFunctor( BINARY_FUNC_MUL, self.getContext()) ]
| ('/' >> unaryExpression)[ BinaryFunctionFunctor( BINARY_FUNC_DIV, self.getContext()) ]
)
;
- additiveExpression =
+ additiveExpression =
multiplicativeExpression
>> *( ('+' >> multiplicativeExpression)[ BinaryFunctionFunctor( BINARY_FUNC_PLUS, self.getContext()) ]
| ('-' >> multiplicativeExpression)[ BinaryFunctionFunctor( BINARY_FUNC_MINUS, self.getContext()) ]
@@ -1116,9 +1118,9 @@ public:
{
return additiveExpression;
}
-
+
private:
- // the constituents of the Spirit arithmetic expression grammar.
+ // the constituents of the Spirit arithmetic expression grammar.
// For the sake of readability, without 'ma' prefix.
::boost::spirit::rule< ScannerT > additiveExpression;
::boost::spirit::rule< ScannerT > multiplicativeExpression;
@@ -1132,7 +1134,7 @@ public:
::boost::spirit::rule< ScannerT > modRef_decl;
::boost::spirit::rule< ScannerT > modifierReference;
::boost::spirit::rule< ScannerT > identifier;
- };
+ };
const ParserContextSharedPtr& getContext() const
{
@@ -1142,13 +1144,13 @@ public:
private:
ParserContextSharedPtr mpParserContext; // might get modified during parsing
};
-
+
#ifdef BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE
const ParserContextSharedPtr& getParserContext()
{
static ParserContextSharedPtr lcl_parserContext( new ParserContext() );
- // clear node stack (since we reuse the static object, that's
+ // clear node stack (since we reuse the static object, that's
// the whole point here)
while( !lcl_parserContext->maOperandStack.empty() )
lcl_parserContext->maOperandStack.pop();
@@ -1161,12 +1163,14 @@ const ParserContextSharedPtr& getParserContext()
namespace EnhancedCustomShape {
+
+
ExpressionNodeSharedPtr FunctionParser::parseFunction( const ::rtl::OUString& rFunction, const EnhancedCustomShape2d& rCustoShape )
{
- // TODO(Q1): Check if a combination of the RTL_UNICODETOTEXT_FLAGS_*
- // gives better conversion robustness here (we might want to map space
+ // TODO(Q1): Check if a combination of the RTL_UNICODETOTEXT_FLAGS_*
+ // gives better conversion robustness here (we might want to map space
// etc. to ASCII space here)
- const ::rtl::OString& rAsciiFunction(
+ const ::rtl::OString& rAsciiFunction(
rtl::OUStringToOString( rFunction, RTL_TEXTENCODING_ASCII_US ) );
StringIteratorT aStart( rAsciiFunction.getStr() );
@@ -1184,23 +1188,28 @@ ExpressionNodeSharedPtr FunctionParser::parseFunction( const ::rtl::OUString& rF
pContext->mpCustoShape = &rCustoShape;
ExpressionGrammar aExpressionGrammer( pContext );
- const ::boost::spirit::parse_info<StringIteratorT> aParseInfo(
+ const ::boost::spirit::parse_info<StringIteratorT> aParseInfo(
::boost::spirit::parse( aStart,
aEnd,
aExpressionGrammer >> ::boost::spirit::end_p,
::boost::spirit::space_p ) );
OSL_DEBUG_ONLY(::std::cout.flush()); // needed to keep stdout and cout in sync
+
+
// input fully congested by the parser?
if( !aParseInfo.full )
throw ParseError( "EnhancedCustomShapeFunctionParser::parseFunction(): string not fully parseable" );
- // parser's state stack now must contain exactly _one_ ExpressionNode,
+ // parser's state stack now must contain exactly _one_ ExpressionNode,
// which represents our formula.
if( pContext->maOperandStack.size() != 1 )
throw ParseError( "EnhancedCustomShapeFunctionParser::parseFunction(): incomplete or empty expression" );
+
return pContext->maOperandStack.top();
}
+
}
+