Inferno
0.2
|
00001 00002 #ifndef UNIQUIFY_IDENTIFIERS_HPP 00003 #define UNIQUIFY_IDENTIFIERS_HPP 00004 00005 #include <map> 00006 #include <vector> 00007 #include "tree/cpptree.hpp" 00008 00009 // Check identifiers for duplication 00010 // Policy is to dedupe with a simple scheme like <name>_<unique number> or even without the underscore 00011 // This or any scheme could clash with existing names. BUT if we bring existing names that happen to be 00012 // the same form into our scheme, as it we created them, then uniqueness is guaranteed (but we will sometimes 00013 // want to change the number, so what started as foo_2 could become foo_3 by the time we're done with it). 00014 00015 typedef set< unsigned > NameUsage; 00016 00017 struct UniquifyIdentifiers; 00018 00019 struct VisibleIdentifiers 00020 { 00021 // Mao of basenames to their offset number tables 00022 typedef pair<const string, NameUsage> NameUsagePair; 00023 map< string, NameUsage > name_usages; 00024 00025 string AddIdentifierNumber( NameUsage &nu, TreePtr<CPPTree::SpecificIdentifier> i, string b, unsigned n ); 00026 string AddIdentifier( TreePtr<CPPTree::SpecificIdentifier> i ); 00027 00028 static string MakeUniqueName( string b, unsigned n ); 00029 static void SplitName( TreePtr<CPPTree::SpecificIdentifier> i, string *b, unsigned *n ); // note static 00030 }; 00031 00032 struct UniquifyIdentifiers : public map< TreePtr<CPPTree::SpecificIdentifier>, string > 00033 { 00034 typedef pair<const TreePtr<CPPTree::SpecificIdentifier>, string> IdentifierNamePair; 00035 void UniquifyScope( TreePtr<Node> root, VisibleIdentifiers v = VisibleIdentifiers() ); // Not a ref because we want a copy so we can go back TODO optimise 00036 }; 00037 00038 00039 #endif