1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "sa_rust_code_emitter.h" 17 18 namespace OHOS { 19 namespace Idl { EmitHeadMacro(StringBuilder & sb) const20void RustCodeEmitter::EmitHeadMacro(StringBuilder &sb) const 21 { 22 sb.Append("#![allow(missing_docs)]\n"); 23 sb.Append("#![allow(unused_variables)]\n"); 24 sb.Append("#![allow(unused_mut)]\n"); 25 sb.Append("\n"); 26 } 27 EmitCommonHeaders(StringBuilder & sb) const28void RustCodeEmitter::EmitCommonHeaders(StringBuilder &sb) const 29 { 30 bool useMap = false; 31 const AST::TypeStringMap &types = ast_->GetTypes(); 32 for (const auto &pair : types) { 33 AutoPtr<ASTType> type = pair.second; 34 switch (type->GetTypeKind()) { 35 case TypeKind::TYPE_MAP: { 36 if (!useMap) { 37 sb.Append("use std::collections::HashMap;\n"); 38 useMap = true; 39 } 40 break; 41 } 42 default: 43 break; 44 } 45 } 46 if (useMap) { 47 sb.Append("\n"); 48 } 49 } 50 51 } // namespace Idl 52 } // namespace OHOS