private IASTParameterDeclaration getParameterDeclaration( INodeFactory nodeFactory, String paramName) { IASTDeclarator sourceDeclarator = getDeclarator(); IASTDeclSpecifier declSpec = safeCopy(getDeclSpecifier()); IASTDeclarator declarator = createDeclarator(nodeFactory, sourceDeclarator, paramName); Indirection indirection = getIndirection(); if (indirection == Indirection.POINTER) { declarator.addPointerOperator(nodeFactory.newPointer()); } else if (indirection == Indirection.REFERENCE) { declarator.addPointerOperator(((ICPPNodeFactory) nodeFactory).newReferenceOperator(false)); } if (indirection != Indirection.NONE && !isWriteAccess && declSpec != null) { declSpec.setConst(true); } declarator.setNestedDeclarator(sourceDeclarator.getNestedDeclarator()); return nodeFactory.newParameterDeclaration(declSpec, declarator); }
private IASTDeclarator createDeclarator( INodeFactory nodeFactory, IASTDeclarator sourceDeclarator, String name) { IASTName astName = name != null ? nodeFactory.newName(name.toCharArray()) : nodeFactory.newName(); IASTDeclarator declarator; if (sourceDeclarator instanceof IASTArrayDeclarator) { IASTArrayDeclarator arrDeclarator = (IASTArrayDeclarator) sourceDeclarator; IASTArrayDeclarator arrayDeclarator = nodeFactory.newArrayDeclarator(astName); IASTArrayModifier[] arrayModifiers = arrDeclarator.getArrayModifiers(); for (IASTArrayModifier arrayModifier : arrayModifiers) { arrayDeclarator.addArrayModifier(arrayModifier.copy(CopyStyle.withLocations)); } declarator = arrayDeclarator; } else { declarator = nodeFactory.newDeclarator(astName); } for (IASTPointerOperator pointerOp : sourceDeclarator.getPointerOperators()) { declarator.addPointerOperator(pointerOp.copy(CopyStyle.withLocations)); } return declarator; }