1 /*
2 
3     This file is part of the Maude 2 interpreter.
4 
5     Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 //
24 //      Class for symbols for built in operations on strings.
25 //
26 #ifndef _stringOpSymbol_hh_
27 #define _stringOpSymbol_hh_
28 #include "rope.hh"
29 #include "freeSymbol.hh"
30 #include "cachedDag.hh"
31 
32 class StringOpSymbol : public FreeSymbol
33 {
34 public:
35   StringOpSymbol(int id, int arity);
36 
37   bool attachData(const Vector<Sort*>& opDeclaration,
38 		  const char* purpose,
39 		  const Vector<const char*>& data);
40   bool attachSymbol(const char* purpose, Symbol* symbol);
41   bool attachTerm(const char* purpose, Term* term);
42   void copyAttachments(Symbol* original, SymbolMap* map);
43   void getDataAttachments(const Vector<Sort*>& opDeclaration,
44 			  Vector<const char*>& purposes,
45 			  Vector<Vector<const char*> >& data);
46   void getSymbolAttachments(Vector<const char*>& purposes,
47 			    Vector<Symbol*>& symbols);
48   void getTermAttachments(Vector<const char*>& purposes,
49 			  Vector<Term*>& terms);
50 
51   bool eqRewrite(DagNode* subject, RewritingContext& context);
52   void postInterSymbolPass();
53   void reset();
54 
55 private:
56   enum
57   {
58     //
59     //	Tha actual maximum number of significant digits in the exact
60     //	decimal represention of a IEEE-754 double is hard to calculate
61     //	but must be < 1074 since there can be at most 1074 binary places
62     //	and with 1074 binary places the first multiplications will produce
63     //	leading zeros.
64     //
65     MAX_FLOAT_DIGITS = 1074
66   };
67   bool rewriteToString(DagNode* subject, RewritingContext& context, const Rope& result);
68   static bool ropeToNumber(const Rope& subject,
69 			   int base,
70 			   mpz_class& numerator,
71 			   mpz_class& denominator);
72   static Rope substring(const Rope& subject, Rope::size_type index, Rope::size_type length);
73   static int fwdFind(const Rope& subject, const Rope& pattern, Rope::size_type start);
74   static int revFind(const Rope& subject, const Rope& pattern, Rope::size_type start);
75 
76   int op;
77   StringSymbol* stringSymbol;
78   SuccSymbol* succSymbol;
79   MinusSymbol* minusSymbol;
80   DivisionSymbol* divisionSymbol;
81   FloatSymbol* floatSymbol;
82   Symbol* decFloatSymbol;
83   CachedDag trueTerm;
84   CachedDag falseTerm;
85   CachedDag notFoundTerm;
86 };
87 
88 #endif
89