OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package translator | 5 package translator |
6 | 6 |
7 // TmplFile contains all of the information needed by the templates to generate | 7 // TmplFile contains all of the information needed by the templates to generate |
8 // the go bindings for one mojom file. | 8 // the go bindings for one mojom file. |
9 type TmplFile struct { | 9 type TmplFile struct { |
10 PackageName string | 10 PackageName string |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 // IsStruct returns true if the field is a struct. | 169 // IsStruct returns true if the field is a struct. |
170 IsStruct() bool | 170 IsStruct() bool |
171 | 171 |
172 // IsUnion returns true if the field is a union. | 172 // IsUnion returns true if the field is a union. |
173 IsUnion() bool | 173 IsUnion() bool |
174 | 174 |
175 // IsEnum returns true if the field is an enum. | 175 // IsEnum returns true if the field is an enum. |
176 IsEnum() bool | 176 IsEnum() bool |
177 | 177 |
| 178 // IsInterface returns true if the field is an interface or interface re
quest. |
| 179 IsInterface() bool |
| 180 |
| 181 // IsInterfaceRequest returns true if the field is an interface request. |
| 182 IsInterfaceRequest() bool |
| 183 |
178 // IsArray returns true if the field is an array. | 184 // IsArray returns true if the field is an array. |
179 IsArray() bool | 185 IsArray() bool |
180 | 186 |
181 // IsMap returns true if the field is a map. | 187 // IsMap returns true if the field is a map. |
182 IsMap() bool | 188 IsMap() bool |
183 | 189 |
184 // IsNullable returns true if the field is nullable. | 190 // IsNullable returns true if the field is nullable. |
185 IsNullable() bool | 191 IsNullable() bool |
186 setNullable(nullable bool) | 192 setNullable(nullable bool) |
187 | 193 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 254 } |
249 | 255 |
250 func (b *baseEncodingInfo) IsUnion() bool { | 256 func (b *baseEncodingInfo) IsUnion() bool { |
251 return false | 257 return false |
252 } | 258 } |
253 | 259 |
254 func (b *baseEncodingInfo) IsEnum() bool { | 260 func (b *baseEncodingInfo) IsEnum() bool { |
255 return false | 261 return false |
256 } | 262 } |
257 | 263 |
| 264 func (b *baseEncodingInfo) IsInterface() bool { |
| 265 return false |
| 266 } |
| 267 |
| 268 func (b *baseEncodingInfo) IsInterfaceRequest() bool { |
| 269 return false |
| 270 } |
| 271 |
258 func (b *baseEncodingInfo) IsArray() bool { | 272 func (b *baseEncodingInfo) IsArray() bool { |
259 return false | 273 return false |
260 } | 274 } |
261 | 275 |
262 func (b *baseEncodingInfo) IsMap() bool { | 276 func (b *baseEncodingInfo) IsMap() bool { |
263 return false | 277 return false |
264 } | 278 } |
265 | 279 |
266 func (b *baseEncodingInfo) ElementEncodingInfo() EncodingInfo { | 280 func (b *baseEncodingInfo) ElementEncodingInfo() EncodingInfo { |
267 panic("Only arrays have elements!") | 281 panic("Only arrays have elements!") |
(...skipping 19 matching lines...) Expand all Loading... |
287 func (b *baseEncodingInfo) GoType() string { | 301 func (b *baseEncodingInfo) GoType() string { |
288 return b.goType | 302 return b.goType |
289 } | 303 } |
290 | 304 |
291 func (b *baseEncodingInfo) setGoType(goType string) { | 305 func (b *baseEncodingInfo) setGoType(goType string) { |
292 b.goType = goType | 306 b.goType = goType |
293 } | 307 } |
294 | 308 |
295 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
296 | 310 |
| 311 type baseNullableEncodingInfo struct { |
| 312 baseEncodingInfo |
| 313 nullable bool |
| 314 } |
| 315 |
| 316 func (b *baseNullableEncodingInfo) IsNullable() bool { |
| 317 return b.nullable |
| 318 } |
| 319 |
| 320 func (b *baseNullableEncodingInfo) setNullable(nullable bool) { |
| 321 b.nullable = nullable |
| 322 } |
| 323 |
| 324 //////////////////////////////////////////////////////////////////////////////// |
| 325 |
297 // basePointerEncodingInfo implements the EncodingInfo for pointer types. | 326 // basePointerEncodingInfo implements the EncodingInfo for pointer types. |
298 type basePointerEncodingInfo struct { | 327 type basePointerEncodingInfo struct { |
299 » baseEncodingInfo | 328 » baseNullableEncodingInfo |
300 » nullable bool | |
301 } | |
302 | |
303 func (b *basePointerEncodingInfo) IsNullable() bool { | |
304 » return b.nullable | |
305 } | |
306 | |
307 func (b *basePointerEncodingInfo) setNullable(nullable bool) { | |
308 » b.nullable = nullable | |
309 } | 329 } |
310 | 330 |
311 func (b *basePointerEncodingInfo) IsPointer() bool { | 331 func (b *basePointerEncodingInfo) IsPointer() bool { |
312 return true | 332 return true |
313 } | 333 } |
314 | 334 |
315 func (b *basePointerEncodingInfo) BitSize() uint32 { | 335 func (b *basePointerEncodingInfo) BitSize() uint32 { |
316 return uint32(64) | 336 return uint32(64) |
317 } | 337 } |
318 | 338 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return "WriteString" | 377 return "WriteString" |
358 } | 378 } |
359 | 379 |
360 func (t *stringTypeEncodingInfo) ReadFunction() string { | 380 func (t *stringTypeEncodingInfo) ReadFunction() string { |
361 return "ReadString" | 381 return "ReadString" |
362 } | 382 } |
363 | 383 |
364 //////////////////////////////////////////////////////////////////////////////// | 384 //////////////////////////////////////////////////////////////////////////////// |
365 | 385 |
366 type handleTypeEncodingInfo struct { | 386 type handleTypeEncodingInfo struct { |
367 » baseEncodingInfo | 387 » baseNullableEncodingInfo |
368 » nullable bool | |
369 readFunction string | 388 readFunction string |
370 } | 389 } |
371 | 390 |
372 func (t *handleTypeEncodingInfo) IsHandle() bool { | 391 func (t *handleTypeEncodingInfo) IsHandle() bool { |
373 return true | 392 return true |
374 } | 393 } |
375 | 394 |
376 func (t *handleTypeEncodingInfo) IsNullable() bool { | |
377 return t.nullable | |
378 } | |
379 | |
380 func (t *handleTypeEncodingInfo) BitSize() uint32 { | 395 func (t *handleTypeEncodingInfo) BitSize() uint32 { |
381 return 32 | 396 return 32 |
382 } | 397 } |
383 | 398 |
384 func (t *handleTypeEncodingInfo) WriteFunction() string { | 399 func (t *handleTypeEncodingInfo) WriteFunction() string { |
385 panic("No write function needs to be specified for handles.") | 400 panic("No write function needs to be specified for handles.") |
386 } | 401 } |
387 | 402 |
388 func (t *handleTypeEncodingInfo) ReadFunction() string { | 403 func (t *handleTypeEncodingInfo) ReadFunction() string { |
389 return t.readFunction | 404 return t.readFunction |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 473 } |
459 | 474 |
460 func (t *structTypeEncodingInfo) ReadFunction() string { | 475 func (t *structTypeEncodingInfo) ReadFunction() string { |
461 panic("Structs don't have a read function.") | 476 panic("Structs don't have a read function.") |
462 } | 477 } |
463 | 478 |
464 //////////////////////////////////////////////////////////////////////////////// | 479 //////////////////////////////////////////////////////////////////////////////// |
465 | 480 |
466 // unionTypeEncodingInfo is the EncodingInfo for a union. | 481 // unionTypeEncodingInfo is the EncodingInfo for a union. |
467 type unionTypeEncodingInfo struct { | 482 type unionTypeEncodingInfo struct { |
468 » baseEncodingInfo | 483 » baseNullableEncodingInfo |
469 nestedUnion bool | 484 nestedUnion bool |
470 nullable bool | |
471 } | 485 } |
472 | 486 |
473 func (t *unionTypeEncodingInfo) BitSize() uint32 { | 487 func (t *unionTypeEncodingInfo) BitSize() uint32 { |
474 if t.nestedUnion { | 488 if t.nestedUnion { |
475 return uint32(64) | 489 return uint32(64) |
476 } | 490 } |
477 return uint32(128) | 491 return uint32(128) |
478 } | 492 } |
479 | 493 |
480 func (t *unionTypeEncodingInfo) IsUnion() bool { | 494 func (t *unionTypeEncodingInfo) IsUnion() bool { |
481 return true | 495 return true |
482 } | 496 } |
483 | 497 |
484 func (t *unionTypeEncodingInfo) IsPointer() bool { | 498 func (t *unionTypeEncodingInfo) IsPointer() bool { |
485 return t.nestedUnion | 499 return t.nestedUnion |
486 } | 500 } |
487 | 501 |
488 func (b *unionTypeEncodingInfo) IsNullable() bool { | |
489 return b.nullable | |
490 } | |
491 | |
492 func (b *unionTypeEncodingInfo) setNullable(nullable bool) { | |
493 b.nullable = nullable | |
494 } | |
495 | |
496 func (t *unionTypeEncodingInfo) WriteFunction() string { | 502 func (t *unionTypeEncodingInfo) WriteFunction() string { |
497 panic("Unions don't have a write function.") | 503 panic("Unions don't have a write function.") |
498 } | 504 } |
499 | 505 |
500 func (t *unionTypeEncodingInfo) ReadFunction() string { | 506 func (t *unionTypeEncodingInfo) ReadFunction() string { |
501 panic("Unions don't have a read function.") | 507 panic("Unions don't have a read function.") |
502 } | 508 } |
503 | 509 |
504 //////////////////////////////////////////////////////////////////////////////// | 510 //////////////////////////////////////////////////////////////////////////////// |
505 | 511 |
(...skipping 10 matching lines...) Expand all Loading... |
516 return true | 522 return true |
517 } | 523 } |
518 | 524 |
519 func (t *enumTypeEncodingInfo) WriteFunction() string { | 525 func (t *enumTypeEncodingInfo) WriteFunction() string { |
520 panic("Enums don't have a write function.") | 526 panic("Enums don't have a write function.") |
521 } | 527 } |
522 | 528 |
523 func (t *enumTypeEncodingInfo) ReadFunction() string { | 529 func (t *enumTypeEncodingInfo) ReadFunction() string { |
524 return "ReadInt32" | 530 return "ReadInt32" |
525 } | 531 } |
| 532 |
| 533 //////////////////////////////////////////////////////////////////////////////// |
| 534 |
| 535 type interfaceTypeEncodingInfo struct { |
| 536 baseNullableEncodingInfo |
| 537 interfaceRequest bool |
| 538 } |
| 539 |
| 540 func (t *interfaceTypeEncodingInfo) IsInterface() bool { |
| 541 return true |
| 542 } |
| 543 |
| 544 func (t *interfaceTypeEncodingInfo) IsInterfaceRequest() bool { |
| 545 return t.interfaceRequest |
| 546 } |
| 547 |
| 548 func (t *interfaceTypeEncodingInfo) BitSize() uint32 { |
| 549 if t.interfaceRequest { |
| 550 return uint32(32) |
| 551 } else { |
| 552 return uint32(64) |
| 553 } |
| 554 } |
| 555 |
| 556 func (t *interfaceTypeEncodingInfo) WriteFunction() string { |
| 557 if t.interfaceRequest { |
| 558 return "WriteHandle" |
| 559 } else { |
| 560 return "WriteInterface" |
| 561 } |
| 562 } |
| 563 |
| 564 func (t *interfaceTypeEncodingInfo) ReadFunction() string { |
| 565 if t.interfaceRequest { |
| 566 return "ReadMessagePipeHandle" |
| 567 } else { |
| 568 return "ReadInterface" |
| 569 } |
| 570 } |
OLD | NEW |