carbon.proto 9.3 KB

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