| 1 | // Copyright 2018 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Package overloads defines the internal overload identifiers for function and |
| 16 | // operator overloads. |
| 17 | package overloads |
| 18 | |
| 19 | // Boolean logic overloads |
| 20 | const ( |
| 21 | Conditional = "conditional" |
| 22 | LogicalAnd = "logical_and" |
| 23 | LogicalOr = "logical_or" |
| 24 | LogicalNot = "logical_not" |
| 25 | NotStrictlyFalse = "not_strictly_false" |
| 26 | Equals = "equals" |
| 27 | NotEquals = "not_equals" |
| 28 | LessBool = "less_bool" |
| 29 | LessInt64 = "less_int64" |
| 30 | LessInt64Double = "less_int64_double" |
| 31 | LessInt64Uint64 = "less_int64_uint64" |
| 32 | LessUint64 = "less_uint64" |
| 33 | LessUint64Double = "less_uint64_double" |
| 34 | LessUint64Int64 = "less_uint64_int64" |
| 35 | LessDouble = "less_double" |
| 36 | LessDoubleInt64 = "less_double_int64" |
| 37 | LessDoubleUint64 = "less_double_uint64" |
| 38 | LessString = "less_string" |
| 39 | LessBytes = "less_bytes" |
| 40 | LessTimestamp = "less_timestamp" |
| 41 | LessDuration = "less_duration" |
| 42 | LessEqualsBool = "less_equals_bool" |
| 43 | LessEqualsInt64 = "less_equals_int64" |
| 44 | LessEqualsInt64Double = "less_equals_int64_double" |
| 45 | LessEqualsInt64Uint64 = "less_equals_int64_uint64" |
| 46 | LessEqualsUint64 = "less_equals_uint64" |
| 47 | LessEqualsUint64Double = "less_equals_uint64_double" |
| 48 | LessEqualsUint64Int64 = "less_equals_uint64_int64" |
| 49 | LessEqualsDouble = "less_equals_double" |
| 50 | LessEqualsDoubleInt64 = "less_equals_double_int64" |
| 51 | LessEqualsDoubleUint64 = "less_equals_double_uint64" |
| 52 | LessEqualsString = "less_equals_string" |
| 53 | LessEqualsBytes = "less_equals_bytes" |
| 54 | LessEqualsTimestamp = "less_equals_timestamp" |
| 55 | LessEqualsDuration = "less_equals_duration" |
| 56 | GreaterBool = "greater_bool" |
| 57 | GreaterInt64 = "greater_int64" |
| 58 | GreaterInt64Double = "greater_int64_double" |
| 59 | GreaterInt64Uint64 = "greater_int64_uint64" |
| 60 | GreaterUint64 = "greater_uint64" |
| 61 | GreaterUint64Double = "greater_uint64_double" |
| 62 | GreaterUint64Int64 = "greater_uint64_int64" |
| 63 | GreaterDouble = "greater_double" |
| 64 | GreaterDoubleInt64 = "greater_double_int64" |
| 65 | GreaterDoubleUint64 = "greater_double_uint64" |
| 66 | GreaterString = "greater_string" |
| 67 | GreaterBytes = "greater_bytes" |
| 68 | GreaterTimestamp = "greater_timestamp" |
| 69 | GreaterDuration = "greater_duration" |
| 70 | GreaterEqualsBool = "greater_equals_bool" |
| 71 | GreaterEqualsInt64 = "greater_equals_int64" |
| 72 | GreaterEqualsInt64Double = "greater_equals_int64_double" |
| 73 | GreaterEqualsInt64Uint64 = "greater_equals_int64_uint64" |
| 74 | GreaterEqualsUint64 = "greater_equals_uint64" |
| 75 | GreaterEqualsUint64Double = "greater_equals_uint64_double" |
| 76 | GreaterEqualsUint64Int64 = "greater_equals_uint64_int64" |
| 77 | GreaterEqualsDouble = "greater_equals_double" |
| 78 | GreaterEqualsDoubleInt64 = "greater_equals_double_int64" |
| 79 | GreaterEqualsDoubleUint64 = "greater_equals_double_uint64" |
| 80 | GreaterEqualsString = "greater_equals_string" |
| 81 | GreaterEqualsBytes = "greater_equals_bytes" |
| 82 | GreaterEqualsTimestamp = "greater_equals_timestamp" |
| 83 | GreaterEqualsDuration = "greater_equals_duration" |
| 84 | ) |
| 85 | |
| 86 | // Math overloads |
| 87 | const ( |
| 88 | AddInt64 = "add_int64" |
| 89 | AddUint64 = "add_uint64" |
| 90 | AddDouble = "add_double" |
| 91 | AddString = "add_string" |
| 92 | AddBytes = "add_bytes" |
| 93 | AddList = "add_list" |
| 94 | AddTimestampDuration = "add_timestamp_duration" |
| 95 | AddDurationTimestamp = "add_duration_timestamp" |
| 96 | AddDurationDuration = "add_duration_duration" |
| 97 | SubtractInt64 = "subtract_int64" |
| 98 | SubtractUint64 = "subtract_uint64" |
| 99 | SubtractDouble = "subtract_double" |
| 100 | SubtractTimestampTimestamp = "subtract_timestamp_timestamp" |
| 101 | SubtractTimestampDuration = "subtract_timestamp_duration" |
| 102 | SubtractDurationDuration = "subtract_duration_duration" |
| 103 | MultiplyInt64 = "multiply_int64" |
| 104 | MultiplyUint64 = "multiply_uint64" |
| 105 | MultiplyDouble = "multiply_double" |
| 106 | DivideInt64 = "divide_int64" |
| 107 | DivideUint64 = "divide_uint64" |
| 108 | DivideDouble = "divide_double" |
| 109 | ModuloInt64 = "modulo_int64" |
| 110 | ModuloUint64 = "modulo_uint64" |
| 111 | NegateInt64 = "negate_int64" |
| 112 | NegateDouble = "negate_double" |
| 113 | ) |
| 114 | |
| 115 | // Index overloads |
| 116 | const ( |
| 117 | IndexList = "index_list" |
| 118 | IndexMap = "index_map" |
| 119 | IndexMessage = "index_message" // TODO: introduce concept of types.Message |
| 120 | ) |
| 121 | |
| 122 | // In operators |
| 123 | const ( |
| 124 | DeprecatedIn = "in" |
| 125 | InList = "in_list" |
| 126 | InMap = "in_map" |
| 127 | InMessage = "in_message" // TODO: introduce concept of types.Message |
| 128 | ) |
| 129 | |
| 130 | // Size overloads |
| 131 | const ( |
| 132 | Size = "size" |
| 133 | SizeString = "size_string" |
| 134 | SizeBytes = "size_bytes" |
| 135 | SizeList = "size_list" |
| 136 | SizeMap = "size_map" |
| 137 | SizeStringInst = "string_size" |
| 138 | SizeBytesInst = "bytes_size" |
| 139 | SizeListInst = "list_size" |
| 140 | SizeMapInst = "map_size" |
| 141 | ) |
| 142 | |
| 143 | // String function names. |
| 144 | const ( |
| 145 | Contains = "contains" |
| 146 | EndsWith = "endsWith" |
| 147 | Matches = "matches" |
| 148 | StartsWith = "startsWith" |
| 149 | ) |
| 150 | |
| 151 | // Extension function overloads with complex behaviors that need to be referenced in runtime and static analysis cost computations. |
| 152 | const ( |
| 153 | ExtQuoteString = "strings_quote" |
| 154 | ) |
| 155 | |
| 156 | // String function overload names. |
| 157 | const ( |
| 158 | ContainsString = "contains_string" |
| 159 | EndsWithString = "ends_with_string" |
| 160 | MatchesString = "matches_string" |
| 161 | StartsWithString = "starts_with_string" |
| 162 | ) |
| 163 | |
| 164 | // Extension function overloads with complex behaviors that need to be referenced in runtime and static analysis cost computations. |
| 165 | const ( |
| 166 | ExtFormatString = "string_format" |
| 167 | ) |
| 168 | |
| 169 | // Time-based functions. |
| 170 | const ( |
| 171 | TimeGetFullYear = "getFullYear" |
| 172 | TimeGetMonth = "getMonth" |
| 173 | TimeGetDayOfYear = "getDayOfYear" |
| 174 | TimeGetDate = "getDate" |
| 175 | TimeGetDayOfMonth = "getDayOfMonth" |
| 176 | TimeGetDayOfWeek = "getDayOfWeek" |
| 177 | TimeGetHours = "getHours" |
| 178 | TimeGetMinutes = "getMinutes" |
| 179 | TimeGetSeconds = "getSeconds" |
| 180 | TimeGetMilliseconds = "getMilliseconds" |
| 181 | ) |
| 182 | |
| 183 | // Timestamp overloads for time functions without timezones. |
| 184 | const ( |
| 185 | TimestampToYear = "timestamp_to_year" |
| 186 | TimestampToMonth = "timestamp_to_month" |
| 187 | TimestampToDayOfYear = "timestamp_to_day_of_year" |
| 188 | TimestampToDayOfMonthZeroBased = "timestamp_to_day_of_month" |
| 189 | TimestampToDayOfMonthOneBased = "timestamp_to_day_of_month_1_based" |
| 190 | TimestampToDayOfWeek = "timestamp_to_day_of_week" |
| 191 | TimestampToHours = "timestamp_to_hours" |
| 192 | TimestampToMinutes = "timestamp_to_minutes" |
| 193 | TimestampToSeconds = "timestamp_to_seconds" |
| 194 | TimestampToMilliseconds = "timestamp_to_milliseconds" |
| 195 | ) |
| 196 | |
| 197 | // Timestamp overloads for time functions with timezones. |
| 198 | const ( |
| 199 | TimestampToYearWithTz = "timestamp_to_year_with_tz" |
| 200 | TimestampToMonthWithTz = "timestamp_to_month_with_tz" |
| 201 | TimestampToDayOfYearWithTz = "timestamp_to_day_of_year_with_tz" |
| 202 | TimestampToDayOfMonthZeroBasedWithTz = "timestamp_to_day_of_month_with_tz" |
| 203 | TimestampToDayOfMonthOneBasedWithTz = "timestamp_to_day_of_month_1_based_with_tz" |
| 204 | TimestampToDayOfWeekWithTz = "timestamp_to_day_of_week_with_tz" |
| 205 | TimestampToHoursWithTz = "timestamp_to_hours_with_tz" |
| 206 | TimestampToMinutesWithTz = "timestamp_to_minutes_with_tz" |
| 207 | TimestampToSecondsWithTz = "timestamp_to_seconds_tz" |
| 208 | TimestampToMillisecondsWithTz = "timestamp_to_milliseconds_with_tz" |
| 209 | ) |
| 210 | |
| 211 | // Duration overloads for time functions. |
| 212 | const ( |
| 213 | DurationToHours = "duration_to_hours" |
| 214 | DurationToMinutes = "duration_to_minutes" |
| 215 | DurationToSeconds = "duration_to_seconds" |
| 216 | DurationToMilliseconds = "duration_to_milliseconds" |
| 217 | ) |
| 218 | |
| 219 | // Type conversion methods and overloads |
| 220 | const ( |
| 221 | TypeConvertInt = "int" |
| 222 | TypeConvertUint = "uint" |
| 223 | TypeConvertDouble = "double" |
| 224 | TypeConvertBool = "bool" |
| 225 | TypeConvertString = "string" |
| 226 | TypeConvertBytes = "bytes" |
| 227 | TypeConvertTimestamp = "timestamp" |
| 228 | TypeConvertDuration = "duration" |
| 229 | TypeConvertType = "type" |
| 230 | TypeConvertDyn = "dyn" |
| 231 | ) |
| 232 | |
| 233 | // Int conversion functions. |
| 234 | const ( |
| 235 | IntToInt = "int64_to_int64" |
| 236 | UintToInt = "uint64_to_int64" |
| 237 | DoubleToInt = "double_to_int64" |
| 238 | StringToInt = "string_to_int64" |
| 239 | TimestampToInt = "timestamp_to_int64" |
| 240 | DurationToInt = "duration_to_int64" |
| 241 | ) |
| 242 | |
| 243 | // Uint conversion functions. |
| 244 | const ( |
| 245 | UintToUint = "uint64_to_uint64" |
| 246 | IntToUint = "int64_to_uint64" |
| 247 | DoubleToUint = "double_to_uint64" |
| 248 | StringToUint = "string_to_uint64" |
| 249 | ) |
| 250 | |
| 251 | // Double conversion functions. |
| 252 | const ( |
| 253 | DoubleToDouble = "double_to_double" |
| 254 | IntToDouble = "int64_to_double" |
| 255 | UintToDouble = "uint64_to_double" |
| 256 | StringToDouble = "string_to_double" |
| 257 | ) |
| 258 | |
| 259 | // Bool conversion functions. |
| 260 | const ( |
| 261 | BoolToBool = "bool_to_bool" |
| 262 | StringToBool = "string_to_bool" |
| 263 | ) |
| 264 | |
| 265 | // Bytes conversion functions. |
| 266 | const ( |
| 267 | BytesToBytes = "bytes_to_bytes" |
| 268 | StringToBytes = "string_to_bytes" |
| 269 | ) |
| 270 | |
| 271 | // String conversion functions. |
| 272 | const ( |
| 273 | StringToString = "string_to_string" |
| 274 | BoolToString = "bool_to_string" |
| 275 | IntToString = "int64_to_string" |
| 276 | UintToString = "uint64_to_string" |
| 277 | DoubleToString = "double_to_string" |
| 278 | BytesToString = "bytes_to_string" |
| 279 | TimestampToString = "timestamp_to_string" |
| 280 | DurationToString = "duration_to_string" |
| 281 | ) |
| 282 | |
| 283 | // Timestamp conversion functions |
| 284 | const ( |
| 285 | TimestampToTimestamp = "timestamp_to_timestamp" |
| 286 | StringToTimestamp = "string_to_timestamp" |
| 287 | IntToTimestamp = "int64_to_timestamp" |
| 288 | ) |
| 289 | |
| 290 | // Convert duration from string |
| 291 | const ( |
| 292 | DurationToDuration = "duration_to_duration" |
| 293 | StringToDuration = "string_to_duration" |
| 294 | IntToDuration = "int64_to_duration" |
| 295 | ) |
| 296 | |
| 297 | // Convert to dyn |
| 298 | const ( |
| 299 | ToDyn = "to_dyn" |
| 300 | ) |
| 301 | |
| 302 | // Comprehensions helper methods, not directly accessible via a developer. |
| 303 | const ( |
| 304 | Iterator = "@iterator" |
| 305 | HasNext = "@hasNext" |
| 306 | Next = "@next" |
| 307 | ) |
| 308 | |
| 309 | // IsTypeConversionFunction returns whether the input function is a standard library type |
| 310 | // conversion function. |
| 311 | func IsTypeConversionFunction(function string) bool { |
| 312 | switch function { |
| 313 | case TypeConvertBool, |
| 314 | TypeConvertBytes, |
| 315 | TypeConvertDouble, |
| 316 | TypeConvertDuration, |
| 317 | TypeConvertDyn, |
| 318 | TypeConvertInt, |
| 319 | TypeConvertString, |
| 320 | TypeConvertTimestamp, |
| 321 | TypeConvertType, |
| 322 | TypeConvertUint: |
| 323 | return true |
| 324 | default: |
| 325 | return false |
| 326 | } |
| 327 | } |