- Timestamp:
- Jun 10, 2024, 2:43:13 AM (19 months ago)
- Branches:
- master
- Children:
- 42cdd07d
- Parents:
- d68de59
- Location:
- src/AST
- Files:
-
- 7 edited
-
Decl.cpp (modified) (1 diff)
-
Decl.hpp (modified) (3 diffs)
-
Expr.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (1 diff)
-
SymbolTable.cpp (modified) (1 diff)
-
SymbolTable.hpp (modified) (1 diff)
-
Util.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
rd68de59 r85855b0 170 170 171 171 const std::string EnumDecl::getUnmangeldArrayName( const ast::EnumAttribute attr ) const { 172 switch( attr ) { 173 case ast::EnumAttribute::Value: return "values_" + name ; 174 case ast::EnumAttribute::Label: return "labels_" + name; 175 default: /* Posn does not generate array */ 176 return ""; 172 switch( attr ) { 173 case ast::EnumAttribute::Value: return "values_" + name ; 174 case ast::EnumAttribute::Label: return "labels_" + name; 175 default: /* Posn does not generate array */ 176 return ""; 177 } 178 } 179 180 unsigned EnumDecl::calChildOffset(const std::string & target) const{ 181 unsigned offset = 0; 182 for (auto childEnum: inlinedDecl) { 183 auto childDecl = childEnum->base; 184 if (childDecl->name == target) { 185 return offset; 177 186 } 178 } 187 offset += childDecl->members.size(); 188 } 189 std::cerr << "Cannot find the target enum" << std::endl; 190 return 0; 191 } 192 193 unsigned EnumDecl::calChildOffset(const ast::EnumInstType * target) const{ 194 return calChildOffset(target->base->name); 195 } 196 197 bool EnumDecl::isSubTypeOf(const ast::EnumDecl * other) const { 198 if (name == other->name) return true; 199 for (auto inlined: other->inlinedDecl) { 200 if (isSubTypeOf(inlined->base)) return true; 201 } 202 return false; 203 } 179 204 180 205 } -
src/AST/Decl.hpp
rd68de59 r85855b0 75 75 bool isDeleted = false; 76 76 bool isTypeFixed = false; 77 bool isHidden = false; 77 78 78 79 DeclWithType( const CodeLocation& loc, const std::string& name, Storage::Classes storage, … … 313 314 ptr<Type> base; 314 315 enum class EnumHiding { Visible, Hide } hide; 316 std::vector< ast::ptr<ast::EnumInstType>> inlinedDecl; // child enums 317 315 318 EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false, 316 319 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, … … 328 331 329 332 const std::string getUnmangeldArrayName( const EnumAttribute attr ) const; 333 334 unsigned calChildOffset(const std::string & childEnum) const; 335 unsigned calChildOffset(const ast::EnumInstType * childEnum) const; 336 337 bool isSubTypeOf(const ast::EnumDecl *) const; 330 338 private: 331 339 EnumDecl * clone() const override { return new EnumDecl{ *this }; } -
src/AST/Expr.hpp
rd68de59 r85855b0 256 256 public: 257 257 ptr<Decl> type_decl; 258 std::string name; 258 const std::string type_name; 259 const std::string name; 259 260 260 261 QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const std::string & n ) 261 : Expr( loc ), type_decl( d ), name( n ) {} 262 : Expr( loc ), type_decl( d ), type_name(""), name( n ) {} 263 264 QualifiedNameExpr( const CodeLocation & loc, const std::string & type_name, const std::string & name) 265 : Expr( loc ), type_name( type_name ), name( name ) {} 262 266 263 267 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Pass.impl.hpp
rd68de59 r85855b0 560 560 561 561 if ( __visit_children() ) { 562 if ( node->hide == ast::EnumDecl::EnumHiding::Hide ) { 563 guard_symtab guard { *this }; 564 maybe_accept( node, &EnumDecl::base ); 565 maybe_accept( node, &EnumDecl::params ); 566 maybe_accept( node, &EnumDecl::members ); 567 maybe_accept( node, &EnumDecl::attributes ); 568 } else { 569 maybe_accept( node, &EnumDecl::base ); 570 maybe_accept( node, &EnumDecl::params ); 571 maybe_accept( node, &EnumDecl::members ); 572 maybe_accept( node, &EnumDecl::attributes ); 573 } 562 maybe_accept( node, &EnumDecl::base ); 563 maybe_accept( node, &EnumDecl::params ); 564 maybe_accept( node, &EnumDecl::members ); 565 maybe_accept( node, &EnumDecl::attributes ); 566 maybe_accept( node, &EnumDecl::inlinedDecl ); 574 567 } 575 568 -
src/AST/SymbolTable.cpp
rd68de59 r85855b0 159 159 } 160 160 161 std::vector<SymbolTable::IdData> SymbolTable::lookupIdIgnoreHidden( const std::string &id ) const { 162 std::vector<IdData> out; 163 std::vector<IdData> lookupResult = lookupId(id); 164 for ( auto candidate: lookupResult) { 165 if ( candidate.id ) { 166 if (candidate.id->isHidden) continue; 167 } 168 out.push_back(candidate); 169 } 170 return out; 171 } 172 161 173 std::vector<SymbolTable::IdData> SymbolTable::specialLookupId( SymbolTable::SpecialFunctionKind kind, const std::string & otypeKey ) const { 162 174 static Stats::Counters::CounterGroup * special_stats = Stats::Counters::build<Stats::Counters::CounterGroup>("Special Lookups"); -
src/AST/SymbolTable.hpp
rd68de59 r85855b0 121 121 /// Gets all declarations with the given ID 122 122 std::vector<IdData> lookupId( const std::string &id ) const; 123 /// Gets all declarations with the given ID, ignoring hidden members from enumeration 124 std::vector<IdData> lookupIdIgnoreHidden( const std::string &id ) const; 123 125 /// Gets special functions associated with a type; if no key is given, returns everything 124 126 std::vector<IdData> specialLookupId( SpecialFunctionKind kind, const std::string & otypeKey = "" ) const; -
src/AST/Util.cpp
rd68de59 r85855b0 352 352 void previsit( EnumDecl const * decl ) { 353 353 enumDecls.insert( decl ); 354 if ( ast::EnumDecl::EnumHiding::Visible == decl->hide ) { 355 for ( auto & member : decl->members ) { 356 typedDecls.insert( member.strict_as<ast::DeclWithType>() ); 357 } 354 for ( auto & member : decl->members ) { 355 typedDecls.insert( member.strict_as<ast::DeclWithType>() ); 358 356 } 359 357 beginScope();
Note:
See TracChangeset
for help on using the changeset viewer.