mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
Patch for Hoda Amer:
-determines the project nature before calling the parser. -sets the visibility of member template methods.
This commit is contained in:
parent
2ba1428cf1
commit
c479717511
3 changed files with 84 additions and 27 deletions
|
@ -323,11 +323,11 @@ public class DeclSpecifier {
|
||||||
type.append(getName().toString());
|
type.append(getName().toString());
|
||||||
else {
|
else {
|
||||||
if (isUnsigned())
|
if (isUnsigned())
|
||||||
type.append("unsigned");
|
type.append("unsigned ");
|
||||||
if (isShort())
|
if (isShort())
|
||||||
type.append("short");
|
type.append("short ");
|
||||||
if (isLong())
|
if (isLong())
|
||||||
type.append("long");
|
type.append("long ");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.INamespace;
|
import org.eclipse.cdt.core.model.INamespace;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
|
@ -44,6 +45,8 @@ import org.eclipse.cdt.internal.core.dom.TemplateParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
|
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
|
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
|
||||||
public class CModelBuilder {
|
public class CModelBuilder {
|
||||||
|
|
||||||
org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
||||||
|
@ -55,6 +58,9 @@ public class CModelBuilder {
|
||||||
DOMBuilder domBuilder = new DOMBuilder();
|
DOMBuilder domBuilder = new DOMBuilder();
|
||||||
String code = translationUnit.getBuffer().getContents();
|
String code = translationUnit.getBuffer().getContents();
|
||||||
Parser parser = new Parser(code, domBuilder, true);
|
Parser parser = new Parser(code, domBuilder, true);
|
||||||
|
IProject currentProject = translationUnit.getCProject().getProject();
|
||||||
|
boolean hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
|
||||||
|
parser.setCppNature(hasCppNature);
|
||||||
parser.parse();
|
parser.parse();
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
generateModelElements(domBuilder.getTranslationUnit());
|
generateModelElements(domBuilder.getTranslationUnit());
|
||||||
|
@ -162,36 +168,30 @@ public class CModelBuilder {
|
||||||
createTypeDef(parent, declarator, simpleDeclaration);
|
createTypeDef(parent, declarator, simpleDeclaration);
|
||||||
} else {
|
} else {
|
||||||
ParameterDeclarationClause pdc = declarator.getParms();
|
ParameterDeclarationClause pdc = declarator.getParms();
|
||||||
|
// variable or field
|
||||||
if (pdc == null){
|
if (pdc == null){
|
||||||
createVariableSpecification(parent, simpleDeclaration, declarator);
|
createVariableSpecification(parent, simpleDeclaration, declarator);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
// pointer to function
|
||||||
|
if(declarator.getDeclarator() != null){
|
||||||
|
createPointerToFunction(parent, simpleDeclaration, declarator, pdc, false);
|
||||||
|
}else {
|
||||||
|
// function or method
|
||||||
createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, false);
|
createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createTemplateElement(Parent parent, TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
|
private void createTemplateElement(Parent parent, TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
|
||||||
ParameterDeclarationClause pdc = declarator.getParms();
|
ParameterDeclarationClause pdc = declarator.getParms();
|
||||||
if (pdc != null){
|
if (pdc != null){
|
||||||
|
// template of function or method
|
||||||
ITemplate template = (ITemplate) createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, true);
|
ITemplate template = (ITemplate) createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, true);
|
||||||
String[] parameterTypes = getTemplateParameters(templateDeclaration);
|
String[] parameterTypes = getTemplateParameters(templateDeclaration);
|
||||||
template.setTemplateParameterTypes(parameterTypes);
|
template.setTemplateParameterTypes(parameterTypes);
|
||||||
|
|
||||||
}
|
}
|
||||||
/*// typedef
|
|
||||||
if(simpleDeclaration.getDeclSpecifier().isTypedef()){
|
|
||||||
createTypeDef(parent, declarator, simpleDeclaration);
|
|
||||||
} else {
|
|
||||||
ParameterDeclarationClause pdc = declarator.getParms();
|
|
||||||
if (pdc == null){
|
|
||||||
createVariableSpecification(parent, simpleDeclaration, declarator);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
createFunctionSpecification(parent, simpleDeclaration, declarator, pdc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
private void createInclusion(Parent parent, Inclusion inclusion){
|
private void createInclusion(Parent parent, Inclusion inclusion){
|
||||||
// create element
|
// create element
|
||||||
|
@ -366,8 +366,7 @@ public class CModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
|
private FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
|
||||||
boolean pointerToFunction = declarator.getDeclarator() != null;
|
String declaratorName = declarator.getName().toString();
|
||||||
String declaratorName = pointerToFunction ? declarator.getDeclarator().getName().toString() : declarator.getName().toString();
|
|
||||||
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
|
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
|
||||||
// getParameterTypes
|
// getParameterTypes
|
||||||
List parameterList = pdc.getDeclarations();
|
List parameterList = pdc.getDeclarations();
|
||||||
|
@ -397,7 +396,7 @@ public class CModelBuilder {
|
||||||
element = newElement;
|
element = newElement;
|
||||||
}else {
|
}else {
|
||||||
MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
|
MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
|
||||||
// newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
|
newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
|
||||||
element = newElement;
|
element = newElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,14 +437,57 @@ public class CModelBuilder {
|
||||||
parent.addChild( element );
|
parent.addChild( element );
|
||||||
|
|
||||||
// hook up the offsets
|
// hook up the offsets
|
||||||
if( pointerToFunction )
|
|
||||||
element.setIdPos( declarator.getDeclarator().getName().getStartOffset(), declarator.getDeclarator().getName().length() );
|
|
||||||
else
|
|
||||||
element.setIdPos( declarator.getName().getStartOffset(), declarator.getName().length() );
|
element.setIdPos( declarator.getName().getStartOffset(), declarator.getName().length() );
|
||||||
element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
|
element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private VariableDeclaration createPointerToFunction(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
|
||||||
|
String declaratorName = declarator.getDeclarator().getName().toString();
|
||||||
|
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
|
||||||
|
// getParameterTypes
|
||||||
|
List parameterList = pdc.getDeclarations();
|
||||||
|
String[] parameterTypes = new String[parameterList.size()];
|
||||||
|
VariableDeclaration element = null;
|
||||||
|
for( int j = 0; j< parameterList.size(); ++j )
|
||||||
|
{
|
||||||
|
ParameterDeclaration param = (ParameterDeclaration )parameterList.get(j);
|
||||||
|
parameterTypes[j] = new String(getType(param, (Declarator)param.getDeclarators().get(0)));
|
||||||
|
}
|
||||||
|
if(( parent instanceof ITranslationUnit )
|
||||||
|
|| ( parent instanceof INamespace ))
|
||||||
|
{
|
||||||
|
element = new VariableDeclaration(parent, declaratorName);
|
||||||
|
}
|
||||||
|
StringBuffer typeName = new StringBuffer();
|
||||||
|
typeName.append(getType(simpleDeclaration, declarator));
|
||||||
|
typeName.append("(*)");
|
||||||
|
if(parameterTypes.length > 0){
|
||||||
|
typeName.append("(");
|
||||||
|
int i = 0;
|
||||||
|
typeName.append(parameterTypes[i++]);
|
||||||
|
while (i < parameterTypes.length){
|
||||||
|
typeName.append(", ");
|
||||||
|
typeName.append(parameterTypes[i++]);
|
||||||
|
}
|
||||||
|
typeName.append(")");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
typeName.append("()");
|
||||||
|
}
|
||||||
|
element.setTypeName( typeName.toString() );
|
||||||
|
element.setVolatile(declSpecifier.isVolatile());
|
||||||
|
element.setStatic(declSpecifier.isStatic());
|
||||||
|
element.setConst(declarator.isConst());
|
||||||
|
|
||||||
|
// add to parent
|
||||||
|
parent.addChild( element );
|
||||||
|
|
||||||
|
// hook up the offsets
|
||||||
|
element.setIdPos( declarator.getDeclarator().getName().getStartOffset(), declarator.getDeclarator().getName().length() );
|
||||||
|
element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
|
||||||
|
return element;
|
||||||
|
}
|
||||||
private String[] getTemplateParameters(ITemplateParameterListOwner templateDeclaration){
|
private String[] getTemplateParameters(ITemplateParameterListOwner templateDeclaration){
|
||||||
// add the parameters
|
// add the parameters
|
||||||
List templateParameters = templateDeclaration.getTemplateParms().getDeclarations();
|
List templateParameters = templateDeclaration.getTemplateParms().getDeclarations();
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class Parser {
|
||||||
private IParserCallback callback;
|
private IParserCallback callback;
|
||||||
private boolean quickParse = false;
|
private boolean quickParse = false;
|
||||||
private boolean parsePassed = true;
|
private boolean parsePassed = true;
|
||||||
|
private boolean cppNature = true;
|
||||||
|
|
||||||
// TO DO: convert to a real symbol table
|
// TO DO: convert to a real symbol table
|
||||||
private Map currRegion = new HashMap();
|
private Map currRegion = new HashMap();
|
||||||
|
@ -2239,4 +2240,18 @@ c, quick);
|
||||||
lastToken = null;
|
lastToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isCppNature() {
|
||||||
|
return cppNature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param b
|
||||||
|
*/
|
||||||
|
public void setCppNature(boolean b) {
|
||||||
|
cppNature = b;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue