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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
// 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 <stdio.h>
#include <stdlib.h>
#include "Puma/ErrorSink.h"
#include "Puma/FileUnit.h"
#include "Repository.h"
#include "version.h"
#include "PointCut.h"
#include "TransformInfo.h"
#include "OrderInfo.h"
#include "AdviceInfo.h"
#include "AspectInfo.h"
#include "RepoXMLDoc.h"
void Repository::open (const char *name, ErrorSink &err) {
RepoXMLDoc doc;
create (name);
if (!doc.load (name) || !doc.root ().has_name ("ac-project")) {
err << sev_error << "project repository '" << name << "' cannot be opened"
" or is invalid" << endMessage;
return;
}
string version = doc.root ().get_str_prop ("version");
if (version != ac_version ()) {
err << sev_warning << "project file version '"
<< version.c_str () << "' differs from ac++ version" << endMessage;
}
RepoXMLNode joinpoints, files, aspects, adv;
// iterate the top-level project elements
for (RepoXMLNode::iter curr = doc.root ().first_child ();
curr != doc.root ().end_child (); ++curr) {
if ((*curr).has_name ("joinpoint-list"))
joinpoints = *curr;
else if ((*curr).has_name ("file-list"))
files = *curr;
else if ((*curr).has_name ("aspect-list"))
aspects = *curr;
else if ((*curr).has_name ("advice-list"))
adv = *curr;
}
if (!joinpoints || !files || !aspects || !adv) {
err << sev_error << "invalid project file, missing list" << endMessage;
return;
}
// now read all join points, files, and aspects
_jprepo.get_xml (joinpoints);
_advrepo.get_xml (adv);
_asprepo.get_xml (aspects);
_frepo.get_xml (files);
}
void Repository::create (const char *name) {
_name = name;
}
void Repository::save (ErrorSink &err) {
// create an XML DOM
RepoXMLDoc doc;
doc.create ("ac-project");
doc.root ().set_str_prop ("version", ac_version ());
// handle join points, files, and aspects
_jprepo.make_xml (doc.root ());
_advrepo.make_xml (doc.root ());
_asprepo.make_xml (doc.root ());
_frepo.make_xml (doc.root ());
// save the file
if (!doc.save (_name)) {
err << sev_error << "Saving repository '" << _name << "' failed"
<< endMessage;
}
}
void Repository::close () {
_name = (const char *)0;
}
const SourceLoc *Repository::source_loc (JoinPointLoc &jpl) {
const SourceLoc *src = 0;
set<SourceLoc> &source_locs = (jpl.type () &
(JoinPointLoc::Method|JoinPointLoc::Construction|JoinPointLoc::Destruction)) ?
jpl.parent ()->source_locs () : jpl.source_locs ();
for (set<SourceLoc>::iterator i = source_locs.begin ();
i != source_locs.end (); ++i) {
if ((*i).kind () != SLK_DECL) {
src = &(*i);
break;
}
}
return src;
}
Repository::REPO_ID Repository::consider (const Unit &unit) {
if (!unit.isFile ())
return -1;
return _frepo.insert (unit.name (),
((Token*)unit.last ())->location ().line (), _primary);
}
Repository::REPO_ID Repository::consider (const File &file) {
return _frepo.insert (file.name ().c_str (), file.len (), _primary);
}
Repository::REPO_ID Repository::consider (JoinPointLoc &jpl, int adv) {
const SourceLoc *src = source_loc (jpl);
if (!src)
return -1;
REPO_ID file_id = consider (*(const File*)jpl.map (src->file_id()));
REPO_ID jp_id = _jprepo.insert (file_id, src->line (), jpl.signature (),
jpl.type_str (), adv, src->len ());
return jp_id;
}
Repository::REPO_ID Repository::consider (JPL_Aspect &jpl) {
const SourceLoc *src = source_loc (jpl);
if (!src)
return -1;
REPO_ID file_id = consider (*(const File*)jpl.map (src->file_id()));
return _asprepo.insert (file_id, src->line (), jpl.signature ());
}
Repository::REPO_ID Repository::consider (JPL_Introduction &intro) {
const SourceLoc *src = source_loc (intro);
if (!src)
return -1;
// remember aspect and advice information in the project repository
REPO_ID aspect_id = consider (*(JPL_Aspect*)intro.parent ());
REPO_ID file_id = consider (*(const File*)intro.map (src->file_id()));
REPO_ID advice_id = _advrepo.insert (file_id, src->line (),
intro.type_str (), aspect_id, src->len ());
return advice_id;
}
void Repository::setup (Unit* prim_unit) {
_frepo.noref ();
_jprepo.noref ();
_advrepo.noref ();
_asprepo.noref ();
_primary = -1;
_primary = consider (*prim_unit);
}
void Repository::cleanup () {
set<int> dep_files;
_frepo.dependent (_primary, dep_files);
_jprepo.cleanup (dep_files);
_advrepo.cleanup (dep_files);
_asprepo.cleanup (dep_files);
_frepo.cleanup (_primary);
}
void Repository::update (JPL_Introduction &intro, JPL_Class &cls) {
// remember aspect information in the project repository
REPO_ID advice_id = consider (intro);
REPO_ID jp_id = consider (cls, advice_id);
cls.assigned_id (jp_id);
}
void Repository::update (AdviceInfo &ai, PointCut &target) {
// remember aspect information in the project repository
REPO_ID aspect_id = consider (ai.aspect ());
const SourceLoc *src = source_loc (ai.code ());
if (!src)
return;
REPO_ID file_id = consider (*(const File*)ai.code ().map (src->file_id()));
REPO_ID advice_id = _advrepo.insert (file_id, src->line (),
ai.code ().type_str (), aspect_id, src->len ());
for (PointCut::iterator iter = target.begin ();
iter != target.end (); ++iter) {
JoinPointLoc &jpl = *((*iter).location ());
const SourceLoc *src = source_loc (jpl);
if (!src)
continue;
REPO_ID jp_id = consider (jpl, advice_id);
jpl.assigned_id (jp_id);
}
}
void Repository::update (OrderInfo &oi) {
// remember order advice information in the project repository
REPO_ID aspect_id = consider (oi.aspect ());
const SourceLoc *src = source_loc (oi.order ());
if (!src)
return;
REPO_ID file_id = consider (*(const File*)oi.order ().map (src->file_id()));
/* REPO_ID advice_id = */ _advrepo.insert (file_id, src->line (),
"order", aspect_id, src->len ());
}
|