carbon.proto 7.8 KB

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