private IType getReturnType() { ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); if (lambdaDtor != null) { IASTTypeId trailingReturnType = lambdaDtor.getTrailingReturnType(); if (trailingReturnType != null) { return CPPVisitor.createType(trailingReturnType); } } IASTCompoundStatement body = fLambdaExpression.getBody(); if (body != null) { IASTStatement[] stmts = body.getStatements(); if (stmts.length > 0) { // Gnu extension allows to deduce return type in complex compound statements IASTStatement stmt = stmts[stmts.length - 1]; if (stmt instanceof IASTReturnStatement) { IASTReturnStatement rtstmt = (IASTReturnStatement) stmt; IASTExpression expr = rtstmt.getReturnValue(); if (expr != null) { IType type = expr.getExpressionType(); type = Conversions.lvalue_to_rvalue(type, false); if (type != null) { return type; } } } } } return CPPSemantics.VOID_TYPE; }
private IType[] getParameterTypes() { ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); if (lambdaDtor != null) { return CPPVisitor.createParameterTypes(lambdaDtor); } return IType.EMPTY_TYPE_ARRAY; }
private ICPPMethod[] createMethods() { boolean needConversionOperator = fLambdaExpression.getCaptureDefault() == CaptureDefault.UNSPECIFIED && fLambdaExpression.getCaptures().length == 0; final ICPPClassScope scope = getCompositeScope(); ICPPMethod[] result = new ICPPMethod[needConversionOperator ? 6 : 5]; // Deleted default constructor: A() CPPImplicitConstructor ctor = new CPPImplicitConstructor( scope, CharArrayUtils.EMPTY, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY); ctor.setDeleted(true); result[0] = ctor; // Copy constructor: A(const A &) IType pType = new CPPReferenceType(SemanticUtil.constQualify(this), false); ICPPParameter[] ps = new ICPPParameter[] {new CPPParameter(pType, 0)}; ctor = new CPPImplicitConstructor(scope, CharArrayUtils.EMPTY, ps); result[1] = ctor; // Deleted copy assignment operator: A& operator = (const A &) IType refType = new CPPReferenceType(this, false); ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, ps, false, false); ICPPMethod m = new CPPImplicitMethod(scope, OverloadableOperator.ASSIGN.toCharArray(), ft, ps); result[2] = m; // Destructor: ~A() ft = CPPVisitor.createImplicitFunctionType( NO_RETURN_TYPE, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false, false); m = new CPPImplicitMethod(scope, new char[] {'~'}, ft, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY); result[3] = m; // Function call operator final IType returnType = getReturnType(); final IType[] parameterTypes = getParameterTypes(); ft = new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false); ICPPParameter[] params = new ICPPParameter[parameterTypes.length]; for (int i = 0; i < params.length; i++) { params[i] = new CPPParameter(parameterTypes[i], i); } m = new CPPImplicitMethod(scope, OverloadableOperator.PAREN.toCharArray(), ft, params) { @Override public boolean isImplicit() { return false; } }; result[4] = m; // Conversion operator if (needConversionOperator) { final CPPFunctionType conversionTarget = new CPPFunctionType(returnType, parameterTypes); ft = new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false); m = new CPPImplicitMethod( scope, CPPASTConversionName.createName(conversionTarget, null), ft, params); result[5] = m; } return result; }
private boolean isMutable() { ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator(); return lambdaDtor != null && lambdaDtor.isMutable(); }