-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aliases.t2t
99 lines (67 loc) · 2.31 KB
/
Aliases.t2t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Aliases
%!includeconf: config.t2t
== Basic Usage ==
An alias is used to give a symbol a new name. The two names can be used
interchangeably and will behave identically. An example of an alias is below.
```
alias languages::vitrualmachine::java::files::jar::Jar JJar;
```
Now you may use JJar in place of languages::vitrualmachine::java::files::jar.
This allows the following code:
```
// main.pool
import containers::jar;
import languages::vitrualmachine::java::files::jar;
{ int main ( String[] arg );
var jars = new containers::jar::Jar();
jars.insert(new languages::vitrualmachine::java::files::jar::Jar(arg[1]));
}
```
becomes:
```
// main.pool
import containers::jar;
import languages::vitrualmachine::java::files::jar;
alias containers::jar::Jar GJar;
alias languages::vitrualmachine::java::files::jar::Jar JJar;
{ int main ( String[] arg );
var jars = new GJar();
jars.insert(new JJar(arg[1]));
}
```
Allowing you to use both your glass jars and ``.jar``s with ease.
It is usefull to give meaningful names to types.
```
{ (int32, uint) getDateFromServer ( uint64, uint64 ); /+ code +/ }
// Pretty meaningless based on it's type signature.
alias int32 TimeStamp;
alias uint ResponseCode;
alias uint64 PostId;
alias uint64 AuthToken;
// Now the definition is more meaningful.
{ (TimeStamp, ResponseCode) getDateFromServer ( AuthToken, PostId ); /+ code +/ }
```
== Disambiguating Aliases ==
Sometimes, like in the previous examples you get two symbols with the same name
from two different modules. If you want to use one without having to fully
qualify paths you can alias the symbol over itself.
```
alias containers::jar::Jar Jar;
```
Now, any reference to ``Jar`` will refer to ``containers::jar::Jar`` without
needing to be fully qualified.
== Scoped Aliases ==
Aliases are only valid in the scope in which they are declared and only below
where they exist in the source file.
```
var score :Score = 1_000_000; // ERROR: Score is undefined.
alias uint Score;
var score :Score = 1_000_000; // Good.
{
alias uint32 Timeval;
var t :Timeval = 779573880;
}
var curTime :Timeval = 779573880; // ERROR: Timeval undefined.
```
This is a recommended way of using aliases as shortcuts as the definition is
close to the useage. This prevents confusion when unreadable names are used.