Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
c2c49bec
Commit
c2c49bec
authored
Aug 21, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added scope rules, removed TODO
R=r DELTA=26 (19 added, 0 deleted, 7 changed) OCL=14358 CL=14386
parent
bb059426
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
go_lang.txt
doc/go_lang.txt
+26
-6
No files found.
doc/go_lang.txt
View file @
c2c49bec
...
...
@@ -1013,19 +1013,39 @@ Literals
Literal = char_lit | string_lit | int_lit | float_lit | FunctionLit | "nil" .
Declarations
Declaration
and scope rule
s
----
A declaration associates a name with a language entity such as a constant, type,
variable, or function.
Every identifier in a program must be declared; some identifiers, such as "int"
and "true", are predeclared. A declaration associates an identifier
with a language entity (package, constant, type, variable, function, method,
or label) and may specify properties of that entity such as its type.
Declaration = [ "export" ] ( ConstDecl | TypeDecl | VarDecl | FunctionDecl ) .
The ``scope'' of a language entity named 'x' extends textually from the point
immediately after the identifier 'x' in the declaration to the end of the
surrounding block (package, function, struct, or interface), excluding any
nested scopes that redeclare 'x'. The entity is said to be local to its scope.
Declarations in the package scope are ``global'' declarations.
The following scope rules apply:
1. No identifier may be declared twice in a single scope.
2. A language entity may only be referred to within its scope.
3. Field and method identifiers may be used only to select elements
from the corresponding types. In effect, the field selector operator
'.' temporarily re-opens the scope of such identifiers (see Expressions).
4. Forward declaration: A type of the form "*T" may be mentioned at a point
where "T" is not yet declared. The declaration of "T" must follow in the
same package and "T" must be visible at the end of the block containing "*T".
Global declarations optionally may be marked for export with the reserved word
"export". Local declarations can never be exported.
All identifiers (and only those identifiers) declared in exported declarations
are made visible to clients of this package, that is other packages that import
are made visible to clients of this package, that is
,
other packages that import
this package.
If the declaration defines a type, the type structure is exported as well. In
particular, if the declaration defines a new "struct" or "interface" type,
all structure fields and all structure and interface methods are exported also.
...
...
@@ -1037,8 +1057,8 @@ Note that at the moment the old-style export via ExportDecl is still supported.
TODO: Eventually we need to be able to restrict visibility of fields and methods.
(gri) The default should be no struct fields and methods are automatically exported.
TODO: specify range of visibility, scope rules
.
Export should be identifier-based: an identifier is either exported or not, and thus
visible or not in importing package
.
[OLD
Declaration = ConstDecl | TypeDecl | VarDecl | FunctionDecl | ExportDecl .
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment