source: src/CodeTools/TrackLoc.cc @ 3b3491b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 3b3491b was a16764a6, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Changed warning system to prepare for toggling warnings

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[dba6db9]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// TrackLoc.cc --
8//
9// Author           : Andrew Beach
10// Created On       : Tues May 2 15:46:00 2017
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed May 3 14:43:00 2017
13// Update Count     : 0
14//
15
16#include "TrackLoc.h"
17
[3268a58]18#include <cstdlib>                   // for exit, EXIT_FAILURE
19#include <iostream>                  // for operator<<, ostream, basic_ostream
[08fc48f]20#include <iterator>                  // for back_inserter, inserter
[3268a58]21#include <stack>                     // for stack
22#include <string>                    // for operator<<, string
23#include <typeindex>                 // for type_index
24
25#include "Common/PassVisitor.h"      // for PassVisitor
26#include "Common/utility.h"          // for CodeLocation
27#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
[08fc48f]28#include "SynTree/Mutator.h"         // for mutateAll
29#include "SynTree/Visitor.h"         // for acceptAll
[bf2438c]30
31class Declaration;
[dba6db9]32
33namespace CodeTools {
[13932f14]34        class LocationPrinter {
35                size_t printLevel;
[dba6db9]36
37                CodeLocation *lastNode;
38
[13932f14]39                std::stack< CodeLocation * > parents;
40        public:
[3268a58]41                LocationPrinter(size_t printLevel) :
[13932f14]42                        printLevel(printLevel), lastNode(nullptr)
43                {}
[dba6db9]44
[13932f14]45                void print( const std::string& name, BaseSyntaxNode *node) {
46                        for (size_t i = 0 ; i < parents.size() ; ++i) {
[dba6db9]47                                std::cout << "    ";
48                        }
[13932f14]49                        if (2 <= printLevel) {
[dba6db9]50                                std::cout << name << '@';
51                        }
52                        std::cout << node->location << std::endl;
[13932f14]53                }
54
55                void atNode( BaseSyntaxNode *node ) {
56                        std::string name = std::type_index(typeid(*node)).name();
57                        if ( node->location.isUnset() ) {
58                                if ( !parents.empty() ) {
59                                        node->location = *parents.top();
[3268a58]60                                }
[13932f14]61                                else if (nullptr != lastNode) {
62                                        node->location = *lastNode;
[3268a58]63                                }
[13932f14]64                                else {
[014450e]65                                        assertf( false, "Top level node has no CodeLocation %s", toString( node ).c_str() );
[dba6db9]66                                }
67                        }
[13932f14]68
[dba6db9]69                        if (0 < printLevel) {
[13932f14]70                                print( name, node );
[dba6db9]71                        }
72                        lastNode = &node->location;
73                }
74
[13932f14]75                void previsit(BaseSyntaxNode * node) {
76                        atNode(node);
77                        parents.push( &node->location );
[dba6db9]78                }
79
[b3c36f4]80                void postvisit( __attribute__((unused)) BaseSyntaxNode * node ) {
[13932f14]81                        parents.pop();
82                }
[dba6db9]83
84        }; // LocationPrinter
85
[13932f14]86        void fillLocations( std::list< Declaration * > & translationUnit, size_t printLevel) {
87                PassVisitor<LocationPrinter> printer(printLevel);
[dba6db9]88                acceptAll( translationUnit, printer );
89        }
90} // namespace CodeTools
91
92// Local Variables: //
93// tab-width: 4 //
94// mode: c++ //
95// compile-command: "make install" //
96// End: //
Note: See TracBrowser for help on using the repository browser.