Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-07

How do I tell codetools to use implicitly loaded unit for code complesion?

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Ring

On embedded targets a unit with the definition of the target (Registers, Interrupts, etc..) is implicitly loaded when fpc compiles the code.

Because of this Codetools does not seem to know about the definitions inside of this specific unit and code completion does not work.

When I implicitly add the unit to the uses line of my program then code completion works just fine but I cannot compile the code because I get a 'Duplicate identifier' error because the unit is first implicitly loaded and then loaded again because it is part of uses

Is there a way that I can give a hint to codetools to also use this unit for code competion?

Thank you,

Michael

Example:

program hello;
uses
   pic32mx795f512h;

gives me code completion for all definitions made in pic32mx795f512h, but when I compile the program I get the following error:

Compile Project: Exit code 1, Errors:2, Hints:1
hello.pas(3,18) Error: Duplicate identifier "PIC32MX795F512H"
hello.pas(3,18) Error: Duplicate identifier "PIC32MX795F512H"
hello.pas(3,18) Hint: Identifier already defined in unit HELLO at line 2
Mattias Gaertner
to Michael Ring
Show quoted text 7 lines
[...] Is there a way that I can give a hint to codetools to also use this unit for code competion? program hello; uses pic32mx795f512h;

Codetools have built in rules to determine the auto used units (see TLinkScanner.GetHiddenUsedUnits).
The pic32mx795f512h needs to be added.
When is it used?
What fpc version, target OS, target CPU, options enables this unit?

Mattias

Michael Ring
to Mattias Gaertner

Hi Mattias, unfortunately I did not see your answer back in July.

I did some digging myself and found GetHiddenUsedUnits.

The rule to make loading happen is that target os is "embedded" fpc version >= 2.7.1 and the value of the option -Wp determines which unit to load.

Example: -Wppic32mx795f512h

should load unit pic32mx795f512h

to make life a (very little) harder the fully correct rule for selecting the right unit is:

search for uppercase(-WpVALUE) in array embeddedcontrollers (defined in [arm,mipsel,avr]/cpuinfo.pas) and load the unit with name defined in the field controllerunitstr

Is something like this doable?

I already hardcoded the unit for my testing purposes (Works fine), but failed to find a way to get the value of the -Wp switch in GetHiddenUsedUnits.

Michael

Mattias Gaertner wrote 23 lines
On Sat, 05 Jul 2014 17:03:55 +0200 Michael Ring wrote: > [...] > Is there a way that I can give a hint to codetools to also use this unit > for code competion? > > program hello; > uses > pic32mx795f512h; Codetools have built in rules to determine the auto used units (see TLinkScanner.GetHiddenUsedUnits). The pic32mx795f512h needs to be added. When is it used? What fpc version, target OS, target CPU, options enables this unit? Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Mattias Gaertner
to Michael Ring
Show quoted text 6 lines
Michael Ring hat am 21. Oktober 2014 um 22:27 geschrieben: [...] Example: -Wppic32mx795f512h should load unit pic32mx795f512h

The IDE already does that.
Search for MacroControllerUnit.

Show quoted text 8 lines
to make life a (very little) harder the fully correct rule for selecting the right unit is: search for uppercase(-WpVALUE) in array embeddedcontrollers (defined in [arm,mipsel,avr]/cpuinfo.pas) and load the unit with name defined in the field controllerunitstr Is something like this doable?

Theoretically yes. Is that needed?

I already hardcoded the unit for my testing purposes (Works fine), but failed to find a way to get the value of the -Wp switch in GetHiddenUsedUnits.

Mattias

Michael Ring
to Mattias Gaertner

Thank you for the hint on macros, I will see if I can come up with a patch.

The lookup of the controllerunitstr looks like the 'right' solution, for my purposes it would be enough to simply add the value of -Wp, but this would only help for mipsel target, for arm there usually exists a mapping from the controller model to a more generalized unit.

How do you import definitions like those, do you duplicate the code from fpc or do you use the units provided by fpc?

If you duplicate the code it is perhaps better to also make the unit files match the controller names in fpc so that the list of controllers does not need to get implemented in both fpc and lazarus.

Michael

Mattias Gaertner wrote 31 lines
> Michael Ring hat am 21. Oktober 2014 um 22:27 > geschrieben: > [...] > Example: -Wppic32mx795f512h > > should load unit pic32mx795f512h The IDE already does that. Search for MacroControllerUnit. > to make life a (very little) harder the fully correct rule for selecting > the right unit is: > > search for uppercase(-WpVALUE) in array embeddedcontrollers (defined in > [arm,mipsel,avr]/cpuinfo.pas) and load the unit with name defined in the > field controllerunitstr > > Is something like this doable? Theoretically yes. Is that needed? > I already hardcoded the unit for my testing purposes (Works fine), but > failed to find a way to get the value of the -Wp switch in > GetHiddenUsedUnits. Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Michael Ring
to Michael Ring

