Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error of class static function #71

Open
ezchi opened this issue Mar 2, 2024 · 0 comments
Open

Parsing error of class static function #71

ezchi opened this issue Mar 2, 2024 · 0 comments

Comments

@ezchi
Copy link

ezchi commented Mar 2, 2024

Example SystemVerilog file: factory-method-example.sv.txt

interface class Shape;
    pure virtual function void draw();
endclass

class Rectangle implements Shape;
    function void draw();
        $display("Drawing a rectangle");
    endfunction
endclass

class Circle implements Shape;
    function void draw();
        $display("Drawing a circle");
    endfunction
endclass

class ShapeFactory;
    static function Shape createShape(string shapeType);
        if (shapeType == "rectangle") begin
            Rectangle newShape = new();
            return newShape;
        end
        else if (shapeType == "circle") begin
            Circle newShape = new();
            return newShape;
        end
        else begin
            $display("Invalid shape type");
            return null;
        end
    endfunction
endclass

module top;
    Shape myShape;
    initial begin
        myShape = ShapeFactory::createShape("rectangle");
        myShape.draw();
        myShape = ShapeFactory::createShape("circle");
        myShape.draw();
        myShape = ShapeFactory::createShape("triangle");
        if (myShape != null) begin
            myShape.draw();
        end
        $finish;
    end
endmodule

Got error in treesit-explore-mode

(source_file
 (package_or_generate_item_declaration
  (interface_class_declaration interface class
   (class_identifier (simple_identifier))
   (interface_class_item ;)
   (interface_class_item
    (interface_class_method pure virtual
     (function_prototype function
      (data_type_or_void void)
      (function_identifier
       (function_identifier (simple_identifier)))
      ( ))
     ;))
   endclass))
 (package_or_generate_item_declaration
  (class_declaration class
   (class_identifier (simple_identifier))
   implements
   (interface_class_type
    (class_identifier (simple_identifier)))
   ;
   (class_item
    (class_method
     (function_declaration function
      (function_body_declaration
       (function_data_type_or_implicit1
        (data_type_or_void void))
       (function_identifier
        (function_identifier (simple_identifier)))
       ( ) ;
       (function_statement_or_null
        (function_statement
         (statement
          (statement_item
           (system_tf_call (system_tf_identifier)
            (list_of_arguments_parent (
             (expression
              (primary
               (primary_literal
                (string_literal " "))))
             )))
           ;))))
       endfunction))))
   endclass))
 (package_or_generate_item_declaration
  (class_declaration class
   (class_identifier (simple_identifier))
   implements
   (interface_class_type
    (class_identifier (simple_identifier)))
   ;
   (class_item
    (class_method
     (function_declaration function
      (function_body_declaration
       (function_data_type_or_implicit1
        (data_type_or_void void))
       (function_identifier
        (function_identifier (simple_identifier)))
       ( ) ;
       (function_statement_or_null
        (function_statement
         (statement
          (statement_item
           (system_tf_call (system_tf_identifier)
            (list_of_arguments_parent (
             (expression
              (primary
               (primary_literal
                (string_literal " "))))
             )))
           ;))))
       endfunction))))
   endclass))
 (package_or_generate_item_declaration
  (class_declaration class
   (class_identifier (simple_identifier))
   ;
   (class_item
    (class_method
     (method_qualifier
      (class_item_qualifier static))
     (function_declaration function
      (function_body_declaration
       (function_data_type_or_implicit1
        (data_type_or_void
         (data_type (simple_identifier))))
       (function_identifier
        (function_identifier (simple_identifier)))
       (
       (tf_port_list
        (tf_port_item1
         (data_type_or_implicit1
          (data_type string))
         (port_identifier (simple_identifier))))
       ) ;
       (function_statement_or_null
        (function_statement
         (statement
          (statement_item
           (conditional_statement if (
            (cond_predicate
             (expression
              (expression
               (primary (simple_identifier)))
              ==
              (expression
               (primary
                (primary_literal
                 (string_literal " "))))))
            )
            (statement_or_null
             (statement
              (statement_item
               (seq_block begin
                (block_item_declaration
                 (data_declaration
                  (data_type_or_implicit1
                   (data_type (simple_identifier)))
                  (list_of_variable_decl_assignments
                   (variable_decl_assignment (simple_identifier) =
                    (class_new new
                     (list_of_arguments_parent ( )))))
                  ;))
                (statement_or_null
                 (statement
                  (statement_item
                   (jump_statement return
                    (expression
                     (primary (simple_identifier)))
                    ;))))
                end))))
            else
            (statement_or_null
             (statement
              (statement_item
               (conditional_statement if (
                (cond_predicate
                 (expression
                  (expression
                   (primary (simple_identifier)))
                  ==
                  (expression
                   (primary
                    (primary_literal
                     (string_literal " "))))))
                )
                (statement_or_null
                 (statement
                  (statement_item
                   (seq_block begin
                    (block_item_declaration
                     (data_declaration
                      (data_type_or_implicit1
                       (data_type (simple_identifier)))
                      (list_of_variable_decl_assignments
                       (variable_decl_assignment (simple_identifier) =
                        (class_new new
                         (list_of_arguments_parent ( )))))
                      ;))
                    (statement_or_null
                     (statement
                      (statement_item
                       (jump_statement return
                        (expression
                         (primary (simple_identifier)))
                        ;))))
                    end))))
                else
                (statement_or_null
                 (statement
                  (statement_item
                   (seq_block begin
                    (statement_or_null
                     (statement
                      (statement_item
                       (system_tf_call (system_tf_identifier)
                        (list_of_arguments_parent (
                         (expression
                          (primary
                           (primary_literal
                            (string_literal " "))))
                         )))
                       ;)))
                    (statement_or_null
                     (statement
                      (statement_item
                       (jump_statement return
                        (expression
                         (primary null))
                        ;))))
                    end)))))))))))))
       endfunction))))
   endclass))
 (ERROR
  (module_header
   (module_keyword module)
   (simple_identifier))
  ;
  (module_or_generate_item
   (package_or_generate_item_declaration
    (net_declaration (simple_identifier)
     (list_of_net_decl_assignments
      (net_decl_assignment (simple_identifier)))
     ;)))
  initial begin
  (variable_lvalue (simple_identifier))
  (assignment_operator =)
  (ERROR
   (package_scope
    (package_identifier (simple_identifier))
    ::)
   (simple_identifier) ( " (simple_identifier)
   (casting_type
    (constant_primary
     (primary_literal
      (string_literal " "))))
   (simple_identifier)
   (casting_type
    (constant_primary
     (primary_literal
      (string_literal " "))))
   (simple_identifier))
  "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant