~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// This file is part of PUMA.
// Copyright (C) 1999-2003  The PUMA developer team.
//                                                                
// 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                                            

#ifndef __CSemantic_h__
#define __CSemantic_h__

#include "Puma/Semantic.h"
#include "Puma/CBuilder.h"
#include "Puma/CLinkage.h"
#include "Puma/CProtection.h"
#include "Puma/CTree.h"

namespace Puma {
  class CSyntax;
}

namespace Puma {

class CSemantic : public Semantic {
  CSyntax &_syntax;
  CBuilder &_builder;

protected:
  enum SemObjType { 
    CLASS, UNION, ENUM,  TYPEDEF, FCT,  ATTRIB, ARG,  TAG, NON_TAG,  ANY 
  };

  bool in_arg_decl;
  bool _in_arg_decl_seq;
  bool is_type_name;
  bool support_implicit_int;
  
  void declareImplicitFcts () {} // builtin functions

public:
  CSemantic (CSyntax &, CBuilder &);

  virtual void init (CClassDatabase &, Unit &);
  void configure (Config &);

protected:
  virtual CBuilder &builder () const;
  virtual CSyntax &syntax () const;
  virtual void Delete ();

public:
  // control parse process
  virtual CTree *id_expr ();
  virtual CTree *typedef_name ();
  virtual CTree *init_declarator (CTree *);
  virtual CTree *abst_declarator ();
  virtual CTree *direct_abst_declarator ();
  virtual CTree *param_decl_clause ();
  virtual CTree *finish_fct_def ();
  virtual CTree *arg_decl_seq ();
  virtual CTree *decl_spec_seq1 ();
  virtual CTree *decl_spec_seq_err ();
  virtual CTree *class_spec_err (CTree *);
  virtual CTree *declare_parameter ();
  virtual CTree *identifier_list ();
  virtual CTree *finish_param_check ();
  virtual CTree *begin_decl ();

  // add scope information to tree nodes
  virtual CTree *trans_unit ();
  virtual CTree *class_spec ();
  virtual CTree *cmpd_stmt ();
  virtual CTree *select_stmt ();
  virtual CTree *iter_stmt ();

  // introduce names... add new entries to the class database
  virtual CTree *introduce_label ();
  virtual CTree *introduce_object ();
  virtual CTree *introduce_named_type ();
  virtual CTree *introduce_enum ();
  virtual CTree *introduce_enumerator ();
  virtual CTree *introduce_function ();
  virtual CTree *introduce_parameter ();
  virtual CTree *introduce_class ();
  virtual CTree *introduce_member ();
  virtual CTree *introduce_tag ();

public: // change or get semantic state information
  void enter_arg_decl_seq ();
  void leave_arg_decl_seq ();
  void begin_param_check ();
  bool in_arg_decl_seq () const;
  bool decl_spec_seq ();
  bool empty_decl_spec_seq ();
  virtual bool implicit_int ();
  virtual CProtection::Type protection () const;
  
protected:
  CObjectInfo *lookup (const char *, SemObjType, bool = false) const;
  CObjectInfo *lookup (CT_SimpleName *, SemObjType, bool = false) const;
  CObjectInfo *lookup (const char *, CStructure *, SemObjType, bool) const;

  CLinkage::Type determine_linkage (CSemDeclSpecs *, SemObjType, 
    CObjectInfo * = (CObjectInfo*)0) const;
  CStorage::Type determine_storage_class (CSemDeclSpecs *, SemObjType, 
    CLinkage::Type) const;

  // helper
  bool typeMatch (CTypeInfo *, CTypeInfo *) const;
  CStructure *findParent () const;
  void setSpecifiers (CObjectInfo *, CSemDeclSpecs *) const;
  bool isRedefiningTypedef (CObjectInfo*, int obj_type) const;

  // create class DB objects
  CAttributeInfo *createAttribute (const char *, CStructure *, CTypeInfo *,
                                   bool = false);
  CTypedefInfo *createTypedef (const char *, CStructure *, CTypeInfo *);
  void createParameter (CFunctionInfo *, CTypeInfo *);
  CFunctionInfo *createFunction (const char *, CStructure *, CTypeInfo *);
};

inline CSemantic::CSemantic (CSyntax &s, CBuilder &b) : 
  _syntax (s), _builder (b),
  in_arg_decl (false),
  _in_arg_decl_seq (false),
  is_type_name (false),
  support_implicit_int (true)
 {}

inline CBuilder &CSemantic::builder () const 
 { return _builder; }

inline CSyntax &CSemantic::syntax () const 
 { return _syntax; }

inline CObjectInfo *CSemantic::lookup (const char *id, SemObjType type, 
  bool nested) const
 { return lookup (id, current_scope, type, nested); }
inline CObjectInfo *CSemantic::lookup (CT_SimpleName *id, SemObjType type, 
  bool nested) const
 { return lookup (id->Text (), current_scope, type, nested); }

inline bool CSemantic::in_arg_decl_seq () const 
 { return _in_arg_decl_seq; }
inline void CSemantic::enter_arg_decl_seq () 
 { _in_arg_decl_seq = true; _in_param_decl_clause.push (true); }
inline void CSemantic::leave_arg_decl_seq () 
 { _in_arg_decl_seq = false; _in_param_decl_clause.pop (); }

inline CProtection::Type CSemantic::protection () const
 { return CProtection::PROT_NONE; }

} // namespace Puma

#endif /* __CSemantic_h__ */