1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Patch for Hoda Amer.

This core patch cleans up the CModelBuilder. It also solves a bug and all tests in IStructureTests now pass successfully. 
In the core.tests patch, the test for templates of variables is removed from ITemplateTests because it is moved to the failed tests.
This commit is contained in:
John Camelon 2003-07-24 21:47:13 +00:00
parent e312c1724b
commit a446c41e78
4 changed files with 67 additions and 308 deletions

View file

@ -1,6 +1,7 @@
2003-07-24 Hoda Amer 2003-07-24 Hoda Amer
Moved part of the CModelElementsTest (Templates of Variables ) to the failed tests. Moved part of the CModelElementsTest (Templates of Variables ) to the failed tests.
Moved the same test (Templates of Variables) from ITemplateTests to failed tests.
2003-07-24 Hoda Amer 2003-07-24 Hoda Amer
This patch updates the CModelBuilder to use the AST instead of the DOM. This patch updates the CModelBuilder to use the AST instead of the DOM.

View file

@ -132,7 +132,9 @@ public class ITemplateTests extends IntegratedCModelTest {
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName()); assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
} }
} }
{ /*
// TEMPLATE_VARIABLE moved to failed tests
{
ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE); ArrayList arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE);
String[] myExpectedValues = { String[] myExpectedValues = {
"default_alloc_template<threads,inst>::S_start_free" "default_alloc_template<threads,inst>::S_start_free"
@ -144,7 +146,7 @@ public class ITemplateTests extends IntegratedCModelTest {
assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName()); assertEquals("Failed on "+i, myExpectedValues[i], myITemplate.getElementName());
} }
} }
} */ }
public void testGetNumberOfTemplateParameters() public void testGetNumberOfTemplateParameters()
@ -156,11 +158,12 @@ public class ITemplateTests extends IntegratedCModelTest {
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
arrayElements.addAll( getTemplateMethods(tu) ); arrayElements.addAll( getTemplateMethods(tu) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) ); // TEMPLATE_VARIABLE moved to failed tests
//arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
int[] myExpectedNumbers = { int[] myExpectedNumbers = {
// 3,1,3,1,1,3 // 3,1,3,1,1,3
3,1,3,1,1,1,1,1,2 3,1,3,1,1,1,1,1/*,2*/
}; };
assertEquals(myExpectedNumbers.length, arrayElements.size()); assertEquals(myExpectedNumbers.length, arrayElements.size());
for(int i=0; i<myExpectedNumbers.length; i++) { for(int i=0; i<myExpectedNumbers.length; i++) {
@ -179,7 +182,8 @@ public class ITemplateTests extends IntegratedCModelTest {
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
arrayElements.addAll( getTemplateMethods(tu) ); arrayElements.addAll( getTemplateMethods(tu) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) ); // TEMPLATE_VARIABLE moved to failed tests
//arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
String[][] myExpectedValues = { String[][] myExpectedValues = {
//"Map" //"Map"
@ -198,8 +202,9 @@ public class ITemplateTests extends IntegratedCModelTest {
{"X"}, {"X"},
//"Foo::fum" //"Foo::fum"
{"Bar"}, {"Bar"},
/*
//"default_alloc_template::S_start_free" //"default_alloc_template::S_start_free"
{"bool", "int"}, {"bool", "int"},*/
}; };
assertEquals(myExpectedValues.length, arrayElements.size()); assertEquals(myExpectedValues.length, arrayElements.size());
for(int i=0; i<myExpectedValues.length; i++) { for(int i=0; i<myExpectedValues.length; i++) {
@ -222,7 +227,8 @@ public class ITemplateTests extends IntegratedCModelTest {
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_UNION ) );
arrayElements.addAll( getTemplateMethods(tu) ); arrayElements.addAll( getTemplateMethods(tu) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) ); arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_FUNCTION ) );
arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) ); // TEMPLATE_VARIABLE moved to failed tests
//arrayElements.addAll( tu.getChildrenOfType(ICElement.C_TEMPLATE_VARIABLE ) );
String[] myExpectedValues = { String[] myExpectedValues = {
"Map<Key, Value, SortAlgorithm>", "Map<Key, Value, SortAlgorithm>",
@ -234,7 +240,7 @@ public class ITemplateTests extends IntegratedCModelTest {
// TODO: shouldn't signature indicate const function as well? // TODO: shouldn't signature indicate const function as well?
"IsGreaterThan<X>(X, X) : bool", "IsGreaterThan<X>(X, X) : bool",
"Foo::fum<Bar>(int) : void", "Foo::fum<Bar>(int) : void",
"default_alloc_template<threads,inst>::S_start_free<bool, int> : char*", /*"default_alloc_template<threads,inst>::S_start_free<bool, int> : char*",*/
}; };
assertEquals(myExpectedValues.length, arrayElements.size()); assertEquals(myExpectedValues.length, arrayElements.size());
for(int i=0; i<myExpectedValues.length; i++) { for(int i=0; i<myExpectedValues.length; i++) {

View file

@ -1,3 +1,6 @@
2003-07-24 Hoda Amer
Clean up of CModelBuilder
2003-07-23 Hoda Amer 2003-07-23 Hoda Amer
Updated the CModelBuilder to use the AST instead of the DOM Updated the CModelBuilder to use the AST instead of the DOM

View file

@ -48,6 +48,7 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.ParserException;
@ -195,23 +196,7 @@ public class CModelBuilder {
protected void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws ASTNotImplementedException protected void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws ASTNotImplementedException
{ {
// IASTAbstractTypeSpecifierDeclaration // IASTAbstractTypeSpecifierDeclaration
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier(); CElement element = createAbstractElement(parent, abstractDeclaration, false);
// IASTEnumerationSpecifier
if ( typeSpec instanceof IASTEnumerationSpecifier){
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
IParent enumElement = createEnumeration (parent, enumSpecifier);
}
// IASTClassSpecifier
else if (typeSpec instanceof IASTClassSpecifier){
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
IParent classElement = createClass (parent, classSpecifier, false);
// create the sub declarations
Iterator j = classSpecifier.getDeclarations();
while (j.hasNext()){
IASTDeclaration subDeclaration = (IASTDeclaration)j.next();
generateModelElements((Parent)classElement, subDeclaration);
} // end while j
}
} }
protected void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws ASTNotImplementedException protected void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws ASTNotImplementedException
@ -219,29 +204,16 @@ public class CModelBuilder {
// Template Declaration // Template Declaration
IASTDeclaration declaration = (IASTDeclaration)templateDeclaration.getOwnedDeclaration(); IASTDeclaration declaration = (IASTDeclaration)templateDeclaration.getOwnedDeclaration();
if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){ if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){
IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ; IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ;
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier(); CElement element = createAbstractElement(parent, abstractDeclaration , true);
if (typeSpec instanceof IASTClassSpecifier){ // set the element position
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec; element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
ITemplate classTemplate = (StructureTemplate)createClass(parent, classSpecifier, true); // set the element lines
CElement element = (CElement) classTemplate; //element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
// set the template parameters
// set the element position String[] parameterTypes = getTemplateParameters(templateDeclaration);
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); ITemplate classTemplate = (ITemplate) element;
// set the element lines classTemplate.setTemplateParameterTypes(parameterTypes);
//element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
// set the template parameters
String[] parameterTypes = getTemplateParameters(templateDeclaration);
classTemplate.setTemplateParameterTypes(parameterTypes);
// create the sub declarations
Iterator j = classSpecifier.getDeclarations();
while (j.hasNext()){
IASTDeclaration subDeclaration = (IASTDeclaration)j.next();
generateModelElements((Parent)classTemplate, subDeclaration);
} // end while j
}
} }
ITemplate template = null; ITemplate template = null;
@ -266,8 +238,6 @@ public class CModelBuilder {
CElement element = (CElement)template; CElement element = (CElement)template;
// set the element position // set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
// set the element lines
//element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
// set the template parameters // set the template parameters
String[] parameterTypes = getTemplateParameters(templateDeclaration); String[] parameterTypes = getTemplateParameters(templateDeclaration);
template.setTemplateParameterTypes(parameterTypes); template.setTemplateParameterTypes(parameterTypes);
@ -278,30 +248,34 @@ public class CModelBuilder {
{ {
TypeDef typeDef = createTypeDef(parent, declaration); TypeDef typeDef = createTypeDef(parent, declaration);
IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator(); IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator();
generateModelElements(parent, abstractDeclaration); CElement element = createAbstractElement(parent, abstractDeclaration, false);
} }
protected void generateModelElements (Parent parent, IASTAbstractDeclaration abstractDeclaration) throws ASTNotImplementedException{ private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate)throws ASTNotImplementedException{
/*------------------------------------------- CElement element = null;
* Checking the type if it is a composite one if(abstractDeclaration != null){
*-------------------------------------------*/ IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier();
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier(); // IASTEnumerationSpecifier
// IASTEnumerationSpecifier if ( typeSpec instanceof IASTEnumerationSpecifier){
if ( typeSpec instanceof IASTEnumerationSpecifier){ IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec; IParent enumElement = createEnumeration (parent, enumSpecifier);
IParent enumElement = createEnumeration (parent, enumSpecifier); element = (CElement) enumElement;
} }
// IASTClassSpecifier // IASTClassSpecifier
else if (typeSpec instanceof IASTClassSpecifier){ else if (typeSpec instanceof IASTClassSpecifier){
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec; IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
IParent classElement = createClass (parent, classSpecifier, false); IParent classElement = createClass(parent, classSpecifier, isTemplate);
// create the sub declarations element = (CElement) classElement;
Iterator j = classSpecifier.getDeclarations();
while (j.hasNext()){ // create the sub declarations
IASTDeclaration subDeclaration = (IASTDeclaration)j.next(); Iterator j = classSpecifier.getDeclarations();
generateModelElements((Parent)classElement, subDeclaration); while (j.hasNext()){
} // end while j IASTDeclaration subDeclaration = (IASTDeclaration)j.next();
} generateModelElements((Parent)classElement, subDeclaration);
} // end while j
}
}
return element;
} }
protected Include createInclusion(Parent parent, IASTInclusion inclusion){ protected Include createInclusion(Parent parent, IASTInclusion inclusion){
@ -312,8 +286,7 @@ public class CModelBuilder {
// set position // set position
element.setIdPos(inclusion.getNameOffset(), inclusion.getName().length()); element.setIdPos(inclusion.getNameOffset(), inclusion.getName().length());
element.setPos(inclusion.getStartingOffset(), inclusion.getEndingOffset() - inclusion.getStartingOffset()); element.setPos(inclusion.getStartingOffset(), inclusion.getEndingOffset() - inclusion.getStartingOffset());
// set the element lines
//element.setLines(inclusion.getTopLine(), inclusion.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
} }
@ -326,8 +299,7 @@ public class CModelBuilder {
// set position // set position
element.setIdPos(macro.getNameOffset(), macro.getName().length()); element.setIdPos(macro.getNameOffset(), macro.getName().length());
element.setPos(macro.getStartingOffset(), macro.getEndingOffset() - macro.getStartingOffset()); element.setPos(macro.getStartingOffset(), macro.getEndingOffset() - macro.getStartingOffset());
// set the element lines
//element.setLines(macro.getTopLine(), macro.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
} }
@ -344,8 +316,6 @@ public class CModelBuilder {
element.setIdPos(nsDef.getNameOffset(), (nsName.length() == 0) ? type.length() : nsName.length()); element.setIdPos(nsDef.getNameOffset(), (nsName.length() == 0) ? type.length() : nsName.length());
element.setPos(nsDef.getStartingOffset(), nsDef.getEndingOffset() - nsDef.getStartingOffset()); element.setPos(nsDef.getStartingOffset(), nsDef.getEndingOffset() - nsDef.getStartingOffset());
element.setTypeName(type); element.setTypeName(type);
// set the element lines
//element.setLines(nsDef.getTopLine(), nsDef.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
@ -370,8 +340,6 @@ public class CModelBuilder {
element.setIdPos(enumSpecifier.getNameOffset(), (enumName.length() == 0) ? type.length() : enumName.length()); element.setIdPos(enumSpecifier.getNameOffset(), (enumName.length() == 0) ? type.length() : enumName.length());
element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getEndingOffset() - enumSpecifier.getStartingOffset()); element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getEndingOffset() - enumSpecifier.getStartingOffset());
element.setTypeName(type); element.setTypeName(type);
// set the element lines
//element.setLines(enumSpecifier.getTopLine(), enumSpecifier.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
@ -384,8 +352,6 @@ public class CModelBuilder {
// set enumerator position // set enumerator position
element.setIdPos(enumDef.getStartingOffset(), enumDef.getName().length()); element.setIdPos(enumDef.getStartingOffset(), enumDef.getName().length());
element.setPos(enumDef.getStartingOffset(), enumDef.getEndingOffset() - enumDef.getStartingOffset()); element.setPos(enumDef.getStartingOffset(), enumDef.getEndingOffset() - enumDef.getStartingOffset());
// set the element lines
//element.setLines(enumDef.getTopLine(), enumDef.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
@ -446,8 +412,6 @@ public class CModelBuilder {
if(!isTemplate){ if(!isTemplate){
// set the element position // set the element position
element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getEndingOffset() - classSpecifier.getStartingOffset()); element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getEndingOffset() - classSpecifier.getStartingOffset());
// set the element lines
//element.setLines(classSpecifier.getTopLine(), classSpecifier.getBottomLine());
} }
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
@ -469,15 +433,16 @@ public class CModelBuilder {
// set positions // set positions
element.setIdPos(typeDefDeclaration.getNameOffset(),name.length()); element.setIdPos(typeDefDeclaration.getNameOffset(),name.length());
element.setPos(typeDefDeclaration.getStartingOffset(), typeDefDeclaration.getEndingOffset() - typeDefDeclaration.getStartingOffset()); element.setPos(typeDefDeclaration.getStartingOffset(), typeDefDeclaration.getEndingOffset() - typeDefDeclaration.getStartingOffset());
// set the element lines
//element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
return element; return element;
} }
protected VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate) protected VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws ASTNotImplementedException
{ {
IASTAbstractDeclaration abstractDeclaration = varDeclaration.getAbstractDeclaration();
CElement abstractElement = createAbstractElement (parent, abstractDeclaration , isTemplate);
String variableName = varDeclaration.getName(); String variableName = varDeclaration.getName();
if(variableName == null){ if(variableName == null){
// something is wrong, skip this element // something is wrong, skip this element
@ -523,8 +488,6 @@ public class CModelBuilder {
if(!isTemplate){ if(!isTemplate){
// set element position // set element position
element.setPos(varDeclaration.getStartingOffset(), varDeclaration.getEndingOffset() - varDeclaration.getStartingOffset()); element.setPos(varDeclaration.getStartingOffset(), varDeclaration.getEndingOffset() - varDeclaration.getStartingOffset());
// set the element lines
//element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
} }
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
@ -615,8 +578,6 @@ public class CModelBuilder {
if(!isTemplate){ if(!isTemplate){
// set the element position // set the element position
element.setPos(functionDeclaration.getStartingOffset(), functionDeclaration.getEndingOffset() - functionDeclaration.getStartingOffset()); element.setPos(functionDeclaration.getStartingOffset(), functionDeclaration.getEndingOffset() - functionDeclaration.getStartingOffset());
// set the element lines
//element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
} }
this.newElements.put(element, element.getElementInfo()); this.newElements.put(element, element.getElementInfo());
@ -678,139 +639,17 @@ public class CModelBuilder {
// get type from declaration // get type from declaration
type.append(getDeclarationType(declaration)); type.append(getDeclarationType(declaration));
type.append(getSubtype(declaration));
// type.append(getSubType(declarator, new SubTypeProcessingFlags(false)));
return type.toString();
}
private String getSubtype(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer();
type.append(getPointerOperation(declaration)); type.append(getPointerOperation(declaration));
type.append(getArrayQualifiers(declaration)); type.append(getArrayQualifiers(declaration));
return type.toString();
}
/* private class SubTypeProcessingFlags {
boolean returnTypeForFunction = false;
boolean processedInnermostParameterList = false;
SubTypeProcessingFlags(boolean returnTypeForFunction) {
this.returnTypeForFunction = returnTypeForFunction;
}
}
*/
/* private String getSubType(Declarator declarator, SubTypeProcessingFlags flags) {
StringBuffer type = new StringBuffer();
// add pointer or reference from declarator if any
String declaratorPointerOperation = getDeclaratorPointerOperation(declarator);
try {
switch (declaratorPointerOperation.charAt(0)) {
case '*':
case '&':
break; // pointer/reference
default:
type.append(" "); // pointer to member
}
} catch (Exception e) {} // Empty/null strings
type.append(declaratorPointerOperation);
String subType = null;
if (declarator.getDeclarator() != null){
// process inner declarator
subType = getSubType(declarator.getDeclarator(), flags);
boolean appendParen = true;
if ( (subType == null) || (subType.length() == 0)
||
((subType.charAt(0) == '(')
&&
(subType.charAt(subType.length()-1) == ')'))) {
// Additional () are not necessary
appendParen = false;
}
if (appendParen) type.append("(");
type.append(subType);
if (appendParen) type.append(")");
}
// parameters
if (declarator.getParms() != null) {
// If we process return type for a function,
// skip innermost parameter list - it is a part
// of function's signature
if ( !flags.returnTypeForFunction
|| flags.processedInnermostParameterList) {
if ((subType == null) || (subType.length() == 0)) {
type.append("()");
}
type.append(getParametersString(declarator));
}
flags.processedInnermostParameterList = true;
}
// arrays
type.append(getDeclaratorArrayQualifiers(declarator));
return type.toString(); return type.toString();
} }
*/
/**
* Here is a tricky one. Determines if a declarator represents a function
* specification, or a variable declaration (that includes pointers to functions).
* If none of the nested declarators contain parameter list, then it is obviously a variable.
* It is a function specification only if no declarators in (A..B] range
* contain any pointer/array specificators. A is the declarator containing
* the innermost parameter list (which corresponds to parameters of the function),
* and B is the innermost declarator (should contain the name of the element).
*
* @param declarator
* @return True, if the declarator represents a function specification
*/
/* private boolean isFunctionSpecification(Declarator declarator)
{
Declarator currentDeclarator = declarator;
boolean result = false;
while (currentDeclarator != null) {
if (currentDeclarator.getParms() != null) {
result = true;
} else {
List ptrOps = currentDeclarator.getPointerOperators();
List arrayQs = currentDeclarator.getArrayQualifiers();
if ( ((ptrOps != null) && (ptrOps.size() > 0))
|| ((arrayQs != null) && (arrayQs.size() > 0))
)
{
result = false;
}
}
currentDeclarator = currentDeclarator.getDeclarator();
}
return result;
}
*/
private String getDeclarationType(IASTAbstractDeclaration declaration){ private String getDeclarationType(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer(); StringBuffer type = new StringBuffer();
if(declaration.isConst()) if(declaration.isConst())
type.append("const "); type.append("const ");
// TODO: Fix volatile
// if(declaration.isVolatile())
// type.append("volatile ");
IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier(); IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier();
if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){ if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier; IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier;
@ -857,10 +696,7 @@ public class CModelBuilder {
pointerString.append(" const"); pointerString.append(" const");
if(po == ASTPointerOperator.VOLATILE_POINTER) if(po == ASTPointerOperator.VOLATILE_POINTER)
pointerString.append(" volatile"); pointerString.append(" volatile");
// case PointerOperator.t_pointer_to_member:
// pointerString.append(po.getNameSpecifier());
} }
return pointerString.toString(); return pointerString.toString();
} }
@ -875,46 +711,6 @@ public class CModelBuilder {
return arrayString.toString(); return arrayString.toString();
} }
/* private String[] getParameterTypes(Declarator declarator, HashMap mapOfKRParams)
{
if (declarator == null) return null;
ParameterDeclarationClause pdc = declarator.getParms();
String[] parameterTypes = null;
if (pdc != null) {
List parameterList = pdc.getDeclarations();
parameterTypes = new String[parameterList.size()];
for (int j = 0; j < parameterList.size(); ++j) {
ParameterDeclaration param = (ParameterDeclaration) parameterList.get(j);
Declarator decl = (Declarator) param.getDeclarators().get(0);
parameterTypes[j] = getType(param);
if ( (mapOfKRParams != null)
&& (mapOfKRParams.size() > 0)
&& (decl.getName() == null))
{
// We have some K&R-style parameter declarations,
// and the current parameter has been declared with a single identifier,
// (like ...(argname)...)
// It has been parsed as a typename, so 'argname' is a name of the type,
// and parameter name is empty. But for this particular case,
// 'argname' is a name, and its type we have to lookup in the map
// of old K&R-style parameter declarations.
// If we can't find it, we keep parameter name in the signature
String oldKRParamType = (String)mapOfKRParams.get(parameterTypes[j]);
if (oldKRParamType != null) {
parameterTypes[j] = oldKRParamType;
}
}
}
}
return parameterTypes;
}
*/
private String[] getFunctionParameterTypes(IASTFunction functionDeclaration) private String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
{ {
Iterator parameters = functionDeclaration.getParameters(); Iterator parameters = functionDeclaration.getParameters();
@ -928,53 +724,6 @@ public class CModelBuilder {
parameterTypes[i] = (String)paramList.get(i); parameterTypes[i] = (String)paramList.get(i);
} }
return parameterTypes; return parameterTypes;
/* Declarator currentDeclarator = declarator;
Declarator innermostPDCDeclarator = null;
while (currentDeclarator != null) {
if (currentDeclarator.getParms() != null) {
innermostPDCDeclarator = currentDeclarator;
}
currentDeclarator = currentDeclarator.getDeclarator();
}
HashMap mapOfKRParams = null;
if ( declarator != null
&& declarator.getParms() != null
&& declarator.getParms().getOldKRParms() != null) {
mapOfKRParams = new HashMap();
OldKRParameterDeclarationClause oldKRpdc = declarator.getParms().getOldKRParms();
List oldKRParameterList = oldKRpdc.getDeclarations();
for (int j = 0; j < oldKRParameterList.size(); ++j) {
if(oldKRParameterList.get(j) instanceof SimpleDeclaration) { // Must be
SimpleDeclaration declKR = (SimpleDeclaration)oldKRParameterList.get(j);
List declarators = declKR.getDeclarators();
Iterator d = declarators.iterator();
while (d.hasNext()) {
Declarator decl = (Declarator) d.next();
String oldKRparamName = getDOMName(decl);
String oldKRparamType = getType(declKR, decl);
if ( (oldKRparamType != null)
&& (oldKRparamName != null)
&& (oldKRparamName.toString().length() > 0)
) {
mapOfKRParams.put(oldKRparamName.toString(), oldKRparamType);
}
}
}
}
}
return getParameterTypes(innermostPDCDeclarator, mapOfKRParams);
*/
} }
private String getParametersString(String[] parameterTypes) private String getParametersString(String[] parameterTypes)