carbon.proto 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 PrimitiveOperatorExpression {
  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. Combine = 12;
  46. As = 13;
  47. }
  48. optional Operator op = 1;
  49. repeated Expression arguments = 2;
  50. }
  51. message TupleLiteralExpression {
  52. repeated Expression fields = 1;
  53. }
  54. message FieldInitializer {
  55. optional string name = 1;
  56. optional Expression expression = 2;
  57. }
  58. message StructLiteralExpression {
  59. repeated FieldInitializer fields = 1;
  60. }
  61. message StructTypeLiteralExpression {
  62. repeated FieldInitializer fields = 1;
  63. }
  64. message IdentifierExpression {
  65. optional string name = 1;
  66. }
  67. message DesignatorExpression {
  68. optional string name = 1;
  69. }
  70. message IntrinsicExpression {
  71. enum Intrinsic {
  72. UnknownIntrinsic = 0;
  73. Print = 1;
  74. Alloc = 2;
  75. Dealloc = 3;
  76. }
  77. optional Intrinsic intrinsic = 1;
  78. optional TupleLiteralExpression argument = 2;
  79. }
  80. message IfExpression {
  81. optional Expression condition = 1;
  82. optional Expression then_expression = 2;
  83. optional Expression else_expression = 3;
  84. }
  85. message BoolTypeLiteral {}
  86. message BoolLiteral {
  87. optional bool value = 1;
  88. }
  89. message IntTypeLiteral {}
  90. message ContinuationTypeLiteral {}
  91. message IntLiteral {
  92. optional int64 value = 1;
  93. }
  94. message StringLiteral {
  95. optional string value = 1;
  96. }
  97. message StringTypeLiteral {}
  98. message TypeTypeLiteral {}
  99. message UnimplementedExpression {}
  100. message ArrayTypeLiteral {
  101. optional Expression element_type = 1;
  102. optional Expression size = 2;
  103. }
  104. message IsWhereClause {
  105. optional Expression type = 1;
  106. optional Expression constraint = 2;
  107. }
  108. message EqualsWhereClause {
  109. optional Expression lhs = 1;
  110. optional Expression rhs = 2;
  111. }
  112. message WhereClause {
  113. oneof kind {
  114. IsWhereClause is = 1;
  115. EqualsWhereClause equals = 2;
  116. }
  117. }
  118. message WhereExpression {
  119. optional Expression base = 1;
  120. repeated WhereClause clauses = 2;
  121. }
  122. message Expression {
  123. oneof kind {
  124. CallExpression call = 1;
  125. FunctionTypeLiteral function_type = 2;
  126. SimpleMemberAccessExpression simple_member_access = 3;
  127. IndexExpression index = 4;
  128. PrimitiveOperatorExpression primitive_operator = 5;
  129. TupleLiteralExpression tuple_literal = 6;
  130. StructLiteralExpression struct_literal = 7;
  131. StructTypeLiteralExpression struct_type_literal = 8;
  132. IdentifierExpression identifier = 9;
  133. IntrinsicExpression intrinsic = 10;
  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 MatchClause {
  220. optional Pattern pattern = 1;
  221. optional Statement statement = 2;
  222. optional bool is_default = 3;
  223. }
  224. message MatchStatement {
  225. optional Expression expression = 1;
  226. repeated MatchClause clauses = 2;
  227. }
  228. message ContinuationStatement {
  229. optional string name = 1;
  230. optional BlockStatement body = 2;
  231. }
  232. message RunStatement {
  233. optional Expression argument = 1;
  234. }
  235. message AwaitStatement {}
  236. message BreakStatement {}
  237. message ContinueStatement {}
  238. message Statement {
  239. oneof kind {
  240. ExpressionStatement expression_statement = 1;
  241. AssignStatement assign = 2;
  242. VariableDefinitionStatement variable_definition = 3;
  243. IfStatement if_statement = 4;
  244. ReturnVarStatement return_var_statement = 5;
  245. ReturnExpressionStatement return_expression_statement = 6;
  246. BlockStatement block = 7;
  247. WhileStatement while_statement = 8;
  248. MatchStatement match = 9;
  249. ContinuationStatement continuation = 10;
  250. RunStatement run = 11;
  251. AwaitStatement await_statement = 12;
  252. BreakStatement break_statement = 13;
  253. ContinueStatement continue_statement = 14;
  254. }
  255. }
  256. // Declarations.
  257. message ReturnTerm {
  258. enum ReturnKind {
  259. UnknownReturnKind = 0;
  260. Omitted = 1;
  261. Auto = 2;
  262. Expression = 3;
  263. }
  264. optional ReturnKind kind = 1;
  265. optional Expression type = 2;
  266. }
  267. message FunctionDeclaration {
  268. optional string name = 1;
  269. repeated GenericBinding deduced_parameters = 2;
  270. optional Pattern me_pattern = 3;
  271. optional TuplePattern param_pattern = 4;
  272. optional ReturnTerm return_term = 5;
  273. optional BlockStatement body = 6;
  274. }
  275. message ClassDeclaration {
  276. optional string name = 1;
  277. repeated Declaration members = 2;
  278. optional TuplePattern type_params = 3;
  279. }
  280. message AlternativeSignature {
  281. optional string name = 1;
  282. optional TupleLiteralExpression signature = 3;
  283. }
  284. message ChoiceDeclaration {
  285. optional string name = 1;
  286. repeated AlternativeSignature alternatives = 2;
  287. }
  288. message VariableDeclaration {
  289. optional BindingPattern binding = 1;
  290. optional Expression initializer = 2;
  291. }
  292. message LetDeclaration {
  293. optional Pattern pattern = 1;
  294. // TODO: Add `optional Expression initializer = 2;` once explorer supports
  295. // `let` declarations in general.
  296. }
  297. message InterfaceDeclaration {
  298. optional string name = 1;
  299. repeated Declaration members = 2;
  300. optional GenericBinding self = 3;
  301. }
  302. message ImplDeclaration {
  303. enum ImplKind {
  304. UnknownImplKind = 0;
  305. InternalImpl = 1;
  306. ExternalImpl = 2;
  307. }
  308. optional ImplKind kind = 1;
  309. optional Expression impl_type = 2;
  310. optional Expression interface = 3;
  311. repeated Declaration members = 4;
  312. }
  313. message AliasDeclaration {
  314. optional string name = 1;
  315. optional Expression target = 2;
  316. }
  317. message Declaration {
  318. oneof kind {
  319. FunctionDeclaration function = 1;
  320. ClassDeclaration class_declaration = 2;
  321. ChoiceDeclaration choice = 3;
  322. VariableDeclaration variable = 4;
  323. InterfaceDeclaration interface = 5;
  324. ImplDeclaration impl = 6;
  325. AliasDeclaration alias = 7;
  326. LetDeclaration let = 8;
  327. }
  328. }
  329. message CompilationUnit {
  330. optional LibraryName package_statement = 1;
  331. optional bool is_api = 2;
  332. repeated Declaration declarations = 3;
  333. // TODO Add support for imports if they are useful in fuzzing.
  334. }
  335. // Top-level fuzzer input.
  336. message Carbon {
  337. optional CompilationUnit compilation_unit = 1;
  338. }