carbon.proto 7.5 KB

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