carbon.proto 11 KB

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