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
|
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
//
// 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
#include "AspectIncludes.h"
#include "AspectInfo.h"
#include "Naming.h"
#include "TransformInfo.h"
#include "Puma/Unit.h"
#include "Puma/CTree.h"
#include "Puma/CProject.h"
#include "Puma/Filename.h"
// helper function that find the unit in which an advice code is defined
Unit *AspectIncludes::aspect_unit (JPL_Aspect *a) {
return TI_Aspect::unit (*a);
// return (Unit*)ai->ClassInfo ()->SourceInfo ()->StartToken ()->token ()->
// belonging_to ();
}
// this function declares that a unit 'iu' depends on the aspect 'ai'
void AspectIncludes::insert (Unit *iu, AspectInfo *a, AspectRef::Kind kind) {
assert (iu);
// check if there is already an entry for this unit
iterator entry = find (iu);
if (entry == end ()) {
// there is no entry for the unit 'iu' yet => make a new one
AspectRefSet new_set;
new_set.insert (AspectRef (a, kind));
UnitAspectRefMap::insert (value_type (iu, new_set));
}
else {
// entry found add the aspect reference to the stored set
AspectRefSet &set = (*entry).second;
AspectRefSet::iterator ref_entry =
set.find (AspectRef (a, AspectRef::AR_UNKNOWN));
if (ref_entry == set.end ()) {
// simply insert a new entry if the aspect has not been found
set.insert (AspectRef (a, kind));
}
else {
// a definition request dominates a declaration request...
AspectRef &ref = (AspectRef&)(*ref_entry);
if (kind > ref._kind)
ref._kind = kind;
}
}
}
// generate the #include directive for a given aspect header unit
string AspectIncludes::generate (CProject &project, JPL_Aspect *a) {
string include_directive;
Unit *unit = aspect_unit (a);
// get the name, which we have to use to include the file
Filename include_file = project.getInclString (unit->name ());
include_directive += "#include \"";
include_directive += include_file.name ();
include_directive += "\"";
return include_directive;
}
// generate the #include directives for a given unit
string AspectIncludes::generate (const_iterator entry,
const BackEndProblems &bep) const {
string includes;
const AspectRefSet &set = (*entry).second;
for (AspectRefSet::const_iterator iter = set.begin ();
iter != set.end (); ++iter) {
switch ((*iter)._kind) {
case AspectRef::AR_DECL:
includes += "class ";
includes += (*iter)._aspect->name ();
includes += ";\n";
break;
case AspectRef::AR_ADVICE:
{
includes += (*iter)._aspect->ifct_decls (bep);
Unit *unit = aspect_unit (&(*iter)._aspect->loc ());
assert (unit && unit->isFile ());
stringstream define;
define << "#ifndef __ac_need_";
Naming::mangle_file (define, (FileUnit*)unit);
define << endl << "#define __ac_need_";
Naming::mangle_file (define, (FileUnit*)unit);
define << endl << "#endif" << endl;
includes += define.str ();
}
break;
default:
cout << "aspect ref type not yet implemented" << endl;
}
}
return includes;
}
|