1 /* 2 * Copyright (c) Facebook, Inc. and its affiliates. 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 #pragma once 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include <thrift/compiler/ast/t_node.h> 25 26 namespace apache { 27 namespace thrift { 28 namespace compiler { 29 30 class t_const; 31 32 /** 33 * class t_named 34 * 35 * Base class for any named AST node. 36 * Anything that is named, can be annotated. 37 */ 38 class t_named : public t_node { 39 public: set_name(const std::string & name)40 void set_name(const std::string& name) { name_ = name; } name()41 const std::string& name() const { return name_; } 42 structured_annotations()43 const std::vector<const t_const*>& structured_annotations() const { 44 return structured_annotations_raw_; 45 } 46 void add_structured_annotation(std::unique_ptr<t_const> annot); 47 48 const t_const* find_structured_annotation_or_null(const char* uri) const; 49 uri()50 const std::string& uri() const { return get_annotation("thrift.uri"); } 51 52 protected: 53 // t_named is abstract. 54 t_named() = default; t_named(std::string name)55 explicit t_named(std::string name) : name_(std::move(name)) {} 56 ~t_named(); 57 58 // TODO(afuller): make private. 59 std::string name_; 60 61 private: 62 std::vector<std::shared_ptr<const t_const>> structured_annotations_; 63 64 // TODO(ytj): use thrift.uri --> t_const map for structured annotation 65 std::vector<const t_const*> structured_annotations_raw_; 66 67 // TODO(afuller): Remove everything below this comment. It is only provided 68 // for backwards compatibility. 69 public: get_name()70 const std::string& get_name() const { return name_; } 71 }; 72 73 // Returns true iff the node is a definition of a transitive annotation, 74 // i.e. it has the @meta.Transitive annotation itself. 75 bool is_transitive_annotation(const t_named& node); 76 77 } // namespace compiler 78 } // namespace thrift 79 } // namespace apache 80