Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 15 | #ifndef VALUE_H_ |
| 16 | #define VALUE_H_ |
| 17 | |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "string_piece.h" |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | class Evaluator; |
Shinichiro Hamaji | 36b326f | 2015-06-26 08:56:13 +0900 | [diff] [blame] | 27 | class Loc; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 28 | |
| 29 | class Evaluable { |
| 30 | public: |
| 31 | virtual void Eval(Evaluator* ev, string* s) const = 0; |
| 32 | virtual shared_ptr<string> Eval(Evaluator*) const; |
| 33 | |
| 34 | protected: |
| 35 | Evaluable(); |
| 36 | virtual ~Evaluable(); |
| 37 | }; |
| 38 | |
| 39 | class Value : public Evaluable { |
| 40 | public: |
| 41 | virtual ~Value(); |
| 42 | |
| 43 | virtual Value* Compact() { return this; } |
| 44 | |
| 45 | string DebugString() const; |
| 46 | |
| 47 | protected: |
| 48 | Value(); |
| 49 | virtual string DebugString_() const = 0; |
| 50 | }; |
| 51 | |
Shinichiro Hamaji | 66bd7bc | 2015-06-19 16:54:06 +0900 | [diff] [blame] | 52 | enum struct ParseExprOpt { |
| 53 | NORMAL = 0, |
| 54 | DEFINE, |
| 55 | COMMAND, |
Shinichiro Hamaji | 4d77b84 | 2015-06-27 06:10:18 +0900 | [diff] [blame] | 56 | FUNC, |
Shinichiro Hamaji | 66bd7bc | 2015-06-19 16:54:06 +0900 | [diff] [blame] | 57 | }; |
| 58 | |
Shinichiro Hamaji | 36b326f | 2015-06-26 08:56:13 +0900 | [diff] [blame] | 59 | Value* ParseExprImpl(const Loc& loc, StringPiece s, const char* terms, |
| 60 | ParseExprOpt opt, |
Shinichiro Hamaji | d146f4c | 2015-06-17 17:51:24 +0900 | [diff] [blame] | 61 | size_t* index_out, bool trim_right_space = false); |
Shinichiro Hamaji | 36b326f | 2015-06-26 08:56:13 +0900 | [diff] [blame] | 62 | Value* ParseExpr(const Loc& loc, StringPiece s, |
| 63 | ParseExprOpt opt = ParseExprOpt::NORMAL); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 64 | |
Shinichiro Hamaji | 76ff983 | 2015-06-18 17:11:22 +0900 | [diff] [blame] | 65 | string JoinValues(const vector<Value*>& vals, const char* sep); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 66 | |
Shinichiro Hamaji | 784b995 | 2015-06-23 14:29:32 +0900 | [diff] [blame] | 67 | Value* NewExpr2(Value* v1, Value* v2); |
Shinichiro Hamaji | 4c469b3 | 2015-06-15 19:53:36 +0900 | [diff] [blame] | 68 | Value* NewExpr3(Value* v1, Value* v2, Value* v3); |
| 69 | |
Shinichiro Hamaji | b74b890 | 2015-06-22 18:22:30 +0900 | [diff] [blame] | 70 | Value* NewLiteral(StringPiece s); |
Shinichiro Hamaji | 4c469b3 | 2015-06-15 19:53:36 +0900 | [diff] [blame] | 71 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 72 | #endif // VALUE_H_ |