ClassDefinition.str 3.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * Copyright (C) 2003  EPITA Research and Development Laboratory
 *
 * 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
 *
 */
david_v's avatar
david_v committed
19
20
21
22
23
24
25
26
27
module ClassDefinition

imports

  lib

imports

  AsFix2-Syntax
28
29
  asfix
  Cxx
david_v's avatar
david_v committed
30
31
32
33
34
35
36
37
38
39
  ClassDefinitionCandidate
  Identifier
  Kinds

rules

  //
  // Process definition of class C in namespace N.
  //

40
41
  ClassDefinition : a@|ClassSpecifier[ ClassKey ID BaseClause-opt { MemberSpecification-opt } ]| -> a
                    where < identifier > ID => c                               // Read identifier (name of C).
david_v's avatar
david_v committed
42
43
44
45
46
47
48
49
50
                        ; < rewrite (!"$namespace") > "$value" => d                    // Get current namespace name.
                        ; < assert (!d) > (c, class-kind)                              // In N, mark C as being a class.
                        ; < ?list-key (as); !as > d => d'                              // Extract the list of nested namespace names.
                        ; < conc; ?x; !list-key (x) > (d', [string-key (c)]) => e      // Append the new namespace name to the current list.
                        ; < print-key > e => e'                                        // Print the current list (this is for debugging only).
                        ; < concat-strings; debug > ["+ Definition of class", " ", e']
                        ; < init-name-space (!e) > a                                   // Initialize symbol table for N.
                        ; < begin-scope (!"$namespace") > a                            // Save old current namespace name.
                        ; < assert (!"$namespace") > ("$value", e)                     // Set new current namespace name.
51
                        ; < definition > MemberSpecification-opt                       // Process the class definition body.
david_v's avatar
david_v committed
52
53
54
                        ; < end-scope (!"$namespace") > a                              // Restore old current namespace name.
                        ; < concat-strings; debug > ["- Definition of class", " ", e']

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  ClassDefinition : a@|ElaboratedTypeSpecifier[ ClassKey Dummy0-opt NestedNameSpecifier-opt ID ]| -> a
                    where scope(!"$namespace",
                            < local-or-global > Dummy0-opt
                          ; < try(
                              ?|NestedNameSpecifier?[ ~NestedNameSpecifier: nested~ ]|;
                              !nested; nested-name-specifier; ?nested';
                              !|NestedNameSpecifier?[ ~NestedNameSpecifier: nested'~ ]|)
                              > NestedNameSpecifier-opt
                          ; < identifier > ID => c
                          ; < rewrite (!"$namespace") > "$value" => d
                          ; < assert (!d) > (c, class-kind)
                          ; < ?list-key (as); !as > d => d'
                          ; < conc; ?x; !list-key (x) > (d', [string-key (c)]) => e
                          ; < print-key > e => e'
                          ; < concat-strings; debug > ["Declaration of class", " ", e'])

david_v's avatar
david_v committed
71
72
strategies

73
  class-definition-stop(s) = class-definition-candidate
david_v's avatar
david_v committed
74
75
76

  class-definition = (class-definition-candidate;
                      ClassDefinition)