ast_nodes.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #include "ast_nodes.h"
  2. namespace NYql::NJsonPath {
  3. TAstNode::TAstNode(TPosition pos)
  4. : Pos(pos)
  5. {
  6. }
  7. TPosition TAstNode::GetPos() const {
  8. return Pos;
  9. }
  10. EReturnType TAstNode::GetReturnType() const {
  11. return EReturnType::Any;
  12. }
  13. TRootNode::TRootNode(TPosition pos, TAstNodePtr expr, EJsonPathMode mode)
  14. : TAstNode(pos)
  15. , Expr(expr)
  16. , Mode(mode)
  17. {
  18. }
  19. const TAstNodePtr TRootNode::GetExpr() const {
  20. return Expr;
  21. }
  22. EJsonPathMode TRootNode::GetMode() const {
  23. return Mode;
  24. }
  25. void TRootNode::Accept(IAstNodeVisitor& visitor) const {
  26. return visitor.VisitRoot(*this);
  27. }
  28. EReturnType TRootNode::GetReturnType() const {
  29. return Expr->GetReturnType();
  30. }
  31. TContextObjectNode::TContextObjectNode(TPosition pos)
  32. : TAstNode(pos)
  33. {
  34. }
  35. void TContextObjectNode::Accept(IAstNodeVisitor& visitor) const {
  36. return visitor.VisitContextObject(*this);
  37. }
  38. TVariableNode::TVariableNode(TPosition pos, const TString& name)
  39. : TAstNode(pos)
  40. , Name(name)
  41. {
  42. }
  43. const TString& TVariableNode::GetName() const {
  44. return Name;
  45. }
  46. void TVariableNode::Accept(IAstNodeVisitor& visitor) const {
  47. visitor.VisitVariable(*this);
  48. }
  49. TLastArrayIndexNode::TLastArrayIndexNode(TPosition pos)
  50. : TAstNode(pos)
  51. {
  52. }
  53. void TLastArrayIndexNode::Accept(IAstNodeVisitor& visitor) const {
  54. visitor.VisitLastArrayIndex(*this);
  55. }
  56. TNumberLiteralNode::TNumberLiteralNode(TPosition pos, double value)
  57. : TAstNode(pos)
  58. , Value(value)
  59. {
  60. }
  61. double TNumberLiteralNode::GetValue() const {
  62. return Value;
  63. }
  64. void TNumberLiteralNode::Accept(IAstNodeVisitor& visitor) const {
  65. return visitor.VisitNumberLiteral(*this);
  66. }
  67. TMemberAccessNode::TMemberAccessNode(TPosition pos, const TString& member, TAstNodePtr input)
  68. : TAstNode(pos)
  69. , Member(member)
  70. , Input(input)
  71. {
  72. }
  73. const TStringBuf TMemberAccessNode::GetMember() const {
  74. return Member;
  75. }
  76. const TAstNodePtr TMemberAccessNode::GetInput() const {
  77. return Input;
  78. }
  79. void TMemberAccessNode::Accept(IAstNodeVisitor& visitor) const {
  80. return visitor.VisitMemberAccess(*this);
  81. }
  82. TWildcardMemberAccessNode::TWildcardMemberAccessNode(TPosition pos, TAstNodePtr input)
  83. : TAstNode(pos)
  84. , Input(input)
  85. {
  86. }
  87. const TAstNodePtr TWildcardMemberAccessNode::GetInput() const {
  88. return Input;
  89. }
  90. void TWildcardMemberAccessNode::Accept(IAstNodeVisitor& visitor) const {
  91. return visitor.VisitWildcardMemberAccess(*this);
  92. }
  93. TArrayAccessNode::TArrayAccessNode(TPosition pos, TVector<TSubscript> subscripts, TAstNodePtr input)
  94. : TAstNode(pos)
  95. , Subscripts(subscripts)
  96. , Input(input)
  97. {
  98. }
  99. const TVector<TArrayAccessNode::TSubscript>& TArrayAccessNode::GetSubscripts() const {
  100. return Subscripts;
  101. }
  102. const TAstNodePtr TArrayAccessNode::GetInput() const {
  103. return Input;
  104. }
  105. void TArrayAccessNode::Accept(IAstNodeVisitor& visitor) const {
  106. return visitor.VisitArrayAccess(*this);
  107. }
  108. TWildcardArrayAccessNode::TWildcardArrayAccessNode(TPosition pos, TAstNodePtr input)
  109. : TAstNode(pos)
  110. , Input(input)
  111. {
  112. }
  113. const TAstNodePtr TWildcardArrayAccessNode::GetInput() const {
  114. return Input;
  115. }
  116. void TWildcardArrayAccessNode::Accept(IAstNodeVisitor& visitor) const {
  117. return visitor.VisitWildcardArrayAccess(*this);
  118. }
  119. TUnaryOperationNode::TUnaryOperationNode(TPosition pos, EUnaryOperation op, TAstNodePtr expr)
  120. : TAstNode(pos)
  121. , Operation(op)
  122. , Expr(expr)
  123. {
  124. }
  125. EUnaryOperation TUnaryOperationNode::GetOp() const {
  126. return Operation;
  127. }
  128. const TAstNodePtr TUnaryOperationNode::GetExpr() const {
  129. return Expr;
  130. }
  131. void TUnaryOperationNode::Accept(IAstNodeVisitor& visitor) const {
  132. return visitor.VisitUnaryOperation(*this);
  133. }
  134. EReturnType TUnaryOperationNode::GetReturnType() const {
  135. return Operation == EUnaryOperation::Not ? EReturnType::Bool : EReturnType::Any;
  136. }
  137. TBinaryOperationNode::TBinaryOperationNode(TPosition pos, EBinaryOperation op, TAstNodePtr leftExpr, TAstNodePtr rightExpr)
  138. : TAstNode(pos)
  139. , Operation(op)
  140. , LeftExpr(leftExpr)
  141. , RightExpr(rightExpr)
  142. {
  143. }
  144. EBinaryOperation TBinaryOperationNode::GetOp() const {
  145. return Operation;
  146. }
  147. const TAstNodePtr TBinaryOperationNode::GetLeftExpr() const {
  148. return LeftExpr;
  149. }
  150. const TAstNodePtr TBinaryOperationNode::GetRightExpr() const {
  151. return RightExpr;
  152. }
  153. void TBinaryOperationNode::Accept(IAstNodeVisitor& visitor) const {
  154. return visitor.VisitBinaryOperation(*this);
  155. }
  156. EReturnType TBinaryOperationNode::GetReturnType() const {
  157. switch (Operation) {
  158. case EBinaryOperation::Less:
  159. case EBinaryOperation::LessEqual:
  160. case EBinaryOperation::Greater:
  161. case EBinaryOperation::GreaterEqual:
  162. case EBinaryOperation::Equal:
  163. case EBinaryOperation::NotEqual:
  164. case EBinaryOperation::And:
  165. case EBinaryOperation::Or:
  166. return EReturnType::Bool;
  167. default:
  168. return EReturnType::Any;
  169. }
  170. }
  171. TBooleanLiteralNode::TBooleanLiteralNode(TPosition pos, bool value)
  172. : TAstNode(pos)
  173. , Value(value)
  174. {
  175. }
  176. bool TBooleanLiteralNode::GetValue() const {
  177. return Value;
  178. }
  179. void TBooleanLiteralNode::Accept(IAstNodeVisitor& visitor) const {
  180. return visitor.VisitBooleanLiteral(*this);
  181. }
  182. TNullLiteralNode::TNullLiteralNode(TPosition pos)
  183. : TAstNode(pos)
  184. {
  185. }
  186. void TNullLiteralNode::Accept(IAstNodeVisitor& visitor) const {
  187. return visitor.VisitNullLiteral(*this);
  188. }
  189. TStringLiteralNode::TStringLiteralNode(TPosition pos, const TString& value)
  190. : TAstNode(pos)
  191. , Value(value)
  192. {
  193. }
  194. const TString& TStringLiteralNode::GetValue() const {
  195. return Value;
  196. }
  197. void TStringLiteralNode::Accept(IAstNodeVisitor& visitor) const {
  198. return visitor.VisitStringLiteral(*this);
  199. }
  200. TFilterObjectNode::TFilterObjectNode(TPosition pos)
  201. : TAstNode(pos)
  202. {
  203. }
  204. void TFilterObjectNode::Accept(IAstNodeVisitor& visitor) const {
  205. return visitor.VisitFilterObject(*this);
  206. }
  207. TFilterPredicateNode::TFilterPredicateNode(TPosition pos, TAstNodePtr predicate, TAstNodePtr input)
  208. : TAstNode(pos)
  209. , Predicate(predicate)
  210. , Input(input)
  211. {
  212. }
  213. const TAstNodePtr TFilterPredicateNode::GetPredicate() const {
  214. return Predicate;
  215. }
  216. const TAstNodePtr TFilterPredicateNode::GetInput() const {
  217. return Input;
  218. }
  219. void TFilterPredicateNode::Accept(IAstNodeVisitor& visitor) const {
  220. return visitor.VisitFilterPredicate(*this);
  221. }
  222. TMethodCallNode::TMethodCallNode(TPosition pos, EMethodType type, TAstNodePtr input)
  223. : TAstNode(pos)
  224. , Type(type)
  225. , Input(input)
  226. {
  227. }
  228. EMethodType TMethodCallNode::GetType() const {
  229. return Type;
  230. }
  231. const TAstNodePtr TMethodCallNode::GetInput() const {
  232. return Input;
  233. }
  234. void TMethodCallNode::Accept(IAstNodeVisitor& visitor) const {
  235. return visitor.VisitMethodCall(*this);
  236. }
  237. TStartsWithPredicateNode::TStartsWithPredicateNode(TPosition pos, TAstNodePtr input, TAstNodePtr prefix)
  238. : TAstNode(pos)
  239. , Input(input)
  240. , Prefix(prefix)
  241. {
  242. }
  243. const TAstNodePtr TStartsWithPredicateNode::GetInput() const {
  244. return Input;
  245. }
  246. const TAstNodePtr TStartsWithPredicateNode::GetPrefix() const {
  247. return Prefix;
  248. }
  249. EReturnType TStartsWithPredicateNode::GetReturnType() const {
  250. return EReturnType::Bool;
  251. }
  252. void TStartsWithPredicateNode::Accept(IAstNodeVisitor& visitor) const {
  253. return visitor.VisitStartsWithPredicate(*this);
  254. }
  255. TExistsPredicateNode::TExistsPredicateNode(TPosition pos, TAstNodePtr input)
  256. : TAstNode(pos)
  257. , Input(input)
  258. {
  259. }
  260. const TAstNodePtr TExistsPredicateNode::GetInput() const {
  261. return Input;
  262. }
  263. EReturnType TExistsPredicateNode::GetReturnType() const {
  264. return EReturnType::Bool;
  265. }
  266. void TExistsPredicateNode::Accept(IAstNodeVisitor& visitor) const {
  267. return visitor.VisitExistsPredicate(*this);
  268. }
  269. TIsUnknownPredicateNode::TIsUnknownPredicateNode(TPosition pos, TAstNodePtr input)
  270. : TAstNode(pos)
  271. , Input(input)
  272. {
  273. }
  274. const TAstNodePtr TIsUnknownPredicateNode::GetInput() const {
  275. return Input;
  276. }
  277. EReturnType TIsUnknownPredicateNode::GetReturnType() const {
  278. return EReturnType::Bool;
  279. }
  280. void TIsUnknownPredicateNode::Accept(IAstNodeVisitor& visitor) const {
  281. return visitor.VisitIsUnknownPredicate(*this);
  282. }
  283. TLikeRegexPredicateNode::TLikeRegexPredicateNode(TPosition pos, TAstNodePtr input, NReWrapper::IRePtr&& regex)
  284. : TAstNode(pos)
  285. , Input(input)
  286. , Regex(std::move(regex))
  287. {
  288. }
  289. const TAstNodePtr TLikeRegexPredicateNode::GetInput() const {
  290. return Input;
  291. }
  292. const NReWrapper::IRePtr& TLikeRegexPredicateNode::GetRegex() const {
  293. return Regex;
  294. }
  295. EReturnType TLikeRegexPredicateNode::GetReturnType() const {
  296. return EReturnType::Bool;
  297. }
  298. void TLikeRegexPredicateNode::Accept(IAstNodeVisitor& visitor) const {
  299. return visitor.VisitLikeRegexPredicate(*this);
  300. }
  301. }