~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/examples/annotator/annotator.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Transformer.h"
 
2
#include <Puma/CProject.h>
 
3
#include <Puma/CTranslationUnit.h>
 
4
#include <Puma/CCParser.h>
 
5
//#include <Puma/CPrintVisitor.h>
 
6
//#include <Puma/CCSemVisitor.h>
 
7
//#include <Puma/PrePrintVisitor.h>
 
8
//#include <Puma/PreTree.h>
 
9
#include <iostream>
 
10
 
 
11
 
 
12
int main(int argc, char** argv) {
 
13
  // This is the error stream object used throughout
 
14
  // the whole system, it supports several error 
 
15
  // severities and auto-formatted error location
 
16
  // output.
 
17
  Puma::ErrorStream err;
 
18
 
 
19
  // The project handles all file related task like
 
20
  // finding, opening, writing, and closing files.
 
21
  // The special CProject additionally is able to
 
22
  // scan files and strings, i.e. it provides an easy
 
23
  // to use interface to the lexical analyzer (scanner).
 
24
  Puma::CProject project(err, argc, argv);
 
25
  // Set the initial source/destination path pair. If 
 
26
  // a file shall be written using the project it is
 
27
  // first checked if this file is located in one of
 
28
  // source paths known to the project. If not, the file
 
29
  // is not written. This mechanism is necessary to 
 
30
  // avoid system headers to be overwritten (except for
 
31
  // the case that the corresponding system include 
 
32
  // path is added as a source path).
 
33
  project.addPath(".", ".");
 
34
  
 
35
  // Check the arguments, need an input file.
 
36
  if (argc != 2) {
 
37
    std::cout << "Usage: " << argv[0] << " FILE" << std::endl;
 
38
    return 1;
 
39
  }
 
40
 
 
41
  // Scan the input file. The result is a token list
 
42
  // representation of the input file.
 
43
  Puma::Unit* unit = project.scanFile(argv[1]);
 
44
  if (! unit) {
 
45
    std::cerr << "Aborted: Unable to scan input file" << std::endl;
 
46
    return 1;
 
47
  }
 
48
 
 
49
  // After the input file was successfully scanned, it is 
 
50
  // now tried to parse it. The result is the so-called 
 
51
  // translation unit encapsulating the preprocessor, 
 
52
  // syntax, and semantic trees.
 
53
  Puma::CCParser parser;
 
54
  Puma::CTranslationUnit* tu = parser.parse(*unit, project);
 
55
 
 
56
  if (tu->tree()) {
 
57
    // During the parsing of the input file only those 
 
58
    // semantic analyses are performed that are necessary
 
59
    // to build the correct syntax tree and to recognize
 
60
    // the correct types. Expression evaluation and so on
 
61
    // is performed in an additional sematic analysis. It
 
62
    // is optional and not needed for this application.
 
63
    //Puma::CCSemVisitor semantics(err);
 
64
    //semantics.run(tu->tree());
 
65
 
 
66
    // The generated syntax tree is an attributed syntax
 
67
    // tree referring to both tokens and semantic information.
 
68
    // It can be traversed using a corresponding tree visitor.
 
69
    // Formatted printing of the tree is performed by the 
 
70
    // CPrintVisitor tree visitor.
 
71
    //CPrintVisitor cprinter;
 
72
    //cprinter.print(tu->tree(), std::cout);
 
73
 
 
74
    // The collected semantic information also is organized 
 
75
    // as a tree reflecting the scope structure of the parsed 
 
76
    // code. The interface to the semantic tree is the class 
 
77
    // CClassDatabase. It can also be used to print this tree.
 
78
    //tu->db().Dump(std::cout, 10);
 
79
    
 
80
    // Now transform the "if" statements so that a comment
 
81
    // exists before every "if" statement.
 
82
    Transformer transformer(err);
 
83
    transformer.transform(tu->tree());
 
84
    
 
85
    // At last the transformed unit has to be saved as file
 
86
    // again. This is also realized using the project class.
 
87
    // The original file shall be renamed to filename.bak
 
88
    // before the transformed version of this file is written.
 
89
    project.saveMode(Puma::SaveMode::RENAME_OLD, ".bak");
 
90
    project.save(unit);
 
91
  }
 
92
  if (tu->cpp_tree()) {
 
93
    // Beside the syntax and semantic trees there is also 
 
94
    // a separate tree for the preprocessor directives.
 
95
    // This tree can be printed using the PrePrintVisitor.
 
96
    //Puma::PrePrintVisitor preprinter;
 
97
    //tu->cpp_tree()->accept(preprinter);
 
98
  }
 
99
  
 
100
  // Clean up.
 
101
  delete tu;
 
102
 
 
103
  // Return 1 if errors or fatal errors occurred.
 
104
  return err.severity() > Puma::sev_warning ? 1 : 0;
 
105
}