use of org.eclipse.cdt.core.dom.ast.IASTTypeId in project Cpp4CIA by thanhminhmr.
the class AstBuilder method createFromTemplateParameter.
private void createFromTemplateParameter(@Nonnull CppNode parentNode, @Nonnull ICPPASTTemplateParameter templateParameter) {
if (templateParameter instanceof ICPPASTParameterDeclaration) {
// region Template Variable
final ICPPASTParameterDeclaration parameterDeclaration = (ICPPASTParameterDeclaration) templateParameter;
final CppNode parameterType = createFromDeclSpecifier(parentNode, parameterDeclaration.getDeclSpecifier());
createFromDeclarator(parentNode, parameterType, parameterDeclaration.getDeclarator(), false);
// endregion
} else if (templateParameter instanceof ICPPASTSimpleTypeTemplateParameter) {
// region Template Typename
final ICPPASTSimpleTypeTemplateParameter simpleParameter = (ICPPASTSimpleTypeTemplateParameter) templateParameter;
final IASTName simpleName = simpleParameter.getName();
final IBinding simpleBinding = simpleName.resolveBinding();
final CppNode typedefNode = createNode(simpleBinding, simpleName, null, new TypedefNode(), parentNode);
if (typedefNode instanceof TypedefNode) {
final IASTTypeId defaultType = simpleParameter.getDefaultType();
if (defaultType != null) {
final IASTDeclSpecifier elementSpecifier = defaultType.getDeclSpecifier();
final IASTDeclarator elementDeclarator = defaultType.getAbstractDeclarator();
final CppNode elementType = elementSpecifier != null ? createFromDeclSpecifier(typedefNode, elementSpecifier) : null;
final CppNode element = elementDeclarator != null && elementType != null ? createFromDeclarator(typedefNode, elementType, elementDeclarator, false) : null;
if (element != null || elementType != null) {
final CppNode typeNode = element != null ? element : elementType;
((TypedefNode) typedefNode).setType(typeNode);
// typedefNode.addDependencyTo(typeNode, DependencyType.USE);
}
}
}
// endregion
} else if (templateParameter instanceof ICPPASTTemplatedTypeTemplateParameter) {
// region Nested Template
final ICPPASTTemplatedTypeTemplateParameter nestedParameter = (ICPPASTTemplatedTypeTemplateParameter) templateParameter;
final IASTName nestedName = nestedParameter.getName();
final CppNode nestedNode = createNode(nestedName.resolveBinding(), nestedName, null, new TypedefNode(), parentNode);
for (final ICPPASTTemplateParameter innerParameter : nestedParameter.getTemplateParameters()) {
createFromTemplateParameter(nestedNode, innerParameter);
}
// endregion
} else {
// todo: debug?
throw new IllegalArgumentException("createFromTemplateParameter(parentNode = (" + Utilities.objectIdentifyString(parentNode) + "), templateParameter = (" + Utilities.objectIdentifyString(templateParameter) + "))");
}
}
Aggregations