carbon.proto 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. optional Expression lhs = 1;
  201. optional Expression rhs = 2;
  202. }
  203. message VariableDefinitionStatement {
  204. optional Pattern pattern = 1;
  205. optional Expression init = 2;
  206. optional bool is_returned = 3;
  207. }
  208. message IfStatement {
  209. optional Expression condition = 1;
  210. optional BlockStatement then_block = 2;
  211. optional BlockStatement else_block = 3;
  212. }
  213. message ReturnVarStatement {}
  214. message ReturnExpressionStatement {
  215. optional Expression expression = 1; // Can be omitted.
  216. optional bool is_omitted_expression = 2;
  217. }
  218. message BlockStatement {
  219. repeated Statement statements = 1;
  220. }
  221. message WhileStatement {
  222. optional Expression condition = 1;
  223. optional BlockStatement body = 2;
  224. }
  225. message ForStatement {
  226. optional BindingPattern var_decl = 1;
  227. optional Expression target = 2;
  228. optional BlockStatement body = 3;
  229. }
  230. message MatchClause {
  231. optional Pattern pattern = 1;
  232. optional Statement statement = 2;
  233. optional bool is_default = 3;
  234. }
  235. message MatchStatement {
  236. optional Expression expression = 1;
  237. repeated MatchClause clauses = 2;
  238. }
  239. message ContinuationStatement {
  240. optional string name = 1;
  241. optional BlockStatement body = 2;
  242. }
  243. message RunStatement {
  244. optional Expression argument = 1;
  245. }
  246. message AwaitStatement {}
  247. message BreakStatement {}
  248. message ContinueStatement {}
  249. message Statement {
  250. oneof kind {
  251. ExpressionStatement expression_statement = 1;
  252. AssignStatement assign = 2;
  253. VariableDefinitionStatement variable_definition = 3;
  254. IfStatement if_statement = 4;
  255. ReturnVarStatement return_var_statement = 5;
  256. ReturnExpressionStatement return_expression_statement = 6;
  257. BlockStatement block = 7;
  258. WhileStatement while_statement = 8;
  259. MatchStatement match = 9;
  260. ContinuationStatement continuation = 10;
  261. RunStatement run = 11;
  262. AwaitStatement await_statement = 12;
  263. BreakStatement break_statement = 13;
  264. ContinueStatement continue_statement = 14;
  265. ForStatement for_statement = 15;
  266. }
  267. }
  268. // Declarations.
  269. message ReturnTerm {
  270. enum ReturnKind {
  271. UnknownReturnKind = 0;
  272. Omitted = 1;
  273. Auto = 2;
  274. Expression = 3;
  275. }
  276. optional ReturnKind kind = 1;
  277. optional Expression type = 2;
  278. }
  279. message FunctionDeclaration {
  280. optional string name = 1;
  281. repeated GenericBinding deduced_parameters = 2;
  282. optional Pattern self_pattern = 3;
  283. optional TuplePattern param_pattern = 4;
  284. optional ReturnTerm return_term = 5;
  285. optional BlockStatement body = 6;
  286. }
  287. message DestructorDeclaration {
  288. optional Pattern self_pattern = 1;
  289. optional BlockStatement body = 2;
  290. }
  291. message ClassDeclaration {
  292. optional string name = 1;
  293. repeated Declaration members = 2;
  294. optional TuplePattern type_params = 3;
  295. }
  296. message AlternativeSignature {
  297. optional string name = 1;
  298. optional TupleLiteralExpression signature = 3;
  299. }
  300. message ChoiceDeclaration {
  301. optional string name = 1;
  302. repeated AlternativeSignature alternatives = 2;
  303. }
  304. message VariableDeclaration {
  305. optional BindingPattern binding = 1;
  306. optional Expression initializer = 2;
  307. }
  308. message LetDeclaration {
  309. optional Pattern pattern = 1;
  310. // TODO: Add `optional Expression initializer = 2;` once explorer supports
  311. // `let` declarations in general.
  312. }
  313. message InterfaceExtendsDeclaration {
  314. optional Expression base = 1;
  315. }
  316. message InterfaceImplDeclaration {
  317. optional Expression impl_type = 1;
  318. optional Expression constraint = 2;
  319. }
  320. message InterfaceDeclaration {
  321. optional string name = 1;
  322. repeated Declaration members = 2;
  323. }
  324. message ConstraintDeclaration {
  325. optional string name = 1;
  326. repeated Declaration members = 2;
  327. }
  328. message ImplDeclaration {
  329. enum ImplKind {
  330. UnknownImplKind = 0;
  331. InternalImpl = 1;
  332. ExternalImpl = 2;
  333. }
  334. optional ImplKind kind = 1;
  335. optional Expression impl_type = 2;
  336. optional Expression interface = 3;
  337. repeated Declaration members = 4;
  338. }
  339. message AliasDeclaration {
  340. optional string name = 1;
  341. optional Expression target = 2;
  342. }
  343. // EXPERIMENTAL MIXIN FEATURE
  344. message MixinDeclaration {
  345. optional string name = 1;
  346. repeated Declaration members = 2;
  347. // Type params not implemented yet
  348. // optional TuplePattern params = 3;
  349. optional GenericBinding self = 4;
  350. }
  351. // EXPERIMENTAL MIXIN FEATURE
  352. message MixDeclaration {
  353. optional Expression mixin = 1;
  354. }
  355. message Declaration {
  356. oneof kind {
  357. FunctionDeclaration function = 1;
  358. ClassDeclaration class_declaration = 2;
  359. ChoiceDeclaration choice = 3;
  360. VariableDeclaration variable = 4;
  361. InterfaceDeclaration interface = 5;
  362. ImplDeclaration impl = 6;
  363. AliasDeclaration alias = 7;
  364. LetDeclaration let = 8;
  365. MixinDeclaration mixin = 9;
  366. MixDeclaration mix = 10;
  367. DestructorDeclaration destructor = 11;
  368. InterfaceExtendsDeclaration interface_extends = 12;
  369. InterfaceImplDeclaration interface_impl = 13;
  370. ConstraintDeclaration constraint = 14;
  371. }
  372. }
  373. message CompilationUnit {
  374. optional LibraryName package_statement = 1;
  375. optional bool is_api = 2;
  376. repeated Declaration declarations = 3;
  377. // TODO: Add support for imports if they are useful in fuzzing.
  378. }
  379. // Top-level fuzzer input.
  380. message Carbon {
  381. optional CompilationUnit compilation_unit = 1;
  382. }