carbon.proto 7.4 KB

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