junrushao1994 commented on code in PR #12048:
URL: https://github.com/apache/tvm/pull/12048#discussion_r922637780


##########
include/tvm/script/printer/doc.h:
##########
@@ -158,6 +188,454 @@ class LiteralDoc : public ExprDoc {
   TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(LiteralDoc, ExprDoc, 
LiteralDocNode);
 };
 
+/*!
+ * \brief Doc that represents identifier.
+ *
+ * \sa IdDoc
+ */
+class IdDocNode : public ExprDocNode {
+ public:
+  /*! \brief The name of the identifier */
+  String name;
+
+  void VisitAttrs(AttrVisitor* v) {
+    ExprDocNode::VisitAttrs(v);
+    v->Visit("name", &name);
+  }
+
+  static constexpr const char* _type_key = "script.printer.IdDoc";
+  TVM_DECLARE_FINAL_OBJECT_INFO(IdDocNode, ExprDocNode);
+};
+
+/*!
+ * \brief Reference type of IdDocNode.
+ *
+ * \sa IdDocNode
+ */
+class IdDoc : public ExprDoc {
+ public:
+  /*!
+   * \brief Constructor of IdDoc.
+   * \param name The name of identifier.
+   */
+  explicit IdDoc(String name);
+  TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(IdDoc, ExprDoc, IdDocNode);
+};
+
+/*!
+ * \brief Doc that represents attribute access on another expression.
+ *
+ * \sa AttrAccessDoc
+ */
+class AttrAccessDocNode : public ExprDocNode {
+ public:
+  /*! \brief The target expression to be accessed */
+  ExprDoc value{nullptr};
+  /*! \brief The attribute to be accessed */
+  String attr;
+
+  void VisitAttrs(AttrVisitor* v) {
+    ExprDocNode::VisitAttrs(v);
+    v->Visit("value", &value);
+    v->Visit("attr", &attr);
+  }
+
+  static constexpr const char* _type_key = "script.printer.AttrAccessDoc";
+  TVM_DECLARE_FINAL_OBJECT_INFO(AttrAccessDocNode, ExprDocNode);
+};
+
+/*!
+ * \brief Reference type of AttrAccessDocNode.
+ *
+ * \sa AttrAccessDocNode
+ */
+class AttrAccessDoc : public ExprDoc {
+ public:
+  /*!
+   * \brief Constructor of AttrAccessDoc
+   * \param value The target expression of attribute access.
+   * \param attr The name of attribute to access.
+   */
+  explicit AttrAccessDoc(ExprDoc value, String attr);
+  TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(AttrAccessDoc, ExprDoc, 
AttrAccessDocNode);
+};
+
+/*!
+ * \brief Doc that represents index access on another expression.
+ *
+ * \sa IndexDoc
+ */
+class IndexDocNode : public ExprDocNode {
+ public:
+  /*! \brief The container value to be accessed */
+  ExprDoc value{nullptr};
+  /*!
+   * \brief The indices to access
+   *
+   * Possible actual types:
+   * - ExprDoc (single point access like a[1, 2])
+   * - SliceDoc (slice access like a[1:5, 2])
+   */
+  Array<Doc> indices;  // Each element is union of: Slice / ExprDoc
+
+  void VisitAttrs(AttrVisitor* v) {
+    ExprDocNode::VisitAttrs(v);
+    v->Visit("value", &value);
+    v->Visit("indices", &indices);
+  }
+
+  static constexpr const char* _type_key = "script.printer.IndexDoc";
+  TVM_DECLARE_FINAL_OBJECT_INFO(IndexDocNode, ExprDocNode);
+};
+
+/*!
+ * \brief Reference type of IndexDocNode.
+ *
+ * \sa IndexDocNode
+ */
+class IndexDoc : public ExprDoc {
+ public:
+  /*!
+   * \brief Constructor of IndexDoc
+   * \param value The target expression of index access.
+   * \param indices The indices to access.
+   */
+  explicit IndexDoc(ExprDoc value, Array<Doc> indices);
+  TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(IndexDoc, ExprDoc, IndexDocNode);
+};
+
+/*!
+ * \brief Doc that represents function call.
+ *
+ * \sa CallDoc
+ */
+class CallDocNode : public ExprDocNode {
+ public:
+  /*! \brief The callee of this function call */
+  ExprDoc callee{nullptr};
+  /*! \brief The positional arguments */
+  Array<ExprDoc> args;
+  /*! \brief The keys of keyword arguments */
+  Array<String> kwargs_keys;
+  /*!
+   * \brief The values of keyword arguments.
+   *
+   * The i-th element is the value of the i-th key in `kwargs_keys`.
+   * It must have the same length as `kwargs_keys`.
+   */
+  Array<ExprDoc> kwargs_values;
+
+  void VisitAttrs(AttrVisitor* v) {
+    ExprDocNode::VisitAttrs(v);
+    v->Visit("callee", &callee);
+    v->Visit("args", &args);
+    v->Visit("kwargs_keys", &kwargs_keys);
+    v->Visit("kwargs_values", &kwargs_values);
+  }
+
+  static constexpr const char* _type_key = "script.printer.CallDoc";
+  TVM_DECLARE_FINAL_OBJECT_INFO(CallDocNode, ExprDocNode);
+};
+
+/*!
+ * \brief Reference type of CallDocNode.
+ *
+ * \sa CallDocNode
+ */
+class CallDoc : public ExprDoc {
+ public:
+  /*!
+   * \brief Constructor of CallDoc
+   * \param callee The callee of this function call.
+   * \param args The positional arguments.
+   * \param kwargs_keys Keys of keyword arguments.
+   * \param kwargs_values Values of keyword arguments, must have the same 
length as `kwargs_keys.
+   */
+  CallDoc(ExprDoc callee, Array<ExprDoc> args, Array<String> kwargs_keys,
+          Array<ExprDoc> kwargs_values);
+  TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(CallDoc, ExprDoc, CallDocNode);
+};
+
+/*!
+ * \brief Doc that represents operation.
+ *
+ * It can be unary, binary and other special operators (for example,
+ * the if-then-else expression).
+ *
+ * \sa OperationDoc
+ */
+class OperationDocNode : public ExprDocNode {
+ public:
+  enum class Kind : int32_t {
+    // Unary operators
+    kUnaryStart,
+    kUSub,    // -x
+    kInvert,  // ~x
+    kUnaryEnd,

Review Comment:
   Let's explicitly specify their values:
   
   ```suggestion
       // Unary operators
       kUnaryStart = 0,
       kUSub = 1,    // -x
       kInvert = 2,  // ~x
       kUnaryEnd = 3,
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to