blob: 02584916860096fc088ebe20aa9ef3d8d23b6bdb [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Yifan Hong52165692016-08-12 18:06:40 -070017#include "ConstantExpression.h"
18
19#include <utils/String8.h>
20
21namespace android {
22
23ConstantExpression::ConstantExpression(const char *value)
24 : mValue(value) {
25}
26
27ConstantExpression::ConstantExpression(const ConstantExpression *lval, const char *op, const ConstantExpression* rval)
28 : mValue(android::String8::format("(%s %s %s)", lval->c_str(), op, rval->c_str()).string()) {
29}
30ConstantExpression::ConstantExpression(const char *op, const ConstantExpression *value)
31 : mValue(android::String8::format("(%s%s)", op, value->c_str()).string()) {
32}
33ConstantExpression::ConstantExpression(const ConstantExpression *cond,
34 const ConstantExpression *trueVal,
35 const ConstantExpression *falseVal)
36 : mValue(android::String8::format("(%s?%s:%s)",
37 cond->c_str(), trueVal->c_str(), falseVal->c_str()).string()) {
38}
39
40const char *ConstantExpression::c_str() const {
41 return mValue.c_str();
42}
43const char *ConstantExpression::value() const {
44 return mValue.c_str();
45}
46
47} // namespace android
48