Changeset 3f12158
- Timestamp:
- Jul 7, 2017, 11:55:37 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7c03d6d
- Parents:
- f32e53e (diff), 54d714e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/LinkageSpec.cc
rf32e53e r3f12158 10 10 // Created On : Sat May 16 13:22:09 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 11:51:00 201713 // Update Count : 2 412 // Last Modified On : Fri Jul 7 11:11:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 22 22 #include "Common/SemanticError.h" 23 23 24 LinkageSpec::Spec LinkageSpec::linkageCheck( const string * spec ) { 24 namespace LinkageSpec { 25 26 Spec linkageCheck( const string * spec ) { 27 assert( spec ); 25 28 unique_ptr<const string> guard( spec ); // allocated by lexer 26 29 if ( *spec == "\"Cforall\"" ) { … … 35 38 } 36 39 37 string LinkageSpec::linkageName( LinkageSpec::Spec linkage ) { 38 assert( 0 <= linkage && linkage < LinkageSpec::NoOfSpecs ); 39 static const char *linkageKinds[LinkageSpec::NoOfSpecs] = { 40 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", "cfa built-in", "c built-in", 41 }; 42 return linkageKinds[linkage]; 40 Spec linkageUpdate( Spec old_spec, const string * cmd ) { 41 assert( cmd ); 42 unique_ptr<const string> guard( cmd ); // allocated by lexer 43 if ( *cmd == "\"Cforall\"" ) { 44 old_spec.is_mangled = true; 45 return old_spec; 46 } else if ( *cmd == "\"C\"" ) { 47 old_spec.is_mangled = false; 48 return old_spec; 49 } else { 50 throw SemanticError( "Invalid linkage specifier " + *cmd ); 51 } // if 43 52 } 44 53 45 bool LinkageSpec::isMangled( Spec spec ) { 46 assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs ); 47 static bool decoratable[LinkageSpec::NoOfSpecs] = { 48 // Intrinsic, Cforall, C, AutoGen, Compiler, 49 true, true, false, true, false, 50 // Builtin, BuiltinC, 51 true, false, 52 }; 53 return decoratable[spec]; 54 std::string linkageName( Spec linkage ) { 55 switch ( linkage ) { 56 case Intrinsic: 57 return "intrinsic"; 58 case C: 59 return "C"; 60 case Cforall: 61 return "Cforall"; 62 case AutoGen: 63 return "autogenerated cfa"; 64 case Compiler: 65 return "compiler built-in"; 66 case BuiltinCFA: 67 return "cfa built-in"; 68 case BuiltinC: 69 return "c built-in"; 70 default: 71 return "<unnamed linkage spec>"; 72 } 54 73 } 55 74 56 bool LinkageSpec::isGeneratable( Spec spec ) { 57 assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs ); 58 static bool generatable[LinkageSpec::NoOfSpecs] = { 59 // Intrinsic, Cforall, C, AutoGen, Compiler, 60 true, true, true, true, false, 61 // Builtin, BuiltinC, 62 true, true, 63 }; 64 return generatable[spec]; 65 } 66 67 bool LinkageSpec::isOverridable( Spec spec ) { 68 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 69 static bool overridable[LinkageSpec::NoOfSpecs] = { 70 // Intrinsic, Cforall, C, AutoGen, Compiler, 71 true, false, false, true, false, 72 // Builtin, BuiltinC, 73 false, false, 74 }; 75 return overridable[spec]; 76 } 77 78 bool LinkageSpec::isBuiltin( Spec spec ) { 79 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 80 static bool builtin[LinkageSpec::NoOfSpecs] = { 81 // Intrinsic, Cforall, C, AutoGen, Compiler, 82 true, false, false, false, true, 83 // Builtin, BuiltinC, 84 true, true, 85 }; 86 return builtin[spec]; 87 } 75 } // LinkageSpec 88 76 89 77 // Local Variables: // -
src/Parser/LinkageSpec.h
rf32e53e r3f12158 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // LinkageSpec.h -- 7 // LinkageSpec.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:24:28 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 11:50:00 201713 // Update Count : 1 212 // Last Modified On : Fri Jul 7 11:03:00 2017 13 // Update Count : 13 14 14 // 15 15 … … 19 19 #include <string> 20 20 21 struct LinkageSpec { 22 enum Spec { 23 Intrinsic, // C built-in defined in prelude 24 Cforall, // ordinary 25 C, // not overloadable, not mangled 26 AutoGen, // built by translator (struct assignment) 27 Compiler, // gcc internal 28 Builtin, // mangled builtins 29 BuiltinC, // non-mangled builtins 30 NoOfSpecs 21 namespace LinkageSpec { 22 // All linkage specs are some combination of these flags: 23 enum { 24 Mangle = 1 << 0, 25 Generate = 1 << 1, 26 Overrideable = 1 << 2, 27 Builtin = 1 << 3, 28 29 NoOfSpecs = 1 << 4, 31 30 }; 32 33 static Spec linkageCheck( const std::string * ); 34 static std::string linkageName( Spec ); 35 36 static bool isMangled( Spec ); 37 static bool isGeneratable( Spec ); 38 static bool isOverridable( Spec ); 39 static bool isBuiltin( Spec ); 31 32 union Spec { 33 unsigned int val; 34 struct { 35 bool is_mangled : 1; 36 bool is_generatable : 1; 37 bool is_overridable : 1; 38 bool is_builtin : 1; 39 }; 40 constexpr Spec( unsigned int val ) : val( val ) {} 41 constexpr Spec( Spec const &other ) : val( other.val ) {} 42 // Operators may go here. 43 // Supports == and != 44 constexpr operator unsigned int () const { return val; } 45 }; 46 47 48 Spec linkageCheck( const std::string * ); 49 // Returns the Spec with the given name (limited to C, Cforall & BuiltinC) 50 Spec linkageUpdate( Spec old_spec, const std::string * cmd ); 51 /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false 52 * If cmd = "Cforall" returns old_spec Spec with is_mangled = true 53 */ 54 55 std::string linkageName( Spec ); 56 57 // To Update: LinkageSpec::isXyz( cur_spec ) -> cur_spec.is_xyz 58 inline bool isMangled( Spec spec ) { return spec.is_mangled; } 59 inline bool isGeneratable( Spec spec ) { return spec.is_generatable; } 60 inline bool isOverridable( Spec spec ) { return spec.is_overridable; } 61 inline bool isBuiltin( Spec spec ) { return spec.is_builtin; } 62 63 // Pre-defined flag combinations: 64 // C built-in defined in prelude 65 constexpr Spec const Intrinsic = { Mangle | Generate | Overrideable | Builtin }; 66 // ordinary 67 constexpr Spec const Cforall = { Mangle | Generate }; 68 // not overloadable, not mangled 69 constexpr Spec const C = { Generate }; 70 // built by translator (struct assignment) 71 constexpr Spec const AutoGen = { Mangle | Generate | Overrideable }; 72 // gcc internal 73 constexpr Spec const Compiler = { Builtin }; 74 // mangled builtins 75 constexpr Spec const BuiltinCFA = { Mangle | Generate | Builtin }; 76 // non-mangled builtins 77 constexpr Spec const BuiltinC = { Generate | Builtin }; 40 78 }; 41 79 -
src/main.cc
rf32e53e r3f12158 10 10 // Author : Richard C. Bilson 11 11 // Created On : Fri May 15 23:12:02 2015 12 // Last Modified By : Peter A. Buhr13 // Last Modified On : Thu Jun 29 12:46:50 201714 // Update Count : 44 112 // Last Modified By : Andrew Beach 13 // Last Modified On : Fri Jul 7 11:13:00 2017 14 // Update Count : 442 15 15 // 16 16 … … 206 206 FILE * builtins = fopen( libcfap | treep ? "../prelude/builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" ); 207 207 assertf( builtins, "cannot open builtins.cf\n" ); 208 parse( builtins, LinkageSpec::Builtin );208 parse( builtins, LinkageSpec::BuiltinCFA ); 209 209 } // if 210 210 } // if
Note: See TracChangeset
for help on using the changeset viewer.