blob: f2673c4882ec4466ecb1252dca6ac1a8e0e4ec22 [file] [log] [blame]
Steven Morelandf1a35f72016-08-17 08:41:49 -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 Hong42009032016-09-29 09:38:15 -070017#include <hidl-util/StringHelper.h>
18
Steven Morelandf1a35f72016-08-17 08:41:49 -070019#include "EnumVarDeclaration.h"
20#include "Expression.h"
21
22namespace android {
23
24EnumVarDeclaration::EnumVarDeclaration(const std::string &name, Expression *expression)
Yifan Hong42009032016-09-29 09:38:15 -070025 : Declaration(""), mExpression(expression)
26{
27 setName(name);
28}
Steven Morelandf1a35f72016-08-17 08:41:49 -070029
30EnumVarDeclaration::~EnumVarDeclaration() {
31 delete mExpression;
32}
33
Yifan Hong42009032016-09-29 09:38:15 -070034void EnumVarDeclaration::setName(const std::string &name) {
35 Declaration::setName(name);
36 forceUpperSnakeCase();
37}
38
Steven Morelandf1a35f72016-08-17 08:41:49 -070039Expression *EnumVarDeclaration::getExpression() const {
40 return mExpression;
41}
42
43void EnumVarDeclaration::generateSource(Formatter &out) const {
44 out << getName();
45
Yi Kong56758da2018-07-24 16:21:37 -070046 if(mExpression != nullptr) {
Yifan Hong42009032016-09-29 09:38:15 -070047 out << " = " << mExpression->toString(StringHelper::kUpperSnakeCase);
Steven Morelandf1a35f72016-08-17 08:41:49 -070048 }
49
50 out << ",\n";
51}
52
53void EnumVarDeclaration::processContents(AST &) {
54 // nothing to do
55}
56
Yifan Hong42009032016-09-29 09:38:15 -070057} //namespace android