blob: 8e18e14380ce42b1bee4c0dc9ec9a090e9772120 [file] [log] [blame]
Shinichiro Hamaji1d545aa2015-06-23 15:29:13 +09001// 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 Hamaji776ca302015-06-06 03:52:48 +090015#ifndef VALUE_H_
16#define VALUE_H_
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#include "string_piece.h"
23
24using namespace std;
25
26class Evaluator;
Shinichiro Hamaji36b326f2015-06-26 08:56:13 +090027class Loc;
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090028
29class 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
39class 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 Hamaji66bd7bc2015-06-19 16:54:06 +090052enum struct ParseExprOpt {
53 NORMAL = 0,
54 DEFINE,
55 COMMAND,
Shinichiro Hamaji4d77b842015-06-27 06:10:18 +090056 FUNC,
Shinichiro Hamaji66bd7bc2015-06-19 16:54:06 +090057};
58
Shinichiro Hamaji36b326f2015-06-26 08:56:13 +090059Value* ParseExprImpl(const Loc& loc, StringPiece s, const char* terms,
60 ParseExprOpt opt,
Shinichiro Hamajid146f4c2015-06-17 17:51:24 +090061 size_t* index_out, bool trim_right_space = false);
Shinichiro Hamaji36b326f2015-06-26 08:56:13 +090062Value* ParseExpr(const Loc& loc, StringPiece s,
63 ParseExprOpt opt = ParseExprOpt::NORMAL);
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090064
Shinichiro Hamaji76ff9832015-06-18 17:11:22 +090065string JoinValues(const vector<Value*>& vals, const char* sep);
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090066
Shinichiro Hamaji784b9952015-06-23 14:29:32 +090067Value* NewExpr2(Value* v1, Value* v2);
Shinichiro Hamaji4c469b32015-06-15 19:53:36 +090068Value* NewExpr3(Value* v1, Value* v2, Value* v3);
69
Shinichiro Hamajib74b8902015-06-22 18:22:30 +090070Value* NewLiteral(StringPiece s);
Shinichiro Hamaji4c469b32015-06-15 19:53:36 +090071
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090072#endif // VALUE_H_