use of org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator in project Cpp4CIA by thanhminhmr.
the class AstBuilder method createFromDeclarator.
@Nonnull
private CppNode createFromDeclarator(@Nonnull CppNode parentNode, @Nullable CppNode typeNode, @Nonnull IASTDeclarator declarator, boolean isTypedef) {
final IASTName declaratorName = declarator.getName();
final IBinding declaratorBinding = declaratorName.resolveBinding();
final String signature = ASTStringUtil.getSignatureString(declarator);
if (declarator instanceof IASTAmbiguousDeclarator) {
return createUnknownNode(parentNode, declaratorBinding, declaratorName.toString(), isTypedef);
} else if (declarator instanceof ICPPASTFunctionDeclarator) {
// region Function
final ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
final CppNode functionNode = createNode(declaratorBinding, declaratorName, signature, new FunctionNode(), parentNode);
if (functionNode instanceof FunctionNode) {
if (!(typeNode instanceof IntegralNode) || !typeNode.getName().isEmpty()) {
((FunctionNode) functionNode).setType(typeNode);
// functionNode.addDependencyTo(typeNode, DependencyType.USE);
}
for (final ICPPASTParameterDeclaration functionParameter : functionDeclarator.getParameters()) {
final CppNode parameterType = createFromDeclSpecifier(functionNode, functionParameter.getDeclSpecifier());
if (!(parameterType instanceof IntegralNode) || !parameterType.getName().equals("void")) {
createFromDeclarator(functionNode, parameterType, functionParameter.getDeclarator(), true);
((FunctionNode) functionNode).addParameter(parameterType);
// functionNode.addDependencyTo(parameterType, DependencyType.USE);
}
}
final IASTInitializer initializer = declarator.getInitializer();
if (initializer != null && initializer.getChildren().length > 0) {
((FunctionNode) functionNode).setBody(initializer.getRawSignature());
childrenCreationQueue.add(Pair.mutableOf(functionNode, initializer));
}
}
// endregion
return functionNode;
} else if (declarator instanceof ICPPASTDeclarator) {
if (isTypedef) {
// region Typedef
final CppNode typedefNode = createNode(declaratorBinding, declaratorName, signature, new TypedefNode(), parentNode);
if (typedefNode instanceof TypedefNode) {
((TypedefNode) typedefNode).setType(typeNode);
// typedefNode.addDependencyTo(typeNode, DependencyType.USE);
}
// endregion
return typedefNode;
} else {
// region Variable
final CppNode variableNode = createNode(declaratorBinding, declaratorName, signature, new VariableNode(), parentNode);
if (variableNode instanceof VariableNode) {
((VariableNode) variableNode).setType(typeNode);
// variableNode.addDependencyTo(typeNode, DependencyType.USE);
final IASTInitializer initializer = declarator.getInitializer();
if (initializer != null) {
((VariableNode) variableNode).setBody(initializer.getRawSignature());
childrenCreationQueue.add(Pair.mutableOf(variableNode, initializer));
}
}
// endregion
return variableNode;
}
} else {
// todo: debug?
throw new IllegalArgumentException("createFromDeclarator(declarator = (" + Utilities.objectIdentifyString(declarator) + "))");
}
}
Aggregations