Diff of /c2iec.y [77aa95] .. [bdceba]  Maximize  Restore

Switch to unified view

a/c2iec.y b/c2iec.y
...
...
59
void fifo_tag(fifo_entry_t type);
59
void fifo_tag(fifo_entry_t type);
60
60
61
// map c datatype to iec (standard and userdefined)
61
// map c datatype to iec (standard and userdefined)
62
char *maptype(char *ctype);
62
char *maptype(char *ctype);
63
63
64
// get identifier from payload data
65
// when used e.g. with the declarator of a struct,
66
// the name is reproducable
67
char *genIdentifier(char *szData);
68
69
// convert input string to upper case
70
char *strUpper(char *szStr);
71
64
// lex/yacc functions
72
// lex/yacc functions
65
extern int yylex (void);
73
extern int yylex (void);
66
%}
74
%}
67
75
68
%%
76
%%
...
...
316
    ;
324
    ;
317
325
318
struct_or_union_specifier
326
struct_or_union_specifier
319
    : struct_or_union IDENTIFIER '{' struct_declaration_list '}'
327
    : struct_or_union IDENTIFIER '{' struct_declaration_list '}'
320
    {
328
    {
321
        printf("TYPE %s:\nSTRUCT\n %s\nEND_STRUCT\nEND_TYPE\n", $<str>2, $<str>4);
329
        printf("TYPE %s:\n%s\n %s\nEND_STRUCT\nEND_TYPE\n\n", $<str>2, strUpper($<str>1), $<str>4);
322
        strcpy($<str>$, "");
330
        strcpy($<str>$, $<str>2);
323
    }
331
    }
324
    | struct_or_union '{' struct_declaration_list '}'
332
    | struct_or_union '{' struct_declaration_list '}'
333
    {
334
        char *szTypeName = genIdentifier($<str>3);
335
        printf("TYPE %s:\n%s\n %s\nEND_STRUCT\nEND_TYPE\n\n", szTypeName, strUpper($<str>1), $<str>3);
336
        strcpy($<str>$, szTypeName);
337
    }
325
    | struct_or_union IDENTIFIER
338
    | struct_or_union IDENTIFIER
326
    ;
339
    ;
327
340
328
struct_or_union
341
struct_or_union
329
    : STRUCT
342
    : STRUCT
...
...
741
        return "ULINT";
754
        return "ULINT";
742
    if (!strcmp(ctype, "struct"))
755
    if (!strcmp(ctype, "struct"))
743
        return "STRUCT";
756
        return "STRUCT";
744
    if (!strcmp(ctype, ""))
757
    if (!strcmp(ctype, ""))
745
        return "";
758
        return "";
746
    printf("maptype: not found: %s\n", ctype);
759
//  printf("maptype: not found: %s\n", ctype);
747
    return ctype;
760
    return ctype;
748
}
761
}
749
762
763
unsigned int genCRC(char *szData)
764
{
765
    char *p;
766
    unsigned int i;
767
    unsigned int v;
768
    unsigned int crc;
769
770
    i = 0;
771
    crc = 42; // start value
772
    p = szData;
773
    while (*p != 0)
774
    {
775
        v = crc & 0xf8000000;
776
        crc = crc << 5;
777
        crc = crc ^ (v >> 27);
778
        crc ^= i;
779
        i++;
780
        p++;
781
    }
782
    return crc;
783
}
784
785
char *genIdentifier(char *szData)
786
{
787
    static char szId[8];
788
    unsigned int crc;
789
    crc = genCRC(szData);
790
    sprintf(szId, "Id%u", crc);
791
    return szId;
792
}
793
794
char *strUpper(char *szStr)
795
{
796
    char *p;
797
    p = szStr;
798
    while (*p != 0)
799
    {
800
        if (*p >= 'a' && *p <= 'z')
801
            *p = *p - ('a' - 'A');
802
        p++;
803
    }
804
    return szStr;
805
}