Author Topic: Nested struct type...  (Read 3490 times)

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #15 on: October 11, 2017, 01:45:49 am »
Good suggestion, thanks.

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Nested structure definition...
« Reply #16 on: December 07, 2017, 08:14:52 pm »
Here is another example of this...

interestingly, the symbol is highlighted as Unknown, but Preview shows its definition.

Code: [Select]
struct ct_sns_rsp {
struct {
struct ct_hdr header;
uint16_t response;
uint16_t residual;
uint8_t fragment_id;
uint8_t reason_code;
uint8_t explanation_code;
uint8_t vendor_unique;
};

union {
struct ga_nxt {
uint8_t port_type;
uint8_t port_id[3];
uint8_t port_name[8];
uint8_t sym_port_name_len;
uint8_t sym_port_name[255];
uint8_t node_name[8];
uint8_t sym_node_name_len;
uint8_t sym_node_name[255];
uint8_t init_proc_assoc[8];
uint8_t node_ip_addr[16];
uint8_t class_of_service[4];
uint8_t fc4_types[32];
uint8_t ip_address[16];
uint8_t fabric_port_name[8];
uint8_t reserved;
uint8_t hard_address[3];
} ga_nxt;

struct {
/* Assume largest number of targets for union */
struct gid_pt_entry {
uint8_t control_byte;
uint8_t port_id[3];
} entries[MAX_FIBRE_DEVICES_MAX];
} gid_pt;

struct {
/* Assume largest number of targets for union */
struct ct_sns_gpn_ft_data {
u8 control_byte;
u8 port_id[3];
u32 reserved;
u8 port_name[8];
} entries[MAX_FIBRE_DEVICES_MAX];
} gpn_ft;

struct gpn_id {
uint8_t port_name[8];
} gpn_id;

struct gnn_id {
uint8_t node_name[8];
} gnn_id;

struct {
uint8_t fc4_types[32];
} gft_id;

struct {
uint32_t entry_count;
uint8_t port_name[8];
struct ct_fdmi1_hba_attributes attrs;
} ghat;

struct gfpn_id {
uint8_t port_name[8];
} gfpn_id;

struct {
uint16_t speeds;
uint16_t speed;
} gpsc;

struct {
uint8_t fc4_features[128];
} gff_id;

struct {
uint8_t reserved;
uint8_t port_id[3];
} gid_pn;

struct gfo {
uint32_t count;
struct {
uint16_t type;
uint16_t length;
uint8_t value[8];
} name;
struct {
struct {
uint16_t type;
uint16_t length;
uint8_t value[1];
uint8_t unused[3];
} supported;
struct {
uint16_t type;
uint16_t length;
uint8_t value[4];
} range[3];
} priority;
} gfo;
} rsp;
};

Code: [Select]
static inline uint
qla25xx_gfo_priority(struct gfo *gfo, uint index)
{
if (gfo->priority.supported.value[0])
return gfo->priority.range[index].value[1] & 0x7f;

return 0;
}



« Last Edit: December 07, 2017, 08:18:42 pm by joecar »

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #17 on: December 07, 2017, 08:22:44 pm »
I did notice that Preview shows the wrong definition of the sub-member .value...

i.e. Preview shows struct name .value in each of these instances:

   if (gfo->priority.supported.value[0])
             return gfo->priority.range[index].value[1] & 0x7f;


Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2542
  • Hero Points: 373
Re: Nested struct type...
« Reply #18 on: December 07, 2017, 08:48:29 pm »
This will be fixed in the upcoming 22.0.1 maintenance release.

The Preview window tends to go for broke if it can't find a symbol's definition using conventional context tagging, it will just display any symbol with a matching name if all else fails.  It's better than nothing and can be helpful, but knowing that, you have to take what it shows with a grain of salt.  It corresponds with the results you might get if you do a Ctrl+Dot on the same symbol, the tagging engine will try to resolve the symbol using Context Tagging, but if the intelligent stuff fails, it falls back to just finding something with a name that matches.

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #19 on: December 08, 2017, 07:55:06 pm »
Ok, thanks.

Thanks for the Preview insight.

 ;)

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #20 on: December 12, 2017, 06:05:06 pm »
Also, here is a possibly related example using typeof (gcc)...

p, declared using typeof, is highlighted as Unknown:






Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2542
  • Hero Points: 373
Re: Nested struct type...
« Reply #21 on: December 13, 2017, 12:39:30 am »
I plan to add full support for the typeof() keyword for a future release, even though it is a GNU extension.  The C++11 keyword is decltype().

If you set up your C/C++ Preprocessing to map "typeof(x)" to "decltype(x)", that should solve this case for you.

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #22 on: December 13, 2017, 06:04:43 pm »
Ok.  Thanks for the hint.

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #23 on: January 15, 2018, 04:30:43 pm »
With hotfix_se2201_2_cumulative I still see this...

( usage of nested struct is marked unknown (see yellow highlight) )

« Last Edit: January 15, 2018, 04:37:55 pm by joecar »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2542
  • Hero Points: 373
Re: Nested struct type...
« Reply #24 on: January 17, 2018, 04:57:54 pm »
As far as I can see, that looks correct for C++.  Is this ANSI-C header file?  What do you have the ".h" extension configured to parse as (C/C++ or ANSI-C)?  Does "qos_fcport_table_array" get colored correctly if you switch the language mode to ANSI-C (Document > Select Mode...)?

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #25 on: January 17, 2018, 06:04:17 pm »
I'm using GNU C, so I had set this workspace/project to C/C++.

When I set the document mode to ANSI-C, the unknown highlighting stops.

This is a linux kernel driver (and kernel allows various GCC C extensions), so which mode should I be using...?

Thanks.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2542
  • Hero Points: 373
Re: Nested struct type...
« Reply #26 on: January 17, 2018, 06:08:09 pm »
Do a Select Mode... > ANSI-C for that file (and any other GNU C kernel header file with similar problems).

You could also use Tools > Options > Languages > Advanced File Mappings to map ".h" files in the directory containing your GNU C kernel headers files to ANSI-C Language mode.


joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #27 on: January 19, 2018, 06:40:37 pm »
What are the differences between the document modes "C/C++" and "ANSI-C".

Since the source code I'm working on uses GCC and GCC extensions, am I losing anything by setting the mode to ANSI-C...?

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2542
  • Hero Points: 373
Re: Nested struct type...
« Reply #28 on: January 19, 2018, 06:45:59 pm »
ANSI-C doesn't recognize classes, templates, basically everything C++.  Also, ANSI-C handles scoping for nested structs by ANSI-C rules, not C++ rules.

If your code is straight C, and not clean enough to just be parsed as if it were C++, like the Linux kernel headers, then you want to use the ANSI-C document mode for those files.

Most other things are the same with respect to syntax expansion and smart editing and tagging.

joecar

  • Senior Community Member
  • Posts: 208
  • Hero Points: 8
  • engineer/gearhead
Re: Nested struct type...
« Reply #29 on: January 23, 2018, 12:20:31 am »
Yes, the code I'm working on is in the linux kernel (C11 with GNU extensions).

Thanks.