File: ACCompiler.cc

package info (click to toggle)
aspectc%2B%2B 1%3A2.3%2Bgit20241211-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 18,148 kB
  • sloc: cpp: 110,334; ansic: 7,644; sh: 2,262; makefile: 1,344; pascal: 634; python: 402; xml: 349
file content (127 lines) | stat: -rw-r--r-- 3,766 bytes parent folder | download | duplicates (7)
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
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2004  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 "ACCompiler.h"
#include "System.h"
#include "regex.h"
#include "file.h"

//stdc++ includes
#include<string>
using namespace std;
using namespace file;

//Puma includes
#include "Puma/VerboseMgr.h"
#include "Puma/SysCall.h"

bool
ACCompiler::execute()
{

  VerboseMgr vm(cout, _config.verbose());
  vm << "Weaving" << endvm;

  // command line string
  string exec_str = "\"" + _config.acc_bin() + "\" --system-config \""
      + _config.pumaconfig_file() + "\" "
      + _config.optvec().getString(OptionItem::OPT_ACC, OptionItem::OPT_FILE);

  // get output path for .acc files from -o option
  string acc_output_path = _config.output_file();
  file::stripFilename(acc_output_path);

  // loop through all options searching a file
  OptionVec::iterator opt = _config.optvec().begin();
  while (opt != _config.optvec().end())
  {
    // skip all options that are not a file which should be processed by
    // AspectC++
    if ((opt->flag() & (OptionItem::OPT_ACC | OptionItem::OPT_FILE))
        != (OptionItem::OPT_ACC | OptionItem::OPT_FILE))
    {
      opt++;
      continue;
    }

    const string file = opt->name();

    //construct name for output file
    string out_file;

    // if an output file for the woven result is not specified on command line
    // or the file(s) shall be compiled after weaving put an intermediate .acc file
    // in acc_output_path
    if (_config.compile() == true || _config.output_file().empty())
    {
      //if we do not want to keep the intermediate acc files
      //generate files in the systems temporary directory
      if (_config.keep_woven() == false)
      {
        string prefix(file);
        stripPath(prefix);
        prefix.append("_agxx_");
        char* tmp_file = (char*) Puma::SysCall::mktemp(prefix.c_str(), &_err);
        out_file = tmp_file;
        free(tmp_file);
      }
      //otherwise create name of output file from name of output file
      else
      {
        string tmp(file);
        stripPath(tmp);
        out_file = tmp;
        int endpos = out_file.rfind('.');
        out_file.replace(endpos, string::npos, ".acc");
        out_file = acc_output_path + out_file;
      }
    }
    else
    {
      out_file = _config.output_file();
    }

    // construct final command string
    string local_exec_str = exec_str + " -c \"" + file + "\" -o \"" + out_file
        + "\"";

    // execute AspectC++
    System acc(_err, _config, local_exec_str);

    //change filename in input_file list, so that the next steps
    //get the proper filename
    opt->name(out_file);
    opt->flag(opt->flag() | (OptionItem::OPT_GCC));

    if (!acc.execute())
    {
      return false;
    }

    opt++;
  }

  // Call Aspect C++ once in case there are no input files
  if ((_config.nr_files() == 0) && (_config.run_acpp_without_input() == true))
  {
    System acc(_err, _config, exec_str);
    return acc.execute();
  }

  return true;
}