carbon.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. syntax = "proto2";
  5. package Carbon.Fuzzing;
  6. message LibraryName {
  7. optional string package_name = 1;
  8. optional string path = 2;
  9. }
  10. // Expressions.
  11. message CallExpression {
  12. optional Expression function = 1;
  13. optional Expression argument = 2;
  14. }
  15. message FunctionTypeLiteral {
  16. optional TupleLiteralExpression parameter = 3;
  17. optional Expression return_type = 2;
  18. }
  19. message SimpleMemberAccessExpression {
  20. optional string field = 1;
  21. optional Expression object = 2;
  22. }
  23. message CompoundMemberAccessExpression {
  24. optional Expression object = 1;
  25. optional Expression path = 2;
  26. }
  27. message IndexExpression {
  28. optional Expression object = 1;
  29. optional Expression offset = 2;
  30. }
  31. message OperatorExpression {
  32. enum Operator {
  33. UnknownOperator = 0;
  34. Add = 1;
  35. AddressOf = 2;
  36. And = 3;
  37. Deref = 4;
  38. Eq = 5;
  39. Mul = 6;
  40. Neg = 7;
  41. Not = 8;
  42. Or = 9;
  43. Sub = 10;
  44. Ptr = 11;
  45. BitwiseAnd = 12;
  46. As = 13;
  47. Mod = 14;
  48. Complement = 15;
  49. BitwiseOr = 16;
  50. BitwiseXor = 17;
  51. BitShiftLeft = 18;
  52. BitShiftRight = 19;
  53. Less = 20;
  54. LessEq = 21;
  55. Greater = 22;
  56. GreaterEq = 23;
  57. NotEq = 24;
  58. Div = 25;
  59. }
  60. optional Operator op = 1;
  61. repeated Expression arguments = 2;
  62. }
  63. message TupleLiteralExpression {
  64. repeated Expression fields = 1;
  65. }
  66. message FieldInitializer {
  67. optional string name = 1;
  68. optional Expression expression = 2;
  69. }
  70. message StructLiteralExpression {
  71. repeated FieldInitializer fields = 1;
  72. }
  73. message StructTypeLiteralExpression {
  74. repeated FieldInitializer fields = 1;
  75. }
  76. message IdentifierExpression {
  77. optional string name = 1;
  78. }
  79. message DesignatorExpression {
  80. optional string name = 1;
  81. }
  82. message IfExpression {
  83. optional Expression condition = 1;
  84. optional Expression then_expression = 2;
  85. optional Expression else_expression = 3;
  86. }
  87. message BoolTypeLiteral {}
  88. message BoolLiteral {
  89. optional bool value = 1;
  90. }
  91. message IntTypeLiteral {}
  92. message ContinuationTypeLiteral {}
  93. message IntLiteral {
  94. optional int64 value = 1;
  95. }
  96. message StringLiteral {
  97. optional string value = 1;
  98. }
  99. message StringTypeLiteral {}
  100. message TypeTypeLiteral {}
  101. message UnimplementedExpression {}
  102. message ArrayTypeLiteral {
  103. optional Expression element_type = 1;
  104. optional Expression size = 2;
  105. }
  106. message IsWhereClause {
  107. optional Expression type = 1;
  108. optional Expression constraint = 2;
  109. }
  110. message EqualsWhereClause {
  111. optional Expression lhs = 1;
  112. optional Expression rhs = 2;
  113. }
  114. message RewriteWhereClause {
  115. optional string member_name = 1;
  116. optional Expression replacement = 2;
  117. }
  118. message WhereClause {
  119. oneof kind {
  120. IsWhereClause is = 1;
  121. EqualsWhereClause equals = 2;
  122. RewriteWhereClause rewrite = 3;
  123. }
  124. }
  125. message WhereExpression {
  126. optional Expression base = 1;
  127. repeated WhereClause clauses = 2;
  128. }
  129. message Expression {
  130. oneof kind {
  131. CallExpression call = 1;
  132. FunctionTypeLiteral function_type = 2;
  133. SimpleMemberAccessExpression simple_member_access = 3;
  134. IndexExpression index = 4;
  135. OperatorExpression operator = 5;
  136. TupleLiteralExpression tuple_literal = 6;
  137. StructLiteralExpression struct_literal = 7;
  138. StructTypeLiteralExpression struct_type_literal = 8;
  139. IdentifierExpression identifier = 9;
  140. IfExpression if_expression = 11;
  141. BoolTypeLiteral bool_type_literal = 12;
  142. BoolLiteral bool_literal = 13;
  143. IntTypeLiteral int_type_literal = 14;
  144. ContinuationTypeLiteral continuation_type_literal = 15;
  145. IntLiteral int_literal = 16;
  146. StringLiteral string_literal = 17;
  147. StringTypeLiteral string_type_literal = 18;
  148. TypeTypeLiteral type_type_literal = 19;
  149. UnimplementedExpression unimplemented_expression = 20;
  150. ArrayTypeLiteral array_type_literal = 21;
  151. CompoundMemberAccessExpression compound_member_access = 22;
  152. WhereExpression where = 23;
  153. DesignatorExpression designator = 24;
  154. }
  155. }
  156. // Patterns.
  157. message BindingPattern {
  158. optional string name = 1;
  159. optional Pattern type = 2;
  160. }
  161. message GenericBinding {
  162. optional string name = 1;
  163. optional Expression type = 2;
  164. }
  165. message TuplePattern {
  166. repeated Pattern fields = 1;
  167. }
  168. message AlternativePattern {
  169. optional Expression choice_type = 1;
  170. optional string alternative_name = 2;
  171. optional TuplePattern arguments = 3;
  172. }
  173. message ExpressionPattern {
  174. optional Expression expression = 1;
  175. }
  176. message AutoPattern {}
  177. message VarPattern {
  178. optional Pattern pattern = 1;
  179. }
  180. message AddrPattern {
  181. optional BindingPattern binding_pattern = 1;
  182. }
  183. message Pattern {
  184. oneof kind {
  185. BindingPattern binding_pattern = 1;
  186. TuplePattern tuple_pattern = 2;
  187. AlternativePattern alternative_pattern = 3;
  188. ExpressionPattern expression_pattern = 4;
  189. AutoPattern auto_pattern = 5;
  190. VarPattern var_pattern = 6;
  191. GenericBinding generic_binding = 7;
  192. AddrPattern addr_pattern = 8;
  193. }
  194. }
  195. // Statements.
  196. message ExpressionStatement {
  197. optional Expression expression = 1;
  198. }
  199. message AssignStatement {
  200. enum Operator {
  201. Plain = 0;
  202. Add = 1;
  203. And = 2;
  204. Div = 3;
  205. Mul = 4;
  206. Or = 5;
  207. Sub = 6;
  208. Mod = 7;
  209. Xor = 8;
  210. ShiftLeft = 9;
  211. ShiftRight = 10;
  212. }
  213. optional Expression lhs = 1;
  214. optional Expression rhs = 2;
  215. optional Operator op = 3;
  216. }
  217. message IncrementDecrementStatement {
  218. optional Expression operand = 1;
  219. optional bool is_increment = 2;
  220. }
  221. message VariableDefinitionStatement {
  222. optional Pattern pattern = 1;
  223. optional Expression init = 2;
  224. optional bool is_returned = 3;
  225. }
  226. message IfStatement {
  227. optional Expression condition = 1;
  228. optional BlockStatement then_block = 2;
  229. optional BlockStatement else_block = 3;
  230. }
  231. message ReturnVarStatement {}
  232. message ReturnExpressionStatement {
  233. optional Expression expression = 1; // Can be omitted.
  234. optional bool is_omitted_expression = 2;
  235. }
  236. message BlockStatement {
  237. repeated Statement statements = 1;
  238. }
  239. message WhileStatement {
  240. optional Expression condition = 1;
  241. optional BlockStatement body = 2;
  242. }
  243. message ForStatement {
  244. optional BindingPattern var_decl = 1;
  245. optional Expression target = 2;
  246. optional BlockStatement body = 3;
  247. }
  248. message MatchClause {
  249. optional Pattern pattern = 1;
  250. optional Statement statement = 2;
  251. optional bool is_default = 3;
  252. }
  253. message MatchStatement {
  254. optional Expression expression = 1;
  255. repeated MatchClause clauses = 2;
  256. }
  257. message ContinuationStatement {
  258. optional string name = 1;
  259. optional BlockStatement body = 2;
  260. }
  261. message RunStatement {
  262. optional Expression argument = 1;
  263. }
  264. message AwaitStatement {}
  265. message BreakStatement {}
  266. message ContinueStatement {}
  267. message Statement {
  268. oneof kind {
  269. ExpressionStatement expression_statement = 1;
  270. AssignStatement assign = 2;
  271. VariableDefinitionStatement variable_definition = 3;
  272. IfStatement if_statement = 4;
  273. ReturnVarStatement return_var_statement = 5;
  274. ReturnExpressionStatement return_expression_statement = 6;
  275. BlockStatement block = 7;
  276. WhileStatement while_statement = 8;
  277. MatchStatement match = 9;
  278. ContinuationStatement continuation = 10;
  279. RunStatement run = 11;
  280. AwaitStatement await_statement = 12;
  281. BreakStatement break_statement = 13;
  282. ContinueStatement continue_statement = 14;
  283. ForStatement for_statement = 15;
  284. IncrementDecrementStatement inc_dec = 16;
  285. }
  286. }
  287. // Declarations.
  288. message ReturnTerm {
  289. enum ReturnKind {
  290. UnknownReturnKind = 0;
  291. Omitted = 1;
  292. Auto = 2;
  293. Expression = 3;
  294. }
  295. optional ReturnKind kind = 1;
  296. optional Expression type = 2;
  297. }
  298. message FunctionDeclaration {
  299. optional string name = 1;
  300. repeated GenericBinding deduced_parameters = 2;
  301. optional Pattern self_pattern = 3;
  302. optional TuplePattern param_pattern = 4;
  303. optional ReturnTerm return_term = 5;
  304. optional BlockStatement body = 6;
  305. }
  306. message DestructorDeclaration {
  307. optional Pattern self_pattern = 1;
  308. optional BlockStatement body = 2;
  309. }
  310. message ClassDeclaration {
  311. optional string name = 1;
  312. repeated Declaration members = 2;
  313. optional TuplePattern type_params = 3;
  314. }
  315. message AlternativeSignature {
  316. optional string name = 1;
  317. optional TupleLiteralExpression signature = 3;
  318. }
  319. message ChoiceDeclaration {
  320. optional string name = 1;
  321. repeated AlternativeSignature alternatives = 2;
  322. }
  323. message VariableDeclaration {
  324. optional BindingPattern binding = 1;
  325. optional Expression initializer = 2;
  326. }
  327. message LetDeclaration {
  328. optional Pattern pattern = 1;
  329. // TODO: Add `optional Expression initializer = 2;` once explorer supports
  330. // `let` declarations in general.
  331. }
  332. message InterfaceExtendsDeclaration {
  333. optional Expression base = 1;
  334. }
  335. message InterfaceImplDeclaration {
  336. optional Expression impl_type = 1;
  337. optional Expression constraint = 2;
  338. }
  339. message InterfaceDeclaration {
  340. optional string name = 1;
  341. repeated Declaration members = 2;
  342. }
  343. message ConstraintDeclaration {
  344. optional string name = 1;
  345. repeated Declaration members = 2;
  346. }
  347. message ImplDeclaration {
  348. enum ImplKind {
  349. UnknownImplKind = 0;
  350. InternalImpl = 1;
  351. ExternalImpl = 2;
  352. }
  353. optional ImplKind kind = 1;
  354. optional Expression impl_type = 2;
  355. optional Expression interface = 3;
  356. repeated Declaration members = 4;
  357. }
  358. message MatchFirstDeclaration {
  359. repeated Declaration impls = 1;
  360. }
  361. message AliasDeclaration {
  362. optional string name = 1;
  363. optional Expression target = 2;
  364. }
  365. // EXPERIMENTAL MIXIN FEATURE
  366. message MixinDeclaration {
  367. optional string name = 1;
  368. repeated Declaration members = 2;
  369. // Type params not implemented yet
  370. // optional TuplePattern params = 3;
  371. optional GenericBinding self = 4;
  372. }
  373. // EXPERIMENTAL MIXIN FEATURE
  374. message MixDeclaration {
  375. optional Expression mixin = 1;
  376. }
  377. message NamespaceDeclaration {
  378. optional string name = 1;
  379. }
  380. message Declaration {
  381. oneof kind {
  382. FunctionDeclaration function = 1;
  383. ClassDeclaration class_declaration = 2;
  384. ChoiceDeclaration choice = 3;
  385. VariableDeclaration variable = 4;
  386. InterfaceDeclaration interface = 5;
  387. ImplDeclaration impl = 6;
  388. AliasDeclaration alias = 7;
  389. LetDeclaration let = 8;
  390. MixinDeclaration mixin = 9;
  391. MixDeclaration mix = 10;
  392. DestructorDeclaration destructor = 11;
  393. InterfaceExtendsDeclaration interface_extends = 12;
  394. InterfaceImplDeclaration interface_impl = 13;
  395. ConstraintDeclaration constraint = 14;
  396. MatchFirstDeclaration match_first = 15;
  397. NamespaceDeclaration namespace = 16;
  398. }
  399. }
  400. message CompilationUnit {
  401. optional LibraryName package_statement = 1;
  402. optional bool is_api = 2;
  403. repeated Declaration declarations = 3;
  404. // TODO: Add support for imports if they are useful in fuzzing.
  405. }
  406. // Top-level fuzzer input.
  407. message Carbon {
  408. optional CompilationUnit compilation_unit = 1;
  409. }