2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 CompilationUnit::CompilationUnit ( const File
* file
)
31 default_name
= new FileLocation ( IntermediateDirectory
,
35 name
= file
->file
.relative_path
+ sSep
+ file
->file
.name
;
36 files
.push_back ( file
);
39 CompilationUnit::CompilationUnit ( const Project
* project
,
41 const XMLElement
* node
)
46 const XMLAttribute
* att
= node
->GetAttribute ( "name", true );
49 default_name
= new FileLocation ( IntermediateDirectory
,
50 module
? module
->output
->relative_path
: "",
53 name
= module
->output
->relative_path
+ cSep
+ att
->value
;
56 CompilationUnit::~CompilationUnit ()
59 for ( i
= 0; i
< files
.size (); i
++ )
66 CompilationUnit::ProcessXML ()
69 for ( i
= 0; i
< files
.size (); i
++ )
70 const_cast<File
*> ( files
[i
] )->ProcessXML ();
74 CompilationUnit::IsGeneratedFile () const
76 if ( files
.size () != 1 )
78 const File
* file
= files
[0];
79 string extension
= GetExtension ( file
->file
);
80 return ( extension
== ".spec" || extension
== ".SPEC" || extension
== ".mc" || extension
== ".MC");
84 CompilationUnit::HasFileWithExtension ( const std::string
& extension
) const
87 for ( i
= 0; i
< files
.size (); i
++ )
89 const File
& file
= *files
[i
];
90 string fileExtension
= GetExtension ( file
.file
);
91 if ( !stricmp ( fileExtension
.c_str (), extension
.c_str () ) )
98 CompilationUnit::IsFirstFile () const
100 if ( files
.size () == 0 || files
.size () > 1 )
102 const File
* file
= files
[0];
108 CompilationUnit::GetFilename () const
110 if ( files
.size () == 0 || files
.size () > 1 )
111 return *default_name
;
113 const File
* file
= files
[0];
118 CompilationUnit::GetSwitches () const
120 static const std::string empty_string
= std::string("");
121 if ( files
.size () == 0 || files
.size () > 1 )
123 const File
* file
= files
[0];
124 return file
->switches
;
128 CompilationUnit::AddFile ( const File
* file
)
130 files
.push_back ( file
);
133 const std::vector
<const File
*>
134 CompilationUnit::GetFiles () const