GetKey.str 5.37 KB
Newer Older
1
/*
2
3
4
 * GetKey.str:
 * this file is a part of CxxGrammar from the Transformers project.
 * Copyright (C) 2004  EPITA Research and Development Laboratory.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
module GetKey

imports

  lib

imports

29
  AsFix
30
31
32
33
34
35
36
37
38
39
  Cxx
  Identifier
  Keys

signature
  constructors
    alias-table : Term -> Term

rules

40
41
42
43
44
45
46
47
48
49
50
51
52
53
  Namespace-GetKey : |NamespaceName[ ~OriginalNamespaceName: |OriginalNamespaceName[ ID ]|~ ]| -> key
                     where < identifier > ID => c
                         ; < rewrite (!"$namespace") > "$value" => d
                         ; !list-key([string-key(c)])
                         ; < ?list-key(a) > d
                         ; !list-key(<conc>(a, [string-key(c)])) => key

  Namespace-GetKey : |NamespaceName[ ~NamespaceAlias: |NamespaceAlias[ ID ]|~ ]| -> key
                     where < identifier > ID => c
                         ; < rewrite (!"$namespace") > "$value" => d
                         ; < get-alias > c
                         ; < ?(list-key(a), list-key(b)) > (d, <id>)
                         ; !list-key(<conc>(a, b)) => key

54
55
56
57
58
59
  TypeName-GetKey : |TypeName[ ~ClassName: |ClassName[ ID ]|~ ]| -> key
                     where < identifier > ID => c
                         ; < rewrite (!"$namespace") > "$value" => d
                         ; ( < scope(!"$namespace", lookup) > c => class-kind
                           ; !list-key([string-key(c)])
                          <+ < scope(!"$namespace", lookup) > c => type-kind
60
61
                           ; ( < get-alias > c
                             <+!list-key([string-key(c)])))
62
63
64
65
66
67
68
69
70
71
                         ; < ?(list-key(a), list-key(b)) > (d, <id>)
                         ; !list-key(<conc>(a, b)) => key

  TypeName-GetKey : |TypeName[ ~ClassName: |ClassName[ ~TemplateId: tid@|TemplateId[ID < TemplateArgumentList-opt > ]|~ ]|~ ]| -> key
                     where < identifier > ID => c
                         ; < template-arguments > TemplateArgumentList-opt => g
                         ; < rewrite (!"$namespace") > "$value" => d
                         ; ( < scope(!"$namespace", lookup) > c => class-template-kind(_)
                           ; !list-key([template-key(c,g)])
                          <+ < scope(!"$namespace", lookup) > c => type-kind
72
73
                           ; ( < get-alias > c
                             <+!list-key([string-key(c)])))
74
75
76
77
78
79
80
81
                         ; < ?(list-key(a), list-key(b)) > (d, <id>)
                         ; !list-key(<conc>(a, b)) => key


  TypeName-GetKey : |TypeName[ ~TypedefName: |TypedefName[ ID ]|~ ]| -> key
                    where < identifier > ID => c
                        ; < rewrite (!"$namespace") > "$value" => d
                        ; < scope (!"$namespace", lookup) > c => type-kind
82
83
                        ; ( < get-alias > c
                          <+!list-key([string-key(c)]))
84
85
86
87
                        ; < ?(list-key(a), list-key(b)) > (d, <id>)
                        ; !list-key(<conc>(a, b)) => key

  SimpleTypeSpecifier-GetKey : |SimpleTypeSpecifier[ Dummy0-opt NestedNameSpecifier-opt TypeName ]| -> key
88
89
90
91
92
93
94
95
96
97
98
99
                    where scope(!"$namespace",
                          < local-or-global > Dummy0-opt
                        ; < try(
                             ?|NestedNameSpecifier?[ ~NestedNameSpecifier: nested~ ]|;
                             !nested; nested-name-specifier; ?nested';
                             !|NestedNameSpecifier?[ ~NestedNameSpecifier: nested'~ ]|)
                          > NestedNameSpecifier-opt
                        ; < TypeName-GetKey > TypeName => key)

  QNamespace-GetKey : |QualifiedNamespaceSpecifier[ Dummy0-opt NestedNameSpecifier-opt NamespaceName ]| -> key
                    where scope(!"$namespace",
                          < local-or-global > Dummy0-opt
100
101
102
103
104
                        ; < try(
                             ?|NestedNameSpecifier?[ ~NestedNameSpecifier: nested~ ]|;
                             !nested; nested-name-specifier; ?nested';
                             !|NestedNameSpecifier?[ ~NestedNameSpecifier: nested'~ ]|)
                          > NestedNameSpecifier-opt
105
                        ; < Namespace-GetKey > NamespaceName => key)
106
107
108
109
110
111

strategies

  follow = rec x(?[e]; ![] <+ [id|x]) => ns
         ; <rewrite(!"$namespace")> "$value" => list-key(old)
         ; !list-key(<conc> (old, ns))
112
         ; <my-assert(!"$namespace")> ("$value", <id>)
113
114
115
116
117
118
119
120
121
122
123
         ; !e

  get-alias = scope(!"$namespace",
                 list-key(follow; string-key(?d))
               ; !d
               ; lookup(!alias-table(<id>)) => list-key(al)
	       ; <rewrite(!"$namespace")> "$value" => list-key(cur)
               ; !list-key(<conc> (cur, al))
               ; ?aliased
                   )
            ; !aliased