carbon.proto 8.8 KB

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