OK, I found out what is going on.

FindControllerUnit in components/codetools/definetemplates.pas already contains a copy of the arm version of cpuinfo.pas but it does not include the mips version of cpuinfo.pas.

so FindControllerUnit does not find a match and returns an empty string -> the Value of -Wp get discarded.

I have attached a patch that adds the missing definitions for mipsel.

Please note that the definitions differ from the ones in trunk; I have asked sergej to merge my latest changes for mipsel but he did not yet find the time to do so.

So trunk is outdated and it makes no sense to use the definitions currently available there.

Michael

Michael Ring wrote 58 lines
Thank you for the hint on macros, I will see if I can come up with a patch. The lookup of the controllerunitstr looks like the 'right' solution, for my purposes it would be enough to simply add the value of -Wp, but this would only help for mipsel target, for arm there usually exists a mapping from the controller model to a more generalized unit. How do you import definitions like those, do you duplicate the code from fpc or do you use the units provided by fpc? If you duplicate the code it is perhaps better to also make the unit files match the controller names in fpc so that the list of controllers does not need to get implemented in both fpc and lazarus. Michael Am 21.10.14 um 23:28 schrieb Mattias Gaertner: > >> Michael Ring hat am 21. Oktober 2014 um 22:27 >> geschrieben: >> [...] >> Example: -Wppic32mx795f512h >> >> should load unit pic32mx795f512h > The IDE already does that. > Search for MacroControllerUnit. > >> to make life a (very little) harder the fully correct rule for >> selecting >> the right unit is: >> >> search for uppercase(-WpVALUE) in array embeddedcontrollers (defined in >> [arm,mipsel,avr]/cpuinfo.pas) and load the unit with name defined in >> the >> field controllerunitstr >> >> Is something like this doable? > Theoretically yes. Is that needed? > > >> I already hardcoded the unit for my testing purposes (Works fine), but >> failed to find a way to get the value of the -Wp switch in >> GetHiddenUsedUnits. > Mattias > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
Index: components/codetools/definetemplates.pas
=================================================================== --- components/codetools/definetemplates.pas (revision 46642) +++ components/codetools/definetemplates.pas (working copy) @@ -6618,7 +6618,7 @@

       controllerunitstr: string[20];
     end;
   const

