carbon.proto 9.5 KB

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