carbon.proto 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. }
  200. message IfStatement {
  201. optional Expression condition = 1;
  202. optional BlockStatement then_block = 2;
  203. optional BlockStatement else_block = 3;
  204. }
  205. message ReturnStatement {
  206. optional Expression expression = 1; // Can be omitted.
  207. optional bool is_omitted_expression = 2;
  208. }
  209. message BlockStatement {
  210. repeated Statement statements = 1;
  211. }
  212. message WhileStatement {
  213. optional Expression condition = 1;
  214. optional BlockStatement body = 2;
  215. }
  216. message MatchClause {
  217. optional Pattern pattern = 1;
  218. optional Statement statement = 2;
  219. optional bool is_default = 3;
  220. }
  221. message MatchStatement {
  222. optional Expression expression = 1;
  223. repeated MatchClause clauses = 2;
  224. }
  225. message ContinuationStatement {
  226. optional string name = 1;
  227. optional BlockStatement body = 2;
  228. }
  229. message RunStatement {
  230. optional Expression argument = 1;
  231. }
  232. message AwaitStatement {}
  233. message BreakStatement {}
  234. message ContinueStatement {}
  235. message Statement {
  236. oneof kind {
  237. ExpressionStatement expression_statement = 1;
  238. AssignStatement assign = 2;
  239. VariableDefinitionStatement variable_definition = 3;
  240. IfStatement if_statement = 4;
  241. ReturnStatement return_statement = 5;
  242. BlockStatement block = 6;
  243. WhileStatement while_statement = 7;
  244. MatchStatement match = 8;
  245. ContinuationStatement continuation = 9;
  246. RunStatement run = 10;
  247. AwaitStatement await_statement = 11;
  248. BreakStatement break_statement = 12;
  249. ContinueStatement continue_statement = 13;
  250. }
  251. }
  252. // Declarations.
  253. message ReturnTerm {
  254. enum ReturnKind {
  255. UnknownReturnKind = 0;
  256. Omitted = 1;
  257. Auto = 2;
  258. Expression = 3;
  259. }
  260. optional ReturnKind kind = 1;
  261. optional Expression type = 2;
  262. }
  263. message FunctionDeclaration {
  264. optional string name = 1;
  265. repeated GenericBinding deduced_parameters = 2;
  266. optional Pattern me_pattern = 3;
  267. optional TuplePattern param_pattern = 4;
  268. optional ReturnTerm return_term = 5;
  269. optional BlockStatement body = 6;
  270. }
  271. message ClassDeclaration {
  272. optional string name = 1;
  273. repeated Declaration members = 2;
  274. optional TuplePattern type_params = 3;
  275. }
  276. message AlternativeSignature {
  277. optional string name = 1;
  278. optional TupleLiteralExpression signature = 3;
  279. }
  280. message ChoiceDeclaration {
  281. optional string name = 1;
  282. repeated AlternativeSignature alternatives = 2;
  283. }
  284. message VariableDeclaration {
  285. optional BindingPattern binding = 1;
  286. optional Expression initializer = 2;
  287. }
  288. message InterfaceDeclaration {
  289. optional string name = 1;
  290. repeated Declaration members = 2;
  291. optional GenericBinding self = 3;
  292. }
  293. message ImplDeclaration {
  294. enum ImplKind {
  295. UnknownImplKind = 0;
  296. InternalImpl = 1;
  297. ExternalImpl = 2;
  298. }
  299. optional ImplKind kind = 1;
  300. optional Expression impl_type = 2;
  301. optional Expression interface = 3;
  302. repeated Declaration members = 4;
  303. }
  304. message AliasDeclaration {
  305. optional string name = 1;
  306. optional Expression target = 2;
  307. }
  308. message Declaration {
  309. oneof kind {
  310. FunctionDeclaration function = 1;
  311. ClassDeclaration class_declaration = 2;
  312. ChoiceDeclaration choice = 3;
  313. VariableDeclaration variable = 4;
  314. InterfaceDeclaration interface = 5;
  315. ImplDeclaration impl = 6;
  316. AliasDeclaration alias = 7;
  317. }
  318. }
  319. message CompilationUnit {
  320. optional LibraryName package_statement = 1;
  321. optional bool is_api = 2;
  322. repeated Declaration declarations = 3;
  323. // TODO Add support for imports if they are useful in fuzzing.
  324. }
  325. // Top-level fuzzer input.
  326. message Carbon {
  327. optional CompilationUnit compilation_unit = 1;
  328. }