[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-dev] Reading formal parameters from AST
|
We don't have a public way of creating the representation for an int.
If you want, you can add something like that to CDT:
interface ITypeFactory {
IBasicType createInt();
}
With that you could use IType.isSameType(IType) to figure out whether
you have an int:
typeFactory.createInt().isSameType(type);
Currently the only alternative to ASTTypeUtil is the following code,
where you probably don't see any simplification:
boolean isInt(IType t) {
if (!(t instanceof IBasicType))
return false;
IBasicType bt= (IBasicType) t;
return bt.getKind() == IBasicType.Kind.eInt &&
(bt.getModifiers() & ~IBasicType.IS_SIGNED) == 0;
}
Markus.
> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx
> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Hagge, Nils
> Sent: Wednesday, January 20, 2010 12:46 PM
> To: CDT General developers list.
> Subject: AW: [cdt-dev] Reading formal parameters from AST
> Importance: Low
>
> Hi Markus,
>
> thanks for your comments!
>
> > It'd be easier to resolve the binding for the function main:
> > IFunction f= (IFunction) declarator.getName().resolveBinding();
>
> > From there you have access to the function type:
> > IFunctionType ft= f.getType();
>
> > Then you can check return type and parameter types:
> > ft.getReturnType(); ft.getParameterTypes(); // or similar
>
> But I don't see any simplification. getParameterTypes()
> returns IType s This is just the same as in my code that
> applies "getType()" to the parameters.
>
> IVariable argCount = (IVariable)argCountParam.resolveBinding();
> String argcType = ASTTypeUtil.getType(argCount.getType());
> if(!"int".equals(argcType))
> status.addFatalError("First parameter of 'main'
> function is expected to be of type 'int'.");
>
> With your proposition I still need ASTTypeUtil.getType(...)
> to generate a String representation of the IType and compare
> to what I want to see. Your code even needs the same
> exceptions to be handled.
> Is there any simpler way like
>
> MagicTypeUtil.compare(argCount.getType(), IType.type_int);
>
> Mit freundlichen Grüßen / Best regards
>
> Dr. Nils Hagge
> Projektleiter Vorfeld
>
> Siemens AG
> Industry Sector, I IA&DT ATS 13
> Telefon +49 911 895-3484
> Telefax +49 911 895-153484
> mailto:nils.hagge@xxxxxxxxxxx
> http://www.siemens.com/automation
>
> Siemens Aktiengesellschaft: Chairman of the Supervisory
> Board: Gerhard Cromme Managing Board: Peter Loescher,
> Chairman, President and Chief Executive Officer; Wolfgang
> Dehen, Heinrich Hiesinger, Joe Kaeser, Jim Reid-Anderson,
> Hermann Requardt, Siegfried Russwurm, Peter Y. Solmssen
> Registered offices: Berlin and Munich; Commercial registries:
> Berlin Charlottenburg, HRB 12300, Munich, HRB 6684
> WEEE-Reg.-No. DE 23691322
>
> -----Ursprüngliche Nachricht-----
> Von: cdt-dev-bounces@xxxxxxxxxxx
> [mailto:cdt-dev-bounces@xxxxxxxxxxx] Im Auftrag von Schorn, Markus
> Gesendet: Mittwoch, 20. Januar 2010 10:01
> An: CDT General developers list.
> Be_______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
>