@@ -27,6 +27,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod
2727import org .eclipse .cdt .internal .core .dom .parser .cpp .ICPPEvaluation
2828import org .eclipse .cdt .internal .core .dom .parser .cpp .semantics .EvalBinding
2929import org .eclipse .cdt .internal .core .dom .parser .cpp .semantics .EvalMemberAccess
30+ import org .eclipse .cdt .internal .core .dom .parser .cpp .CPPASTFoldExpression
31+ import org .eclipse .cdt .internal .core .dom .parser .cpp .semantics .EvalBinary
32+ import org .eclipse .cdt .internal .core .dom .parser .cpp .semantics .EvalFoldExpression
33+ import org .eclipse .cdt .internal .core .dom .parser .cpp .CPPASTEqualsInitializer
34+ import org .eclipse .cdt .internal .core .dom .parser .cpp .CPPFunction
35+ import org .eclipse .cdt .internal .core .dom .parser .cpp .CPPVariable
3036import org .eclipse .cdt .internal .core .model .ASTStringUtil
3137
3238import java .nio .file .Path
@@ -148,8 +154,9 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
148154 } else {
149155 rawType
150156 }
151- StringUtils .normalizeSpace(tpe) match {
157+ StringUtils .normalizeSpace(tpe.stripSuffix( " () " ) ) match {
152158 case " " => Defines .Any
159+ case t if t.startsWith(" [*this]" ) || t.startsWith(" [this]" ) => t
153160 case t if t.startsWith(" [" ) && t.endsWith(" ]" ) => Defines .Array
154161 case t if t.contains(" ->" ) => Defines .Function
155162 case t if t.contains(" ?" ) => Defines .Any
@@ -186,6 +193,13 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
186193 Try (expr.getEvaluation).toOption
187194 }
188195
196+ protected def safeGetBinding (spec : IASTNamedTypeSpecifier ): Option [IBinding ] = {
197+ // In case of unresolved includes etc. this may fail throwing an unrecoverable exception
198+ Try (spec.getName.resolveBinding()).toOption.collect {
199+ case binding : IBinding if ! binding.isInstanceOf [IProblemBinding ] => binding
200+ }
201+ }
202+
189203 protected def safeGetType (tpe : IType ): String = {
190204 // In case of unresolved includes etc. this may fail throwing an unrecoverable exception
191205 Try (ASTTypeUtil .getType(tpe)).getOrElse(Defines .Any )
@@ -203,6 +217,22 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
203217 }
204218 }
205219
220+ private def typeForCPPASTFoldExpression (f : CPPASTFoldExpression , stripKeywords : Boolean = true ): String = {
221+ safeGetEvaluation(f) match {
222+ case Some (evaluation : EvalFoldExpression ) =>
223+ Try (evaluation.getValue.getEvaluation).toOption match {
224+ case Some (value : EvalBinary ) =>
225+ val s = value.toString
226+ cleanType(s.substring(0 , s.indexOf(" : " )), stripKeywords)
227+ case Some (value : EvalBinding ) if value.getType.isInstanceOf [ICPPParameterPackType ] =>
228+ val s = value.getType.asInstanceOf [ICPPParameterPackType ].getType.toString
229+ cleanType(s, stripKeywords)
230+ case _ => Defines .Any
231+ }
232+ case _ => Defines .Any
233+ }
234+ }
235+
206236 @ nowarn
207237 private def typeForIASTArrayDeclarator (a : IASTArrayDeclarator , stripKeywords : Boolean = true ): String = {
208238 import org .eclipse .cdt .core .dom .ast .ASTSignatureUtil .getNodeSignature
@@ -234,8 +264,10 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
234264 cleanType(evaluation.getOwnerType.toString + deref, stripKeywords)
235265 case Some (evalBinding : EvalBinding ) =>
236266 evalBinding.getBinding match {
237- case m : CPPMethod => cleanType(fullName(m.getDefinition))
238- case _ => cleanType(safeGetNodeType(s), stripKeywords)
267+ case m : CPPMethod => cleanType(safeGetNodeType(m.getPrimaryDeclaration), stripKeywords)
268+ case f : CPPFunction => cleanType(safeGetNodeType(f.getDefinition), stripKeywords)
269+ case v : CPPVariable => cleanType(v.getType.toString)
270+ case _ => cleanType(safeGetNodeType(s), stripKeywords)
239271 }
240272 case _ => cleanType(safeGetNodeType(s), stripKeywords)
241273 }
@@ -256,26 +288,46 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
256288 }
257289 }
258290
291+ private def typeForCPPASTEqualsInitializer (c : CPPASTEqualsInitializer , stripKeywords : Boolean = true ): String = {
292+ import org .eclipse .cdt .core .dom .ast .ASTSignatureUtil .getNodeSignature
293+ c.getInitializerClause match {
294+ case initializer : ICPPASTFunctionCallExpression
295+ if initializer.getFunctionNameExpression.isInstanceOf [CPPASTIdExpression ] =>
296+ val name = initializer.getFunctionNameExpression.asInstanceOf [CPPASTIdExpression ]
297+ typeForCPPASTIdExpression(name, stripKeywords)
298+ case _ =>
299+ cleanType(getNodeSignature(c), stripKeywords)
300+ }
301+ }
302+
259303 @ nowarn
260304 protected def typeFor (node : IASTNode , stripKeywords : Boolean = true ): String = {
261305 import org .eclipse .cdt .core .dom .ast .ASTSignatureUtil .getNodeSignature
262306 node match {
263- case f : CPPASTFieldReference => typeForCPPASTFieldReference(f)
264- case f : IASTFieldReference => cleanType(safeGetType(f.getFieldOwner.getExpressionType), stripKeywords)
265- case a : IASTArrayDeclarator => typeForIASTArrayDeclarator(a)
266- case s : CPPASTIdExpression => typeForCPPASTIdExpression(s)
307+ case f : CPPASTFoldExpression => typeForCPPASTFoldExpression(f, stripKeywords)
308+ case f : CPPASTFieldReference => typeForCPPASTFieldReference(f, stripKeywords)
309+ case s : CPPASTIdExpression => typeForCPPASTIdExpression(s, stripKeywords)
310+ case s : ICPPASTNamedTypeSpecifier => typeForCPPAstNamedTypeSpecifier(s, stripKeywords)
311+ case a : IASTArrayDeclarator => typeForIASTArrayDeclarator(a, stripKeywords)
312+ case c : ICPPASTConstructorInitializer => typeForICPPASTConstructorInitializer(c, stripKeywords)
313+ case c : CPPASTEqualsInitializer => typeForCPPASTEqualsInitializer(c, stripKeywords)
267314 case _ : IASTIdExpression | _ : IASTName | _ : IASTDeclarator => cleanType(safeGetNodeType(node), stripKeywords)
268- case s : IASTNamedTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
269- case s : IASTCompositeTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
270- case s : IASTEnumerationSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
271- case s : IASTElaboratedTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
272- case l : IASTLiteralExpression => cleanType(safeGetType(l.getExpressionType) )
273- case e : IASTExpression => cleanType(safeGetNodeType(e ), stripKeywords)
274- case c : ICPPASTConstructorInitializer => typeForICPPASTConstructorInitializer(c )
275- case _ => cleanType(getNodeSignature(node), stripKeywords)
315+ case f : IASTFieldReference => cleanType(safeGetType(f.getFieldOwner.getExpressionType ), stripKeywords)
316+ case s : IASTNamedTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
317+ case s : IASTCompositeTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
318+ case s : IASTEnumerationSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords)
319+ case s : IASTElaboratedTypeSpecifier => cleanType(ASTStringUtil .getReturnTypeString(s, null ), stripKeywords )
320+ case l : IASTLiteralExpression => cleanType(safeGetType(l.getExpressionType ), stripKeywords)
321+ case e : IASTExpression => cleanType(safeGetNodeType(e), stripKeywords )
322+ case _ => cleanType(getNodeSignature(node), stripKeywords)
276323 }
277324 }
278325
326+ private def typeForCPPAstNamedTypeSpecifier (s : ICPPASTNamedTypeSpecifier , stripKeywords : Boolean ): String = {
327+ val tpe = safeGetBinding(s).map(_.toString.replace(" " , " " )).getOrElse(ASTStringUtil .getReturnTypeString(s, null ))
328+ cleanType(tpe, stripKeywords)
329+ }
330+
279331 private def notHandledText (node : IASTNode ): String =
280332 s """ Node ' ${node.getClass.getSimpleName}' not handled yet!
281333 | Code: ' ${node.getRawSignature}'
@@ -305,6 +357,9 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
305357 r
306358 }
307359
360+ protected def nullSafeAst (node : IASTInitializer ): Ast =
361+ Option (node).map(astForNode).getOrElse(Ast ())
362+
308363 protected def nullSafeAst (node : IASTExpression ): Ast =
309364 Option (node).map(astForNode).getOrElse(Ast ())
310365
@@ -322,7 +377,10 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
322377 }
323378
324379 private def pointersAsString (spec : IASTDeclSpecifier , parentDecl : IASTDeclarator , stripKeywords : Boolean ): String = {
325- val tpe = typeFor(spec, stripKeywords)
380+ val tpe = typeFor(spec, stripKeywords) match {
381+ case Defines .Auto => typeFor(parentDecl, stripKeywords)
382+ case t => t
383+ }
326384 val pointers = parentDecl.getPointerOperators
327385 val arr = parentDecl match {
328386 case p : IASTArrayDeclarator => p.getArrayModifiers.toList.map(_.getRawSignature).mkString
@@ -425,6 +483,7 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
425483 case l : IASTInitializerList => astForInitializerList(l)
426484 case c : ICPPASTConstructorInitializer => astForCPPASTConstructorInitializer(c)
427485 case d : ICASTDesignatedInitializer => astForCASTDesignatedInitializer(d)
486+ case d : IASTEqualsInitializer => astForNode(d.getInitializerClause)
428487 case d : ICPPASTDesignatedInitializer => astForCPPASTDesignatedInitializer(d)
429488 case d : CASTArrayRangeDesignator => astForCASTArrayRangeDesignator(d)
430489 case d : CPPASTArrayRangeDesignator => astForCPPASTArrayRangeDesignator(d)
0 commit comments