Home | History | Annotate | Download | only in c2hal
      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 
     17 #include <hidl-util/StringHelper.h>
     18 
     19 #include "EnumVarDeclaration.h"
     20 #include "Expression.h"
     21 
     22 namespace android {
     23 
     24 EnumVarDeclaration::EnumVarDeclaration(const std::string &name, Expression *expression)
     25     : Declaration(""), mExpression(expression)
     26 {
     27     setName(name);
     28 }
     29 
     30 EnumVarDeclaration::~EnumVarDeclaration() {
     31     delete mExpression;
     32 }
     33 
     34 void EnumVarDeclaration::setName(const std::string &name) {
     35     Declaration::setName(name);
     36     forceUpperSnakeCase();
     37 }
     38 
     39 Expression *EnumVarDeclaration::getExpression() const {
     40     return mExpression;
     41 }
     42 
     43 void EnumVarDeclaration::generateSource(Formatter &out) const {
     44     out << getName();
     45 
     46     if(mExpression != NULL) {
     47         out << " = " << mExpression->toString(StringHelper::kUpperSnakeCase);
     48     }
     49 
     50     out << ",\n";
     51 }
     52 
     53 void EnumVarDeclaration::processContents(AST &) {
     54     // nothing to do
     55 }
     56 
     57 } //namespace android
     58