source: CMT/v1r20p20070208/source/cmt_include.cxx

Last change on this file was 82, checked in by arnault, 19 years ago

Make include_dirs subject to private sections - see CL#277

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <ctype.h>
11
12#include "cmt_include.h"
13#include "cmt_use.h"
14#include "cmt_symbol.h"
15#include "cmt_log.h"
16
17/*----------------------------------------------------------*/
18/*                                                          */
19/*  Operations on Include                                   */
20/*                                                          */
21/*----------------------------------------------------------*/
22
23/**
24   Executed to parse an include_dirs statement
25   It postpones the macro expansion to the post-processing stage
26   (during set_standard_macros)
27 */
28void Include::action (const CmtSystem::cmt_string_vector& words, Use* use)
29{
30  cmt_string name;
31
32  if (use == 0) use = &(Use::current());
33
34  if (Cmt::get_current_access () == UserMode)
35    {
36      if (use->get_current_scope () == ScopePrivate) return;
37    }
38
39  for (int i = 1; i < words.size (); i++)
40    {
41      /*
42        statement words may contain macro references at that level
43        they are stored as they are.
44        They will be expanded later on using the parse_all method
45
46        (called from set_standard_macros)
47
48       */
49      name = words[i];
50      if (name == "") return;
51
52      add (name, use);
53    }
54}
55
56/**
57   Search a database entry for this include_dirs matching the
58   duet {name, use}
59 */
60Include* Include::find (const cmt_string& name, Use* use)
61{
62  int include_index;
63
64  if (use == 0) use = &(Use::current());
65
66  if (use->includes.size () == 0) return (0);
67
68  for (include_index = 0;
69       include_index < use->includes.size ();
70       include_index++)
71    {
72      Include& incl = use->includes[include_index];
73
74      if (incl.use != use) continue;
75
76      if (incl.name == name)
77        {
78          return (&incl);
79        }
80    }
81
82  return (0);
83}
84
85/**
86   Add a unique entry for this include_dirs specification given by the duet {name, use}
87 */
88Include* Include::add (const cmt_string& name, Use* use)
89{
90  if (name == "") return (0);
91
92  if (use == 0) use = &(Use::current());
93
94  {
95    Include* incl;
96
97    incl = find (name, use);
98    if (incl != 0) return (incl);
99  }
100
101  Include& incl = use->includes.add ();
102
103  incl.name = name;
104  incl.use = use;
105
106  return (&incl);
107}
108
109/*----------------------------------------------------------*/
110void Include::clear_all ()
111{
112  for (int include_number = 0;
113       include_number < (Use::current()).includes.size ();
114       include_number++)
115    {
116      Include& incl = (Use::current()).includes[include_number];
117
118      incl.clear ();
119    }
120}
121
122/**
123   Post processing of the include_dirs statements of a Use object.
124   This is meant to expand all macro references used in the
125   include_dirs statements
126
127   Note that this may create new Include objects. Thus the loop is
128   only performed onto the existing objects before the post-processing step
129 */
130void Include::parse_all (Use* use)
131{
132  int size;
133  int i;
134
135  size = use->includes.size ();
136  for (i = 0; i < size; i++)
137    {
138      Include& incl = use->includes[i];
139
140      incl.parse ();
141    }
142}
143
144/*----------------------------------------------------------*/
145void Include::clear ()
146{
147  use = 0;
148}
149
150/**
151   Post processing of an include_dirs statement.
152
153   The name field is expanded for its macro references
154   and split into individual words.
155   Each word in turn generates a new Include object
156   The old Include object is inactivated by setting an empty name
157 */
158void Include::parse ()
159{
160  cmt_string new_name = name;
161
162  Symbol::expand (new_name);
163
164  if (new_name == name) return;
165
166  CmtSystem::cmt_string_vector ws;
167
168  ws.clear ();
169
170  CmtSystem::split (new_name, " ", ws);
171
172  name = "";
173
174  for (int j = 0; j < ws.size (); j++)
175    {
176      const cmt_string& w = ws[j];
177
178      add (w, use);
179    }
180
181  use = 0;
182}
183
184/*----------------------------------------------------------*/
185Include::Include ()
186{
187  clear ();
188}
189
190/*----------------------------------------------------------*/
191Include::~Include ()
192{
193  use = 0;
194}
195
Note: See TracBrowser for help on using the repository browser.