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. 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 IntLiteral {
  97. optional int64 value = 1;
  98. }
  99. message StringLiteral {
  100. optional string value = 1;
  101. }
  102. message StringTypeLiteral {}
  103. message TypeTypeLiteral {}
  104. message UnimplementedExpression {}
  105. message ArrayTypeLiteral {
  106. optional Expression element_type = 1;
  107. optional Expression size = 2;
  108. }
  109. message ImplsWhereClause {
  110. optional Expression type = 1;
  111. optional Expression constraint = 2;
  112. }
  113. message EqualsWhereClause {
  114. optional Expression lhs = 1;
  115. optional Expression rhs = 2;
  116. }
  117. message RewriteWhereClause {
  118. optional string member_name = 1;
  119. optional Expression replacement = 2;
  120. }
  121. message WhereClause {
  122. oneof kind {
  123. ImplsWhereClause impls = 1;
  124. EqualsWhereClause equals = 2;
  125. RewriteWhereClause rewrite = 3;
  126. }
  127. }
  128. message WhereExpression {
  129. optional Expression base = 1;
  130. repeated WhereClause clauses = 2;
  131. }
  132. message Expression {
  133. oneof kind {
  134. CallExpression call = 1;
  135. FunctionTypeLiteral function_type = 2;
  136. SimpleMemberAccessExpression simple_member_access = 3;
  137. IndexExpression index = 4;
  138. OperatorExpression operator = 5;
  139. TupleLiteralExpression tuple_literal = 6;
  140. StructLiteralExpression struct_literal = 7;
  141. StructTypeLiteralExpression struct_type_literal = 8;
  142. IdentifierExpression identifier = 9;
  143. IfExpression if_expression = 11;
  144. BoolTypeLiteral bool_type_literal = 12;
  145. BoolLiteral bool_literal = 13;
  146. IntTypeLiteral int_type_literal = 14;
  147. IntLiteral int_literal = 15;
  148. StringLiteral string_literal = 16;
  149. StringTypeLiteral string_type_literal = 17;
  150. TypeTypeLiteral type_type_literal = 18;
  151. UnimplementedExpression unimplemented_expression = 19;
  152. ArrayTypeLiteral array_type_literal = 20;
  153. CompoundMemberAccessExpression compound_member_access = 21;
  154. WhereExpression where = 22;
  155. DesignatorExpression designator = 23;
  156. }
  157. }
  158. // Patterns.
  159. message BindingPattern {
  160. optional string name = 1;
  161. optional Pattern type = 2;
  162. }
  163. message GenericBinding {
  164. enum Kind {
  165. Checked = 0;
  166. Template = 1;
  167. }
  168. optional string name = 1;
  169. optional Expression type = 2;
  170. optional Kind kind = 3;
  171. }
  172. message TuplePattern {
  173. repeated Pattern fields = 1;
  174. }
  175. message AlternativePattern {
  176. optional Expression choice_type = 1;
  177. optional string alternative_name = 2;
  178. optional TuplePattern arguments = 3;
  179. }
  180. message ExpressionPattern {
  181. optional Expression expression = 1;
  182. }
  183. message AutoPattern {}
  184. message VarPattern {
  185. optional Pattern pattern = 1;
  186. }
  187. message AddrPattern {
  188. optional BindingPattern binding_pattern = 1;
  189. }
  190. message Pattern {
  191. oneof kind {
  192. BindingPattern binding_pattern = 1;
  193. TuplePattern tuple_pattern = 2;
  194. AlternativePattern alternative_pattern = 3;
  195. ExpressionPattern expression_pattern = 4;
  196. AutoPattern auto_pattern = 5;
  197. VarPattern var_pattern = 6;
  198. GenericBinding generic_binding = 7;
  199. AddrPattern addr_pattern = 8;
  200. }
  201. }
  202. // Statements.
  203. message ExpressionStatement {
  204. optional Expression expression = 1;
  205. }
  206. message AssignStatement {
  207. enum Operator {
  208. Plain = 0;
  209. Add = 1;
  210. And = 2;
  211. Div = 3;
  212. Mul = 4;
  213. Or = 5;
  214. Sub = 6;
  215. Mod = 7;
  216. Xor = 8;
  217. ShiftLeft = 9;
  218. ShiftRight = 10;
  219. }
  220. optional Expression lhs = 1;
  221. optional Expression rhs = 2;
  222. optional Operator op = 3;
  223. }
  224. message IncrementDecrementStatement {
  225. optional Expression operand = 1;
  226. optional bool is_increment = 2;
  227. }
  228. message VariableDefinitionStatement {
  229. optional Pattern pattern = 1;
  230. optional Expression init = 2;
  231. optional bool is_returned = 3;
  232. }
  233. message IfStatement {
  234. optional Expression condition = 1;
  235. optional BlockStatement then_block = 2;
  236. optional BlockStatement else_block = 3;
  237. }
  238. message ReturnVarStatement {}
  239. message ReturnExpressionStatement {
  240. optional Expression expression = 1; // Can be omitted.
  241. optional bool is_omitted_expression = 2;
  242. }
  243. message BlockStatement {
  244. repeated Statement statements = 1;
  245. }
  246. message WhileStatement {
  247. optional Expression condition = 1;
  248. optional BlockStatement body = 2;
  249. }
  250. message ForStatement {
  251. optional BindingPattern var_decl = 1;
  252. optional Expression target = 2;
  253. optional BlockStatement body = 3;
  254. }
  255. message MatchClause {
  256. optional Pattern pattern = 1;
  257. optional Statement statement = 2;
  258. optional bool is_default = 3;
  259. }
  260. message MatchStatement {
  261. optional Expression expression = 1;
  262. repeated MatchClause clauses = 2;
  263. }
  264. message BreakStatement {}
  265. message ContinueStatement {}
  266. message Statement {
  267. oneof kind {
  268. ExpressionStatement expression_statement = 1;
  269. AssignStatement assign = 2;
  270. VariableDefinitionStatement variable_definition = 3;
  271. IfStatement if_statement = 4;
  272. ReturnVarStatement return_var_statement = 5;
  273. ReturnExpressionStatement return_expression_statement = 6;
  274. BlockStatement block = 7;
  275. WhileStatement while_statement = 8;
  276. MatchStatement match = 9;
  277. BreakStatement break_statement = 10;
  278. ContinueStatement continue_statement = 11;
  279. ForStatement for_statement = 12;
  280. IncrementDecrementStatement inc_dec = 13;
  281. }
  282. }
  283. // Declarations.
  284. message ReturnTerm {
  285. enum ReturnKind {
  286. UnknownReturnKind = 0;
  287. Omitted = 1;
  288. Auto = 2;
  289. Expression = 3;
  290. }
  291. optional ReturnKind kind = 1;
  292. optional Expression type = 2;
  293. }
  294. message FunctionDeclaration {
  295. optional DeclaredName name = 1;
  296. repeated GenericBinding deduced_parameters = 2;
  297. optional Pattern self_pattern = 3;
  298. optional TuplePattern param_pattern = 4;
  299. optional ReturnTerm return_term = 5;
  300. optional BlockStatement body = 6;
  301. }
  302. message DestructorDeclaration {
  303. optional Pattern self_pattern = 1;
  304. optional BlockStatement body = 2;
  305. }
  306. message ClassDeclaration {
  307. optional DeclaredName name = 1;
  308. repeated Declaration members = 2;
  309. optional TuplePattern type_params = 3;
  310. }
  311. message ExtendBaseDeclaration {
  312. optional Expression base_class = 1;
  313. }
  314. message AlternativeSignature {
  315. optional string name = 1;
  316. optional TupleLiteralExpression signature = 3;
  317. }
  318. message ChoiceDeclaration {
  319. optional DeclaredName name = 1;
  320. repeated AlternativeSignature alternatives = 2;
  321. }
  322. message VariableDeclaration {
  323. optional BindingPattern binding = 1;
  324. optional Expression initializer = 2;
  325. }
  326. message LetDeclaration {
  327. optional Pattern pattern = 1;
  328. // TODO: Add `optional Expression initializer = 2;` once explorer supports
  329. // `let` declarations in general.
  330. }
  331. message InterfaceExtendDeclaration {
  332. optional Expression base = 1;
  333. }
  334. message InterfaceRequireDeclaration {
  335. optional Expression impl_type = 1;
  336. optional Expression constraint = 2;
  337. }
  338. message InterfaceDeclaration {
  339. optional DeclaredName name = 1;
  340. repeated Declaration members = 2;
  341. }
  342. message ConstraintDeclaration {
  343. optional DeclaredName name = 1;
  344. repeated Declaration members = 2;
  345. }
  346. message ImplDeclaration {
  347. enum ImplKind {
  348. UnknownImplKind = 0;
  349. InternalImpl = 1;
  350. ExternalImpl = 2;
  351. }
  352. optional ImplKind kind = 1;
  353. repeated GenericBinding deduced_parameters = 2;
  354. optional Expression impl_type = 3;
  355. optional Expression interface = 4;
  356. repeated Declaration members = 5;
  357. }
  358. message MatchFirstDeclaration {
  359. repeated Declaration impl_declarations = 1;
  360. }
  361. message AliasDeclaration {
  362. optional DeclaredName name = 1;
  363. optional Expression target = 2;
  364. }
  365. // EXPERIMENTAL MIXIN FEATURE
  366. message MixinDeclaration {
  367. optional DeclaredName 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 DeclaredName 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. InterfaceExtendDeclaration interface_extend = 12;
  394. InterfaceRequireDeclaration interface_require = 13;
  395. ConstraintDeclaration constraint = 14;
  396. MatchFirstDeclaration match_first = 15;
  397. NamespaceDeclaration namespace = 16;
  398. ExtendBaseDeclaration extend_base = 17;
  399. }
  400. }
  401. message CompilationUnit {
  402. optional LibraryName package_statement = 1;
  403. optional bool is_api = 2;
  404. repeated Declaration declarations = 3;
  405. // TODO: Add support for imports if they are useful in fuzzing.
  406. }
  407. // Top-level fuzzer input.
  408. message Carbon {
  409. optional CompilationUnit compilation_unit = 1;
  410. }