Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame^] | 1 | /* |
| 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 Hong | 5216569 | 2016-08-12 18:06:40 -0700 | [diff] [blame] | 17 | #include "ConstantExpression.h" |
| 18 | |
| 19 | #include <utils/String8.h> |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | ConstantExpression::ConstantExpression(const char *value) |
| 24 | : mValue(value) { |
| 25 | } |
| 26 | |
| 27 | ConstantExpression::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 | } |
| 30 | ConstantExpression::ConstantExpression(const char *op, const ConstantExpression *value) |
| 31 | : mValue(android::String8::format("(%s%s)", op, value->c_str()).string()) { |
| 32 | } |
| 33 | ConstantExpression::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 | |
| 40 | const char *ConstantExpression::c_str() const { |
| 41 | return mValue.c_str(); |
| 42 | } |
| 43 | const char *ConstantExpression::value() const { |
| 44 | return mValue.c_str(); |
| 45 | } |
| 46 | |
| 47 | } // namespace android |
| 48 | |