source: CMT/v1r19/source/cmt_include.cxx @ 597

Last change on this file since 597 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
RevLine 
[2]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"
[78]14#include "cmt_symbol.h"
[79]15#include "cmt_log.h"
[2]16
17/*----------------------------------------------------------*/
18/*                                                          */
19/*  Operations on Include                                   */
20/*                                                          */
21/*----------------------------------------------------------*/
22
[78]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 */
[2]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
[82]34  if (Cmt::get_current_access () == UserMode)
35    {
36      if (use->get_current_scope () == ScopePrivate) return;
37    }
38
[2]39  for (int i = 1; i < words.size (); i++)
40    {
[78]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       */
[2]49      name = words[i];
50      if (name == "") return;
[78]51
[2]52      add (name, use);
53    }
54}
55
[78]56/**
57   Search a database entry for this include_dirs matching the
58   duet {name, use}
59 */
[2]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
[78]85/**
86   Add a unique entry for this include_dirs specification given by the duet {name, use}
87 */
[2]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/*----------------------------------------------------------*/
[78]110void Include::clear_all ()
[2]111{
[78]112  for (int include_number = 0;
113       include_number < (Use::current()).includes.size ();
114       include_number++)
[2]115    {
[78]116      Include& incl = (Use::current()).includes[include_number];
[2]117
[78]118      incl.clear ();
119    }
120}
[2]121
[78]122/**
[79]123   Post processing of the include_dirs statements of a Use object.
[78]124   This is meant to expand all macro references used in the
125   include_dirs statements
[2]126
[78]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 */
[79]130void Include::parse_all (Use* use)
[78]131{
[79]132  int size;
133  int i;
[2]134
[79]135  size = use->includes.size ();
136  for (i = 0; i < size; i++)
[2]137    {
[79]138      Include& incl = use->includes[i];
[2]139
[78]140      incl.parse ();
[2]141    }
142}
143
144/*----------------------------------------------------------*/
[78]145void Include::clear ()
[2]146{
[78]147  use = 0;
148}
[2]149
[78]150/**
151   Post processing of an include_dirs statement.
[2]152
[78]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{
[79]160  cmt_string new_name = name;
[2]161
[79]162  Symbol::expand (new_name);
163
164  if (new_name == name) return;
165
[78]166  CmtSystem::cmt_string_vector ws;
[2]167
[78]168  ws.clear ();
[2]169
[79]170  CmtSystem::split (new_name, " ", ws);
[2]171
[78]172  name = "";
[2]173
[78]174  for (int j = 0; j < ws.size (); j++)
175    {
176      const cmt_string& w = ws[j];
[2]177
[78]178      add (w, use);
179    }
[79]180
181  use = 0;
[2]182}
183
184/*----------------------------------------------------------*/
185Include::Include ()
186{
[78]187  clear ();
[2]188}
189
190/*----------------------------------------------------------*/
191Include::~Include ()
192{
193  use = 0;
194}
195
Note: See TracBrowser for help on using the repository browser.