Coverage for skema/program_analysis/CAST2FN/model/cast/ast_node.py: 60%

43 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1# coding: utf-8 

2 

3""" 

4 SKEMA Common Abstract Syntax Tree (CAST) 

5 

6 This document outlines the structure of the CAST that will be used as a generic representation of the semantics of a program written in any language. This will be used when creating functions networks from programs using the SKEMA Program Analysis pipeline. __Generating Class Structure__ To automatically generate Python or Java models corresponding to this document, you can use [swagger-codegen](https://swagger.io/tools/swagger-codegen/). We can use this to generate client code based off of this spec that will also generate the class structure. 1. Install via the method described for your operating system [here](https://github.com/swagger-api/swagger-codegen#Prerequisites). Make sure to install a version after 3.0 that will support openapi 3. 2. Run swagger-codegen with the options in the example below. The URL references where the yaml for this documentation is stored on github. Make sure to replace CURRENT_VERSION with the correct version. To generate Java classes rather, change the `-l python` to `-l java`. Change the value to the `-o` option to the desired output location. ``` swagger-codegen generate -l python -o ./client -i https://raw.githubusercontent.com/ml4ai/automates-v2/master/docs/source/cast_v{CURRENT_VERSION}.yaml ``` 3. Once it executes, the client code will be generated at your specified location. For python, the classes will be located in `$OUTPUT_PATH/swagger_client/models/`. For java, they will be located in `$OUTPUT_PATH/src/main/java/io/swagger/client/model/` # noqa: E501 

7 

8 OpenAPI spec version: 1.2.6 

9  

10 Generated by: https://github.com/swagger-api/swagger-codegen.git 

11""" 

12 

13import pprint 

14import re # noqa: F401 

15 

16import six 

17 

18class AstNode(object): 

19 """NOTE: This class is auto generated by the swagger code generator program. 

20 

21 Do not edit the class manually. 

22 """ 

23 """ 

24 Attributes: 

25 swagger_types (dict): The key is attribute name 

26 and the value is attribute type. 

27 attribute_map (dict): The key is attribute name 

28 and the value is json key in definition. 

29 """ 

30 swagger_types = { 

31 'source_refs': 'list[SourceRef]' 

32 } 

33 

34 attribute_map = { 

35 'source_refs': 'source_refs' 

36 } 

37 

38 def __init__(self, source_refs=None): # noqa: E501 

39 """AstNode - a model defined in Swagger""" # noqa: E501 

40 self._source_refs = None 

41 self.discriminator = None 

42 if source_refs is not None: 

43 self.source_refs = source_refs 

44 

45 @property 

46 def source_refs(self): 

47 """Gets the source_refs of this AstNode. # noqa: E501 

48 

49 

50 :return: The source_refs of this AstNode. # noqa: E501 

51 :rtype: list[SourceRef] 

52 """ 

53 return self._source_refs 

54 

55 @source_refs.setter 

56 def source_refs(self, source_refs): 

57 """Sets the source_refs of this AstNode. 

58 

59 

60 :param source_refs: The source_refs of this AstNode. # noqa: E501 

61 :type: list[SourceRef] 

62 """ 

63 

64 self._source_refs = source_refs 

65 

66 def to_dict(self): 

67 """Returns the model properties as a dict""" 

68 result = {} 

69 

70 for attr, _ in six.iteritems(self.swagger_types): 

71 value = getattr(self, attr) 

72 if isinstance(value, list): 

73 result[attr] = list(map( 

74 lambda x: x.to_dict() if hasattr(x, "to_dict") else x, 

75 value 

76 )) 

77 elif hasattr(value, "to_dict"): 

78 result[attr] = value.to_dict() 

79 elif isinstance(value, dict): 

80 result[attr] = dict(map( 

81 lambda item: (item[0], item[1].to_dict()) 

82 if hasattr(item[1], "to_dict") else item, 

83 value.items() 

84 )) 

85 else: 

86 result[attr] = value 

87 if issubclass(AstNode, dict): 

88 for key, value in self.items(): 

89 result[key] = value 

90 

91 return result 

92 

93 def to_str(self): 

94 """Returns the string representation of the model""" 

95 return pprint.pformat(self.to_dict()) 

96 

97 def __repr__(self): 

98 """For `print` and `pprint`""" 

99 return self.to_str() 

100 

101 def __eq__(self, other): 

102 """Returns true if both objects are equal""" 

103 if not isinstance(other, AstNode): 

104 return False 

105 

106 return self.__dict__ == other.__dict__ 

107 

108 def __ne__(self, other): 

109 """Returns true if both objects are not equal""" 

110 return not self == other