From 2e90e5424ee21cc3303bd2479e7ab5e935191326 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 30 Oct 2008 15:52:37 -0700 Subject: [PATCH] - language for struct field tags DELTA=17 (15 added, 0 deleted, 2 changed) OCL=18177 CL=18184 --- doc/go_spec.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.txt b/doc/go_spec.txt index 8978434ddb..dbd7fa40c6 100644 --- a/doc/go_spec.txt +++ b/doc/go_spec.txt @@ -4,7 +4,7 @@ The Go Programming Language Specification (DRAFT) Robert Griesemer, Rob Pike, Ken Thompson ---- -(October 28, 2008) +(October 30, 2008) This document is a semi-formal specification of the Go systems @@ -1094,7 +1094,8 @@ identifier may be declared twice and all field types must be complete types (§Types). StructType = "struct" [ "{" [ List ] "}" ] . - FieldDecl = IdentifierList CompleteType | TypeName . + FieldDecl = (IdentifierList CompleteType | TypeName) [ Tag ] . + Tag = string_lit . // An empty struct. struct {} @@ -1135,6 +1136,20 @@ Fields and methods (§Method declarations) of an anonymous field become directly accessible as fields and methods of the struct without the need to provide the type name of the respective anonymous field (§Selectors). +A field declaration may be followed by an optional string literal tag which +becomes an ``attribute'' for all the identifiers in the corresponding +field declaration. The tags are available via the reflection library but +are ignored otherwise. A tag may contain arbitrary application-specific +information (for instance protocol buffer field information). + + // A struct corresponding to the EventIdMessage protocol buffer. + // The tag strings contain the protocol buffer field tags. + struct { + time_usec uint64 "1"; + server_ip uint32 "2"; + process_id uint32 "3"; + } + Forward declaration: A struct type consisting of only the reserved word "struct" may be used in a type declaration; it declares an incomplete struct type (§Type declarations). -- 2.48.1