- ControllerTypes: array[0..211] of TControllerType =
+ ControllerTypes: array[0..302] of TControllerType = ((controllertypestr:''; controllerunitstr:''), (controllertypestr:'LPC810M021FN8'; controllerunitstr:'LPC8xx'), (controllertypestr:'LPC811M001FDH16'; controllerunitstr:'LPC8xx'), @@ -6830,7 +6830,99 @@
(controllertypestr:'XMC4500X768'; controllerunitstr:'XMC4500'), (controllertypestr:'XMC4502X768'; controllerunitstr:'XMC4502'), (controllertypestr:'XMC4504X512'; controllerunitstr:'XMC4504'),
- (controllertypestr:'THUMB2_BARE'; controllerunitstr:'THUMB2_BARE'));
+ (controllertypestr:'THUMB2_BARE'; controllerunitstr:'THUMB2_BARE'),
+ (controllertypestr:'PIC32MX110F016B'; controllerunitstr:'PIC32MX110F016B'),
+ (controllertypestr:'PIC32MX110F016C'; controllerunitstr:'PIC32MX110F016C'),
+ (controllertypestr:'PIC32MX110F016D'; controllerunitstr:'PIC32MX110F016D'),
+ (controllertypestr:'PIC32MX120F032B'; controllerunitstr:'PIC32MX120F032B'),
+ (controllertypestr:'PIC32MX120F032C'; controllerunitstr:'PIC32MX120F032C'),
+ (controllertypestr:'PIC32MX120F032D'; controllerunitstr:'PIC32MX120F032D'),
+ (controllertypestr:'PIC32MX130F064B'; controllerunitstr:'PIC32MX130F064B'),
+ (controllertypestr:'PIC32MX130F064C'; controllerunitstr:'PIC32MX130F064C'),
+ (controllertypestr:'PIC32MX130F064D'; controllerunitstr:'PIC32MX130F064D'),
+ (controllertypestr:'PIC32MX150F128B'; controllerunitstr:'PIC32MX150F128B'),
+ (controllertypestr:'PIC32MX150F128C'; controllerunitstr:'PIC32MX150F128C'),
+ (controllertypestr:'PIC32MX150F128D'; controllerunitstr:'PIC32MX150F128D'),
+ (controllertypestr:'PIC32MX170F256B'; controllerunitstr:'PIC32MX170F256B'),
+ (controllertypestr:'PIC32MX170F256C'; controllerunitstr:'PIC32MX170F256C'),
+ (controllertypestr:'PIC32MX170F256D'; controllerunitstr:'PIC32MX170F256D'),
+ (controllertypestr:'PIC32MX210F016B'; controllerunitstr:'PIC32MX210F016B'),
+ (controllertypestr:'PIC32MX210F016C'; controllerunitstr:'PIC32MX210F016C'),
+ (controllertypestr:'PIC32MX210F016D'; controllerunitstr:'PIC32MX210F016D'),
+ (controllertypestr:'PIC32MX220F032B'; controllerunitstr:'PIC32MX220F032B'),
+ (controllertypestr:'PIC32MX220F032C'; controllerunitstr:'PIC32MX220F032C'),
+ (controllertypestr:'PIC32MX220F032D'; controllerunitstr:'PIC32MX220F032D'),
+ (controllertypestr:'PIC32MX230F064B'; controllerunitstr:'PIC32MX230F064B'),
+ (controllertypestr:'PIC32MX230F064C'; controllerunitstr:'PIC32MX230F064C'),
+ (controllertypestr:'PIC32MX230F064D'; controllerunitstr:'PIC32MX230F064D'),
+ (controllertypestr:'PIC32MX250F128B'; controllerunitstr:'PIC32MX250F128B'),
+ (controllertypestr:'PIC32MX250F128C'; controllerunitstr:'PIC32MX250F128C'),
+ (controllertypestr:'PIC32MX250F128D'; controllerunitstr:'PIC32MX250F128D'),
+ (controllertypestr:'PIC32MX270F256B'; controllerunitstr:'PIC32MX270F256B'),
+ (controllertypestr:'PIC32MX270F256C'; controllerunitstr:'PIC32MX270F256C'),
+ (controllertypestr:'PIC32MX270F256D'; controllerunitstr:'PIC32MX270F256D'),
+ (controllertypestr:'PIC32MX320F032H'; controllerunitstr:'PIC32MX320F032H'),
+ (controllertypestr:'PIC32MX320F064H'; controllerunitstr:'PIC32MX320F064H'),
+ (controllertypestr:'PIC32MX320F128H'; controllerunitstr:'PIC32MX320F128H'),
+ (controllertypestr:'PIC32MX320F128L'; controllerunitstr:'PIC32MX320F128L'),
+ (controllertypestr:'PIC32MX330F064H'; controllerunitstr:'PIC32MX330F064H'),
+ (controllertypestr:'PIC32MX330F064L'; controllerunitstr:'PIC32MX330F064L'),
+ (controllertypestr:'PIC32MX340F128H'; controllerunitstr:'PIC32MX340F128H'),
+ (controllertypestr:'PIC32MX340F128L'; controllerunitstr:'PIC32MX340F128L'),
+ (controllertypestr:'PIC32MX340F256H'; controllerunitstr:'PIC32MX340F256H'),
+ (controllertypestr:'PIC32MX340F512H'; controllerunitstr:'PIC32MX340F512H'),
+ (controllertypestr:'PIC32MX350F128H'; controllerunitstr:'PIC32MX350F128H'),
+ (controllertypestr:'PIC32MX350F128L'; controllerunitstr:'PIC32MX350F128L'),
+ (controllertypestr:'PIC32MX350F256H'; controllerunitstr:'PIC32MX350F256H'),
+ (controllertypestr:'PIC32MX350F256L'; controllerunitstr:'PIC32MX350F256L'),
+ (controllertypestr:'PIC32MX360F256L'; controllerunitstr:'PIC32MX360F256L'),
+ (controllertypestr:'PIC32MX360F512L'; controllerunitstr:'PIC32MX360F512L'),
+ (controllertypestr:'PIC32MX370F512H'; controllerunitstr:'PIC32MX370F512H'),
+ (controllertypestr:'PIC32MX370F512L'; controllerunitstr:'PIC32MX370F512L'),
+ (controllertypestr:'PIC32MX420F032H'; controllerunitstr:'PIC32MX420F032H'),
+ (controllertypestr:'PIC32MX430F064H'; controllerunitstr:'PIC32MX430F064H'),
+ (controllertypestr:'PIC32MX430F064L'; controllerunitstr:'PIC32MX430F064L'),
+ (controllertypestr:'PIC32MX440F128H'; controllerunitstr:'PIC32MX440F128H'),
+ (controllertypestr:'PIC32MX440F128L'; controllerunitstr:'PIC32MX440F128L'),
+ (controllertypestr:'PIC32MX440F256H'; controllerunitstr:'PIC32MX440F256H'),
+ (controllertypestr:'PIC32MX440F512H'; controllerunitstr:'PIC32MX440F512H'),
+ (controllertypestr:'PIC32MX450F128H'; controllerunitstr:'PIC32MX450F128H'),
+ (controllertypestr:'PIC32MX450F128L'; controllerunitstr:'PIC32MX450F128L'),
+ (controllertypestr:'PIC32MX450F256H'; controllerunitstr:'PIC32MX450F256H'),
+ (controllertypestr:'PIC32MX450F256L'; controllerunitstr:'PIC32MX450F256L'),
+ (controllertypestr:'PIC32MX460F256L'; controllerunitstr:'PIC32MX460F256L'),
+ (controllertypestr:'PIC32MX460F512L'; controllerunitstr:'PIC32MX460F512L'),
+ (controllertypestr:'PIC32MX460F512H'; controllerunitstr:'PIC32MX460F512H'),
+ (controllertypestr:'PIC32MX460F512L'; controllerunitstr:'PIC32MX460F512L'),
+ (controllertypestr:'PIC32MX534F064H'; controllerunitstr:'PIC32MX534F064H'),
+ (controllertypestr:'PIC32MX534F064L'; controllerunitstr:'PIC32MX534F064L'),
+ (controllertypestr:'PIC32MX564F064H'; controllerunitstr:'PIC32MX564F064H'),
+ (controllertypestr:'PIC32MX564F064L'; controllerunitstr:'PIC32MX564F064L'),
+ (controllertypestr:'PIC32MX564F128H'; controllerunitstr:'PIC32MX564F128H'),
+ (controllertypestr:'PIC32MX564F128L'; controllerunitstr:'PIC32MX564F128L'),
+ (controllertypestr:'PIC32MX575F256H'; controllerunitstr:'PIC32MX575F256H'),
+ (controllertypestr:'PIC32MX575F256L'; controllerunitstr:'PIC32MX575F256L'),
+ (controllertypestr:'PIC32MX575F512H'; controllerunitstr:'PIC32MX575F512H'),
+ (controllertypestr:'PIC32MX575F512L'; controllerunitstr:'PIC32MX575F512L'),
+ (controllertypestr:'PIC32MX664F064H'; controllerunitstr:'PIC32MX664F064H'),
+ (controllertypestr:'PIC32MX664F064L'; controllerunitstr:'PIC32MX664F064L'),
+ (controllertypestr:'PIC32MX664F128H'; controllerunitstr:'PIC32MX664F128H'),
+ (controllertypestr:'PIC32MX664F128L'; controllerunitstr:'PIC32MX664F128L'),
+ (controllertypestr:'PIC32MX675F256H'; controllerunitstr:'PIC32MX675F256H'),
+ (controllertypestr:'PIC32MX675F256L'; controllerunitstr:'PIC32MX675F256L'),
+ (controllertypestr:'PIC32MX675F512H'; controllerunitstr:'PIC32MX675F512H'),
+ (controllertypestr:'PIC32MX675F512L'; controllerunitstr:'PIC32MX675F512L'),
+ (controllertypestr:'PIC32MX695F512H'; controllerunitstr:'PIC32MX695F512H'),
+ (controllertypestr:'PIC32MX695F512L'; controllerunitstr:'PIC32MX695F512L'),
+ (controllertypestr:'PIC32MX764F128H'; controllerunitstr:'PIC32MX764F128H'),
+ (controllertypestr:'PIC32MX764F128L'; controllerunitstr:'PIC32MX764F128L'),
+ (controllertypestr:'PIC32MX775F256H'; controllerunitstr:'PIC32MX775F256H'),
+ (controllertypestr:'PIC32MX775F256L'; controllerunitstr:'PIC32MX775F256L'),
+ (controllertypestr:'PIC32MX775F512H'; controllerunitstr:'PIC32MX775F512H'),
+ (controllertypestr:'PIC32MX775F512L'; controllerunitstr:'PIC32MX775F512L'),
+ (controllertypestr:'PIC32MX795F512H'; controllerunitstr:'PIC32MX795F512H'),
+ (controllertypestr:'PIC32MX795F512L'; controllerunitstr:'PIC32MX795F512L')); +

   var
     i: integer;
     str: String;
Mattias Gaertner
to Michael Ring
Michael Ring hat am 22. Oktober 2014 um 22:05 geschrieben: [...] I have attached a patch that adds the missing definitions for mipsel.

Thanks. Applied.

Mattias

Michael Ring
to Mattias Gaertner

Saw it, thank you very much!

One more thing:

I am using record helpers and Codetools does not seem to support them right now, do you have any plans on supporting them some day?

I can workarround this limitation, but this makes the units for the controllers a little more uglier to read.

Michael

Mattias Gaertner wrote 14 lines
> Michael Ring hat am 22. Oktober 2014 um 22:05 > geschrieben: > [...] > I have attached a patch that adds the missing definitions for mipsel. Thanks. Applied. Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus