1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HC_GEN_MACRO_GEN_H 10 #define HC_GEN_MACRO_GEN_H 11 12 #include <fstream> 13 #include <map> 14 15 #include "generator.h" 16 17 namespace OHOS { 18 namespace Hardware { 19 class MacroGen : public Generator { 20 public: 21 explicit MacroGen(std::shared_ptr<Ast> ast); 22 23 ~MacroGen() override = default; 24 25 bool Output() override; 26 27 private: 28 bool Initialize(); 29 30 bool TemplateNodeSeparate(); 31 32 std::string GenFullName(int32_t depth, const std::shared_ptr<AstObject> &node, const std::string &sep); 33 34 bool GenNodeForeach(int32_t depth, const std::shared_ptr<AstObject> &node); 35 36 bool NodeWalk(); 37 38 void SetTypeData(uint32_t type, const std::shared_ptr<AstObject> ¤t, uint32_t &arraySize, int32_t depth); 39 40 void SetTypeDataUinit64(const std::string &arrayName, uint32_t &arraySize, uint32_t arrayType, 41 const std::shared_ptr<AstObject> ¤t); 42 43 bool HeaderTopOutput(); 44 45 bool HeaderBottomOutput(); 46 47 static const std::string &ToUpperString(std::string &str); 48 49 bool GenArray(const std::string &arrName, uint32_t &arrSize, uint32_t type, const std::shared_ptr<AstObject> &node); 50 51 std::string GenRefObjName(int32_t depth, const std::shared_ptr<AstObject> &object); 52 53 std::ofstream ofs_; 54 std::string outFileName_; 55 std::map<int, std::string> nodeNameMap_; 56 }; 57 } // namespace Hardware 58 } // namespace OHOS 59 #endif // HC_GEN_MACRO_GEN_H 60