@@ -307,7 +307,29 @@ struct Parser::GetDeclaratorType {
307307 }
308308 }
309309
310- void operator ()(PtrToMemberOperatorAST* ast) {}
310+ void operator ()(PtrToMemberOperatorAST* ast) {
311+ if (!type_) return ;
312+
313+ auto symbol = ast->nestedNameSpecifier ->symbol ;
314+ if (!symbol) return ;
315+
316+ auto classType = type_cast<ClassType>(symbol->type ());
317+ if (!classType) return ;
318+
319+ if (auto functionType = type_cast<FunctionType>(type_)) {
320+ type_ = control ()->getMemberFunctionPointerType (classType, functionType);
321+ } else {
322+ type_ = control ()->getMemberObjectPointerType (classType, type_);
323+ }
324+
325+ for (auto it = ast->cvQualifierList ; it; it = it->next ) {
326+ if (ast_cast<ConstQualifierAST>(it->value )) {
327+ type_ = control ()->getConstType (type_);
328+ } else if (ast_cast<VolatileQualifierAST>(it->value )) {
329+ type_ = control ()->getVolatileType (type_);
330+ }
331+ }
332+ }
311333
312334 void operator ()(BitfieldDeclaratorAST* ast) {}
313335
@@ -2932,6 +2954,55 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast,
29322954 break ;
29332955 }
29342956
2957+ case TokenKind::T_AMP: {
2958+ if (!ast->expression ->type ) {
2959+ break ;
2960+ }
2961+
2962+ if (!is_glvalue (ast->expression )) {
2963+ break ;
2964+ }
2965+
2966+ // TODO xvalue to lvalue
2967+
2968+ auto expr = strip_parentheses (ast->expression );
2969+
2970+ if (auto idExpr = ast_cast<IdExpressionAST>(expr);
2971+ idExpr && idExpr->nestedNameSpecifier ) {
2972+ auto symbol = idExpr->symbol ;
2973+ if (auto field = symbol_cast<FieldSymbol>(symbol);
2974+ field && !field->isStatic ()) {
2975+ auto parentClass = field->enclosingSymbol ();
2976+ auto classType = type_cast<ClassType>(parentClass->type ());
2977+
2978+ ast->type =
2979+ control_->getMemberObjectPointerType (classType, field->type ());
2980+
2981+ ast->valueCategory = ValueCategory::kPrValue ;
2982+
2983+ break ;
2984+ }
2985+
2986+ if (auto function = symbol_cast<FunctionSymbol>(symbol);
2987+ function && !function->isStatic ()) {
2988+ auto functionType = type_cast<FunctionType>(function->type ());
2989+ auto parentClass = function->enclosingSymbol ();
2990+ auto classType = type_cast<ClassType>(parentClass->type ());
2991+
2992+ ast->type =
2993+ control_->getMemberFunctionPointerType (classType, functionType);
2994+
2995+ ast->valueCategory = ValueCategory::kPrValue ;
2996+
2997+ break ;
2998+ }
2999+ } // id expression
3000+
3001+ ast->type = control_->getPointerType (ast->expression ->type );
3002+ ast->valueCategory = ValueCategory::kPrValue ;
3003+ break ;
3004+ }
3005+
29353006 case TokenKind::T_PLUS: {
29363007 ExpressionAST* expr = ast->expression ;
29373008 ensure_prvalue (expr);
@@ -5985,6 +6056,13 @@ void Parser::check_type_traits() {
59856056 rewind (typeTraitLoc);
59866057}
59876058
6059+ auto Parser::strip_parentheses (ExpressionAST* ast) -> ExpressionAST* {
6060+ while (auto paren = ast_cast<NestedExpressionAST>(ast)) {
6061+ ast = paren->expression ;
6062+ }
6063+ return ast;
6064+ }
6065+
59886066auto Parser::lvalue_to_rvalue_conversion (ExpressionAST*& expr) -> bool {
59896067 if (!is_glvalue (expr)) return false ;
59906068
0 commit comments