Search in sources :

Example 1 with IASTTypeId

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) + "))");
    }
}
Also used : ICPPASTTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) IASTDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) ICPPASTSimpleTypeTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) CppNode(mrmathami.cia.cpp.ast.CppNode) ICPPASTTemplatedTypeTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter) IASTTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) ICPPASTParameterDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration) TypedefNode(mrmathami.cia.cpp.ast.TypedefNode) IASTDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)

Aggregations

CppNode (mrmathami.cia.cpp.ast.CppNode)1 TypedefNode (mrmathami.cia.cpp.ast.TypedefNode)1 IASTDeclSpecifier (org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)1 IASTDeclarator (org.eclipse.cdt.core.dom.ast.IASTDeclarator)1 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)1 IASTTypeId (org.eclipse.cdt.core.dom.ast.IASTTypeId)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 ICPPASTParameterDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration)1 ICPPASTSimpleTypeTemplateParameter (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter)1 ICPPASTTemplateParameter (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter)1 ICPPASTTemplatedTypeTemplateParameter (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter)1