@@ -612,106 +612,72 @@ def convertTypeToCpp(self, type_declaration: list[Any] | dict[str, Any] | str) -
612612 if not isinstance (type_declaration , list ):
613613 return self .convertTypeToCpp ([type_declaration ])
614614
615- if len (type_declaration ) == 1 :
616- if type_declaration [0 ] in ("null" , "https://w3id.org/cwl/salad#null" ):
615+ if len (type_declaration ) > 1 :
616+ type_declaration = list (map (self .convertTypeToCpp , type_declaration ))
617+ type_declaration = ", " .join (type_declaration )
618+ return f"std::variant<{ type_declaration } >"
619+
620+ match type_declaration [0 ]:
621+ case "null" | "https://w3id.org/cwl/salad#null" :
617622 return "std::monostate"
618- elif type_declaration [0 ] in (
619- "string" ,
620- "http://www.w3.org/2001/XMLSchema#string" ,
621- ):
623+ case "string" | "http://www.w3.org/2001/XMLSchema#string" :
622624 return "std::string"
623- elif type_declaration [ 0 ] in ( "int" , "http://www.w3.org/2001/XMLSchema#int" ) :
625+ case "int" | "http://www.w3.org/2001/XMLSchema#int" :
624626 return "int32_t"
625- elif type_declaration [0 ] in (
626- "long" ,
627- "http://www.w3.org/2001/XMLSchema#long" ,
628- ):
627+ case "long" | "http://www.w3.org/2001/XMLSchema#long" :
629628 return "int64_t"
630- elif type_declaration [0 ] in (
631- "float" ,
632- "http://www.w3.org/2001/XMLSchema#float" ,
633- ):
629+ case "float" | "http://www.w3.org/2001/XMLSchema#float" :
634630 return "float"
635- elif type_declaration [0 ] in (
636- "double" ,
637- "http://www.w3.org/2001/XMLSchema#double" ,
638- ):
631+ case "double" | "http://www.w3.org/2001/XMLSchema#double" :
639632 return "double"
640- elif type_declaration [0 ] in (
641- "boolean" ,
642- "http://www.w3.org/2001/XMLSchema#boolean" ,
643- ):
633+ case "boolean" | "http://www.w3.org/2001/XMLSchema#boolean" :
644634 return "bool"
645- elif type_declaration [ 0 ] == "https://w3id.org/cwl/salad#Any" :
635+ case "https://w3id.org/cwl/salad#Any" :
646636 return "std::any"
647- elif type_declaration [ 0 ] == "https://w3id.org/cwl/cwl#Expression" :
637+ case "https://w3id.org/cwl/cwl#Expression" :
648638 return "cwl_expression_string"
649- elif type_declaration [0 ] in (
650- "PrimitiveType" ,
651- "https://w3id.org/cwl/salad#PrimitiveType" ,
652- ):
639+ case "PrimitiveType" | "https://w3id.org/cwl/salad#PrimitiveType" :
653640 return "std::variant<bool, int32_t, int64_t, float, double, std::string>"
654- elif isinstance (type_declaration [0 ], dict ):
655- if "type" in type_declaration [0 ] and type_declaration [0 ]["type" ] in (
656- "enum" ,
657- "https://w3id.org/cwl/salad#enum" ,
658- ):
659- name = type_declaration [0 ]["name" ]
660- if name not in self .enumDefinitions :
661- self .enumDefinitions [name ] = EnumDefinition (
662- type_declaration [0 ]["name" ],
663- list (map (shortname , type_declaration [0 ]["symbols" ])),
664- )
665- if len (name .split ("#" )) != 2 :
666- return safename (name )
667- (namespace , classname ) = name .split ("#" )
668- return safenamespacename (namespace ) + "::" + safename (classname )
669- elif "type" in type_declaration [0 ] and type_declaration [0 ]["type" ] in (
670- "array" ,
671- "https://w3id.org/cwl/salad#array" ,
672- ):
673- items = type_declaration [0 ]["items" ]
674- if isinstance (items , list ):
675- ts = [self .convertTypeToCpp (i ) for i in items ]
676- name = ", " .join (ts )
677- return f"std::vector<std::variant<{ name } >>"
678- else :
679- i = self .convertTypeToCpp (items )
680- return f"std::vector<{ i } >"
681- elif "type" in type_declaration [0 ] and type_declaration [0 ]["type" ] in (
682- "map" ,
683- "https://w3id.org/cwl/salad#map" ,
684- ):
685- values = type_declaration [0 ]["values" ]
686- if isinstance (values , list ):
687- ts = [self .convertTypeToCpp (i ) for i in values ]
688- name = ", " .join (ts )
689- return f"std::map<std::string, std::variant<{ name } >>"
690- else :
691- i = self .convertTypeToCpp (values )
692- return f"std::map<std::string, { i } >"
693- elif "type" in type_declaration [0 ] and type_declaration [0 ]["type" ] in (
694- "record" ,
695- "https://w3id.org/cwl/salad#record" ,
696- ):
697- n = type_declaration [0 ]["name" ]
698- (namespace , classname ) = split_name (n )
699- return safenamespacename (namespace ) + "::" + safename (classname )
700-
641+ case {"type" : "enum" | "https://w3id.org/cwl/salad#enum" }:
642+ name = type_declaration [0 ]["name" ]
643+ if name not in self .enumDefinitions :
644+ self .enumDefinitions [name ] = EnumDefinition (
645+ type_declaration [0 ]["name" ],
646+ list (map (shortname , type_declaration [0 ]["symbols" ])),
647+ )
648+ if len (name .split ("#" )) != 2 :
649+ return safename (name )
650+ (namespace , classname ) = name .split ("#" )
651+ return safenamespacename (namespace ) + "::" + safename (classname )
652+ case {"type" : "array" | "https://w3id.org/cwl/salad#array" , "items" : list (items )}:
653+ ts = [self .convertTypeToCpp (i ) for i in items ]
654+ name = ", " .join (ts )
655+ return f"std::vector<std::variant<{ name } >>"
656+ case {"type" : "array" | "https://w3id.org/cwl/salad#array" , "items" : items }:
657+ i = self .convertTypeToCpp (items )
658+ return f"std::vector<{ i } >"
659+ case {"type" : "map" | "https://w3id.org/cwl/salad#map" , "values" : list (values )}:
660+ ts = [self .convertTypeToCpp (i ) for i in values ]
661+ name = ", " .join (ts )
662+ return f"std::map<std::string, std::variant<{ name } >>"
663+ case {"type" : "map" | "https://w3id.org/cwl/salad#map" , "values" : values }:
664+ i = self .convertTypeToCpp (values )
665+ return f"std::map<std::string, { i } >"
666+ case {"type" : "record" | "https://w3id.org/cwl/salad#record" }:
667+ n = type_declaration [0 ]["name" ]
668+ (namespace , classname ) = split_name (n )
669+ return safenamespacename (namespace ) + "::" + safename (classname )
670+ case dict ():
701671 n = type_declaration [0 ]["type" ]
702672 (namespace , classname ) = split_name (n )
703673 return safenamespacename (namespace ) + "::" + safename (classname )
704674
705- if len (type_declaration [0 ].split ("#" )) != 2 :
706- _logger .debug (f"// something weird2 about { type_declaration [0 ]} " )
707- return cast (str , type_declaration [0 ])
708-
709- (namespace , classname ) = split_name (type_declaration [0 ])
710- return safenamespacename (namespace ) + "::" + safename (classname )
675+ if len (type_declaration [0 ].split ("#" )) != 2 :
676+ _logger .debug (f"// something weird2 about { type_declaration [0 ]} " )
677+ return cast (str , type_declaration [0 ])
711678
712- type_declaration = list (map (self .convertTypeToCpp , type_declaration ))
713- type_declaration = ", " .join (type_declaration )
714- return f"std::variant<{ type_declaration } >"
679+ (namespace , classname ) = split_name (type_declaration [0 ])
680+ return safenamespacename (namespace ) + "::" + safename (classname )
715681
716682 def epilogue (self , root_loader : TypeDef | None ) -> None :
717683 """Trigger to generate the epilouge code."""
0 commit comments