Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -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 | 4200903 | 2016-09-29 09:38:15 -0700 | [diff] [blame] | 17 | #include <hidl-util/StringHelper.h> |
| 18 | |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 19 | #include "EnumVarDeclaration.h" |
| 20 | #include "Expression.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | EnumVarDeclaration::EnumVarDeclaration(const std::string &name, Expression *expression) |
Yifan Hong | 4200903 | 2016-09-29 09:38:15 -0700 | [diff] [blame] | 25 | : Declaration(""), mExpression(expression) |
| 26 | { |
| 27 | setName(name); |
| 28 | } |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 29 | |
| 30 | EnumVarDeclaration::~EnumVarDeclaration() { |
| 31 | delete mExpression; |
| 32 | } |
| 33 | |
Yifan Hong | 4200903 | 2016-09-29 09:38:15 -0700 | [diff] [blame] | 34 | void EnumVarDeclaration::setName(const std::string &name) { |
| 35 | Declaration::setName(name); |
| 36 | forceUpperSnakeCase(); |
| 37 | } |
| 38 | |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 39 | Expression *EnumVarDeclaration::getExpression() const { |
| 40 | return mExpression; |
| 41 | } |
| 42 | |
| 43 | void EnumVarDeclaration::generateSource(Formatter &out) const { |
| 44 | out << getName(); |
| 45 | |
Yi Kong | 56758da | 2018-07-24 16:21:37 -0700 | [diff] [blame] | 46 | if(mExpression != nullptr) { |
Yifan Hong | 4200903 | 2016-09-29 09:38:15 -0700 | [diff] [blame] | 47 | out << " = " << mExpression->toString(StringHelper::kUpperSnakeCase); |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | out << ",\n"; |
| 51 | } |
| 52 | |
| 53 | void EnumVarDeclaration::processContents(AST &) { |
| 54 | // nothing to do |
| 55 | } |
| 56 | |
Yifan Hong | 4200903 | 2016-09-29 09:38:15 -0700 | [diff] [blame] | 57 | } //namespace android |