Changes in / [c2b3243:ce7d197]
- Location:
- src
- Files:
-
- 20 edited
-
AST/Convert.cpp (modified) (5 diffs)
-
AST/Decl.hpp (modified) (2 diffs)
-
AST/Expr.hpp (modified) (1 diff)
-
AST/Pass.impl.hpp (modified) (1 diff)
-
CodeGen/CodeGenerator.cc (modified) (1 diff)
-
CodeGen/CodeGenerator.h (modified) (1 diff)
-
Common/PassVisitor.impl.h (modified) (3 diffs)
-
Parser/DeclarationNode.cc (modified) (1 diff)
-
Parser/ExpressionNode.cc (modified) (1 diff)
-
Parser/ParseNode.h (modified) (2 diffs)
-
Parser/TypeData.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (1 diff)
-
ResolvExpr/CandidateFinder.cpp (modified) (1 diff)
-
SymTab/Mangler.cc (modified) (4 diffs)
-
SymTab/Validate.cc (modified) (1 diff)
-
SymTab/ValidateType.cc (modified) (1 diff)
-
SynTree/Declaration.h (modified) (1 diff)
-
SynTree/Expression.h (modified) (1 diff)
-
Validate/FixQualifiedTypes.cpp (modified) (1 diff)
-
Validate/LinkReferenceToTypes.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rc2b3243 rce7d197 310 310 node->name, 311 311 get<Attribute>().acceptL( node->attributes ), 312 node->isTyped,312 false, // Temporary 313 313 LinkageSpec::Spec( node->linkage.val ), 314 314 get<Type>().accept1(node->base) 315 315 ); 316 return aggregatePostamble( decl, node ); 316 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble 317 317 } 318 318 … … 737 737 node->name 738 738 ); 739 temp->var = get<DeclarationWithType>().accept1(node->var); 739 740 auto expr = visitBaseExpr( node, 740 741 temp … … 1614 1615 { old->get_funcSpec().val } 1615 1616 ); 1616 decl->enumInLine = old->enumInLine;1617 1617 cache.emplace(old, decl); 1618 1618 assert(cache.find( old ) != cache.end()); … … 2281 2281 } 2282 2282 2283 /// xxx - type_decl should be DeclWithType in the final design 2284 /// type_decl is set to EnumDecl as a temporary fix 2283 2285 virtual void visit( const QualifiedNameExpr * old ) override final { 2284 2286 this->node = visitBaseExpr( old, … … 2286 2288 old->location, 2287 2289 GET_ACCEPT_1(type_decl, Decl), 2290 GET_ACCEPT_1(var, DeclWithType), 2288 2291 old->name 2289 2292 ) -
src/AST/Decl.hpp
rc2b3243 rce7d197 105 105 ptr<Init> init; 106 106 ptr<Expr> bitfieldWidth; 107 bool enumInLine = false; // A flag vairable to tell the compile:108 // this is not a real object declaration. It is a place holder for109 // a set of enum value (ObjectDecl).110 107 111 108 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, … … 315 312 class EnumDecl final : public AggregateDecl { 316 313 public: 317 bool isTyped; // isTyped indicated if the enum has a declaration like: 318 // enum (type_optional) Name {...} 319 ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum 314 bool isTyped; 315 ptr<Type> base; 320 316 321 317 EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false, -
src/AST/Expr.hpp
rc2b3243 rce7d197 257 257 public: 258 258 ptr<Decl> type_decl; 259 ptr<DeclWithType> var; 259 260 std::string name; 260 261 261 QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const std::string & n )262 : Expr( loc ), type_decl( d ), name( n ) {}262 QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const DeclWithType * r, const std::string & n ) 263 : Expr( loc ), type_decl( d ), var(r), name( n ) {} 263 264 264 265 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Pass.impl.hpp
rc2b3243 rce7d197 1205 1205 if ( __visit_children() ) { 1206 1206 guard_symtab guard { *this }; 1207 maybe_accept( node, &QualifiedNameExpr::var ); 1207 1208 maybe_accept( node, &QualifiedNameExpr::type_decl ); 1208 1209 } -
src/CodeGen/CodeGenerator.cc
rc2b3243 rce7d197 912 912 } 913 913 output << ")"; 914 } 915 916 // QualifiedNameExpr should not reach to CodeGen. 917 // FixQualifiedName Convert QualifiedNameExpr to VariableExpr 918 void CodeGenerator::postvisit( QualifiedNameExpr * expr ) { 919 output << "/* label */" << mangleName(expr->var); 914 920 } 915 921 -
src/CodeGen/CodeGenerator.h
rc2b3243 rce7d197 103 103 void postvisit( DefaultArgExpr * ); 104 104 void postvisit( GenericExpr * ); 105 void postvisit( QualifiedNameExpr *); 105 106 106 107 //*** Statements -
src/Common/PassVisitor.impl.h
rc2b3243 rce7d197 1934 1934 indexerScopedAccept( node->result, *this ); 1935 1935 maybeAccept_impl( node->type_decl, *this ); 1936 maybeAccept_impl( node->var, *this ); 1936 1937 1937 1938 VISIT_END( node ); … … 1944 1945 indexerScopedAccept( node->result, *this ); 1945 1946 maybeAccept_impl( node->type_decl, *this ); 1947 maybeAccept_impl( node->var, *this ); 1946 1948 1947 1949 VISIT_END( node ); … … 1955 1957 indexerScopedMutate( node->result, *this ); 1956 1958 maybeMutate_impl( node->type_decl, *this ); 1959 maybeAccept_impl( node->var, *this ); 1957 1960 1958 1961 MUTATE_END( Expression, node ); -
src/Parser/DeclarationNode.cc
rc2b3243 rce7d197 297 297 } // if 298 298 } // DeclarationNode::newEnumValueGeneric 299 300 DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {301 DeclarationNode * newnode = newName( new std::string(name) );302 newnode->enumInLine = true;303 return newnode;304 }305 299 306 300 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) { -
src/Parser/ExpressionNode.cc
rc2b3243 rce7d197 523 523 auto enumInst = new EnumInstType( Type::Qualifiers(), e ); 524 524 auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr ); 525 ret->set_var( obj ); 525 526 } 526 527 return ret; -
src/Parser/ParseNode.h
rc2b3243 rce7d197 240 240 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 241 241 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); 242 static DeclarationNode * newEnumInLine( const std::string name );243 242 static DeclarationNode * newName( const std::string * ); 244 243 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params ); … … 340 339 341 340 bool inLine = false; 342 bool enumInLine = false;343 341 Type::FuncSpecifiers funcSpecs; 344 342 Type::StorageClasses storageClasses; -
src/Parser/TypeData.cc
rc2b3243 rce7d197 924 924 list< Declaration * >::iterator members = ret->get_members().begin(); 925 925 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 926 if ( cur->enumInLine ) {927 // Tell the compiler this is a inline value placeholder928 ObjectDecl * member = dynamic_cast< ObjectDecl* >(* members);929 member->enumInLine = true;930 }931 926 if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) { 932 927 SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." ); -
src/Parser/parser.yy
rc2b3243 rce7d197 2605 2605 { $$ = DeclarationNode::newEnumValueGeneric( $1, $2 ); } 2606 2606 | INLINE type_name 2607 { $$ = DeclarationNode::newEnum InLine( *$2->type->symbolic.name); }2607 { $$ = DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ); } 2608 2608 | enumerator_list ',' identifier_or_type_name enumerator_value_opt 2609 2609 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $3, $4 ) ); } -
src/ResolvExpr/CandidateFinder.cpp
rc2b3243 rce7d197 862 862 } 863 863 } 864 } 865 866 void postvisit( const ast::QualifiedNameExpr * qualifiedNameExpr ) { 867 auto mangleName = Mangle::mangle(qualifiedNameExpr->var); 868 addCandidate( qualifiedNameExpr, tenv ); 864 869 } 865 870 -
src/SymTab/Mangler.cc
rc2b3243 rce7d197 65 65 void postvisit( const QualifiedType * qualType ); 66 66 67 void postvisit( const QualifiedNameExpr * qualNameExpr ); 68 67 69 std::string get_mangleName() { return mangleName; } 68 70 private: … … 305 307 mangleName += Encoding::qualifiedTypeEnd; 306 308 } 309 } 310 311 void Mangler_old::postvisit( const QualifiedNameExpr * qual ) { 312 maybeAccept( qual->var, *visitor ); 307 313 } 308 314 … … 417 423 void postvisit( const ast::OneType * oneType ); 418 424 void postvisit( const ast::QualifiedType * qualType ); 425 void postvisit( const ast::QualifiedNameExpr * qualNameExpr ); 419 426 420 427 std::string get_mangleName() { return mangleName; } … … 645 652 mangleName += Encoding::qualifiedTypeEnd; 646 653 } 654 } 655 void Mangler_new::postvisit( const ast::QualifiedNameExpr * qual ) { 656 maybeAccept( qual->var.get(), *visitor ); 647 657 } 648 658 -
src/SymTab/Validate.cc
rc2b3243 rce7d197 858 858 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); 859 859 } else if ( EnumInstType * enumInst = dynamic_cast< EnumInstType * >( designatorType ) ) { 860 // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 860 861 if ( enumInst->baseEnum ) { 861 862 const EnumDecl * enumDecl = enumInst->baseEnum; -
src/SymTab/ValidateType.cc
rc2b3243 rce7d197 81 81 void previsit( QualifiedType * qualType ); 82 82 void postvisit( QualifiedType * qualType ); 83 83 84 void postvisit( QualifiedNameExpr * qualExpr ); 84 85 85 86 void postvisit( EnumDecl * enumDecl ); 86 87 void postvisit( StructDecl * structDecl ); -
src/SynTree/Declaration.h
rc2b3243 rce7d197 121 121 Initializer * init; 122 122 Expression * bitfieldWidth; 123 bool enumInLine = false;124 123 125 124 ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init, -
src/SynTree/Expression.h
rc2b3243 rce7d197 168 168 Declaration * type_decl; 169 169 std::string name; 170 DeclarationWithType * var; 170 171 171 172 QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {} 172 QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name) {} 173 QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name), var(other.var) {} 174 DeclarationWithType * get_var() const { return var; } 175 void set_var( DeclarationWithType * newValue ) { var = newValue; } 173 176 174 177 virtual ~QualifiedNameExpr() { 178 delete var; 175 179 delete type_decl; 176 180 } -
src/Validate/FixQualifiedTypes.cpp
rc2b3243 rce7d197 102 102 } 103 103 104 auto var = new ast::ObjectDecl( t->location, t->name, 105 new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall ); 104 105 auto var = new ast::ObjectDecl( t->var->location, t->name, 106 new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall ); 107 var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue 106 108 var->mangleName = Mangle::mangle( var ); 107 109 return new ast::VariableExpr( t->location, var ); 110 // return ret; 108 111 } 109 112 -
src/Validate/LinkReferenceToTypes.cpp
rc2b3243 rce7d197 44 44 void postvisit( ast::UnionDecl const * decl ); 45 45 ast::TraitDecl const * postvisit( ast::TraitDecl const * decl ); 46 ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl); 46 47 47 48 private: … … 202 203 } 203 204 204 // The following section205 auto mut = ast::mutate( decl );206 std::vector<ast::ptr<ast::Decl>> buffer;207 for ( auto it = decl->members.begin(); it != decl->members.end(); ++it) {208 auto member = (*it).as<ast::ObjectDecl>();209 if ( member->enumInLine ) {210 auto targetEnum = symtab.lookupEnum( member->name );211 if (targetEnum) {212 for (auto singleMamber : targetEnum->members) {213 auto tm = singleMamber.as<ast::ObjectDecl>();214 auto t = new ast::ObjectDecl(215 member->location, // use the "inline" location216 tm->name,217 new ast::EnumInstType( decl, ast::CV::Const ),218 // Construct a new EnumInstType as the type219 tm->init,220 tm->storage,221 tm->linkage,222 tm->bitfieldWidth,223 {}, // enum member doesn't have attribute224 tm->funcSpec225 );226 buffer.push_back(t);227 }228 }229 } else {230 buffer.push_back( *it );231 }232 }233 mut->members = buffer;234 decl = mut;235 236 205 ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name ); 237 206 if ( fwds != forwardEnums.end() ) { … … 315 284 } 316 285 286 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) { 287 // Try to lookup type 288 if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) { 289 if ( auto inst = objDecl->type.as<ast::TypeInstType>()) { 290 if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) { 291 auto mut = ast::mutate( decl ); 292 mut->type_decl = enumDecl; 293 auto enumInst = new ast::EnumInstType( enumDecl ); 294 enumInst->name = decl->name; 295 // Adding result; addCandidate() use result 296 mut->result = enumInst; 297 decl = mut; 298 } 299 } 300 } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) { 301 auto mut = ast::mutate( decl ); 302 auto enumInst = new ast::EnumInstType( enumDecl ); 303 enumInst->name = decl->name; 304 // Adding result; addCandidate() use result 305 mut->result = enumInst; 306 decl = mut; 307 } 308 // ast::EnumDecl const * decl = symtab.lookupEnum( type->name ); 309 // // It's not a semantic error if the enum is not found, just an implicit forward declaration. 310 // if ( decl ) { 311 // // Just linking in the node. 312 // auto mut = ast::mutate( type ); 313 // mut->base = const_cast<ast::EnumDecl *>( decl ); 314 // type = mut; 315 // } 316 return decl; 317 } 318 317 319 } // namespace 318 320
Note:
See TracChangeset
for help on using the changeset viewer.