@@ -564,8 +564,29 @@ var_type: simple_type
564
564
$$.type_index = mm_strdup("-1");
565
565
$$.type_sizeof = NULL;
566
566
}
567
- | ECPGColLabelCommon '(' precision opt_scale ')'
567
+ | NUMERIC '(' precision opt_scale ')'
568
568
{
569
+ $$.type_enum = ECPGt_numeric;
570
+ $$.type_str = mm_strdup("numeric");
571
+ $$.type_dimension = mm_strdup("-1");
572
+ $$.type_index = mm_strdup("-1");
573
+ $$.type_sizeof = NULL;
574
+ }
575
+ | DECIMAL_P '(' precision opt_scale ')'
576
+ {
577
+ $$.type_enum = ECPGt_decimal;
578
+ $$.type_str = mm_strdup("decimal");
579
+ $$.type_dimension = mm_strdup("-1");
580
+ $$.type_index = mm_strdup("-1");
581
+ $$.type_sizeof = NULL;
582
+ }
583
+ | IDENT '(' precision opt_scale ')'
584
+ {
585
+ /*
586
+ * In C parsing mode, NUMERIC and DECIMAL are not keywords, so
587
+ * they will show up here as a plain identifier, and we need
588
+ * this duplicate code to recognize them.
589
+ */
569
590
if (strcmp($1, "numeric") == 0)
570
591
{
571
592
$$.type_enum = ECPGt_numeric;
@@ -587,15 +608,98 @@ var_type: simple_type
587
608
$$.type_index = mm_strdup("-1");
588
609
$$.type_sizeof = NULL;
589
610
}
590
- | ECPGColLabelCommon ecpg_interval
611
+ | VARCHAR
591
612
{
592
- if (strlen($2) != 0 && strcmp ($1, "datetime") != 0 && strcmp ($1, "interval") != 0)
593
- mmerror (PARSE_ERROR, ET_ERROR, "interval specification not allowed here");
613
+ $$.type_enum = ECPGt_varchar;
614
+ $$.type_str = EMPTY; /*mm_strdup("varchar");*/
615
+ $$.type_dimension = mm_strdup("-1");
616
+ $$.type_index = mm_strdup("-1");
617
+ $$.type_sizeof = NULL;
618
+ }
619
+ | FLOAT_P
620
+ {
621
+ /* Note: DOUBLE is handled in simple_type */
622
+ $$.type_enum = ECPGt_float;
623
+ $$.type_str = mm_strdup("float");
624
+ $$.type_dimension = mm_strdup("-1");
625
+ $$.type_index = mm_strdup("-1");
626
+ $$.type_sizeof = NULL;
627
+ }
628
+ | NUMERIC
629
+ {
630
+ $$.type_enum = ECPGt_numeric;
631
+ $$.type_str = mm_strdup("numeric");
632
+ $$.type_dimension = mm_strdup("-1");
633
+ $$.type_index = mm_strdup("-1");
634
+ $$.type_sizeof = NULL;
635
+ }
636
+ | DECIMAL_P
637
+ {
638
+ $$.type_enum = ECPGt_decimal;
639
+ $$.type_str = mm_strdup("decimal");
640
+ $$.type_dimension = mm_strdup("-1");
641
+ $$.type_index = mm_strdup("-1");
642
+ $$.type_sizeof = NULL;
643
+ }
644
+ | TIMESTAMP
645
+ {
646
+ $$.type_enum = ECPGt_timestamp;
647
+ $$.type_str = mm_strdup("timestamp");
648
+ $$.type_dimension = mm_strdup("-1");
649
+ $$.type_index = mm_strdup("-1");
650
+ $$.type_sizeof = NULL;
651
+ }
652
+ | INTERVAL ecpg_interval
653
+ {
654
+ $$.type_enum = ECPGt_interval;
655
+ $$.type_str = mm_strdup("interval");
656
+ $$.type_dimension = mm_strdup("-1");
657
+ $$.type_index = mm_strdup("-1");
658
+ $$.type_sizeof = NULL;
659
+ }
660
+ | STRING
661
+ {
662
+ if (INFORMIX_MODE)
663
+ {
664
+ /* In Informix mode, "string" is automatically a typedef */
665
+ $$.type_enum = ECPGt_string;
666
+ $$.type_str = mm_strdup("char");
667
+ $$.type_dimension = mm_strdup("-1");
668
+ $$.type_index = mm_strdup("-1");
669
+ $$.type_sizeof = NULL;
670
+ }
671
+ else
672
+ {
673
+ /* Otherwise, legal only if user typedef'ed it */
674
+ struct typedefs *this = get_typedef("string", false);
675
+
676
+ $$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? EMPTY : mm_strdup(this->name);
677
+ $$.type_enum = this->type->type_enum;
678
+ $$.type_dimension = this->type->type_dimension;
679
+ $$.type_index = this->type->type_index;
680
+ if (this->type->type_sizeof && strlen(this->type->type_sizeof) != 0)
681
+ $$.type_sizeof = this->type->type_sizeof;
682
+ else
683
+ $$.type_sizeof = cat_str(3, mm_strdup("sizeof("), mm_strdup(this->name), mm_strdup(")"));
594
684
685
+ struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
686
+ }
687
+ }
688
+ | IDENT ecpg_interval
689
+ {
595
690
/*
596
- * Check for type names that the SQL grammar treats as
597
- * unreserved keywords
691
+ * In C parsing mode, the above SQL type names are not keywords,
692
+ * so they will show up here as a plain identifier, and we need
693
+ * this duplicate code to recognize them.
694
+ *
695
+ * Note that we also handle the type names bytea, date, and
696
+ * datetime here, but not above because those are not currently
697
+ * SQL keywords. If they ever become so, they must gain duplicate
698
+ * productions above.
598
699
*/
700
+ if (strlen($2) != 0 && strcmp ($1, "datetime") != 0 && strcmp ($1, "interval") != 0)
701
+ mmerror (PARSE_ERROR, ET_ERROR, "interval specification not allowed here");
702
+
599
703
if (strcmp($1, "varchar") == 0)
600
704
{
601
705
$$.type_enum = ECPGt_varchar;
@@ -686,45 +790,8 @@ var_type: simple_type
686
790
}
687
791
else
688
792
{
689
- /* this is for typedef'ed types */
690
- struct typedefs *this = get_typedef($1);
691
-
692
- $$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? EMPTY : mm_strdup(this->name);
693
- $$.type_enum = this->type->type_enum;
694
- $$.type_dimension = this->type->type_dimension;
695
- $$.type_index = this->type->type_index;
696
- if (this->type->type_sizeof && strlen(this->type->type_sizeof) != 0)
697
- $$.type_sizeof = this->type->type_sizeof;
698
- else
699
- $$.type_sizeof = cat_str(3, mm_strdup("sizeof("), mm_strdup(this->name), mm_strdup(")"));
700
-
701
- struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
702
- }
703
- }
704
- | STRING
705
- {
706
- /*
707
- * It's quite horrid that ECPGColLabelCommon excludes
708
- * unreserved_keyword, meaning that unreserved keywords can't be
709
- * used as type names in var_type. However, this is hard to avoid
710
- * since what follows ecpgstart can be either a random SQL
711
- * statement or an ECPGVarDeclaration (beginning with var_type).
712
- * Pending a bright idea about how to fix that, we must
713
- * special-case STRING (and any other unreserved keywords that are
714
- * likely to be needed here).
715
- */
716
- if (INFORMIX_MODE)
717
- {
718
- $$.type_enum = ECPGt_string;
719
- $$.type_str = mm_strdup("char");
720
- $$.type_dimension = mm_strdup("-1");
721
- $$.type_index = mm_strdup("-1");
722
- $$.type_sizeof = NULL;
723
- }
724
- else
725
- {
726
- /* this is for typedef'ed types */
727
- struct typedefs *this = get_typedef("string");
793
+ /* Otherwise, it must be a user-defined typedef name */
794
+ struct typedefs *this = get_typedef($1, false);
728
795
729
796
$$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? EMPTY : mm_strdup(this->name);
730
797
$$.type_enum = this->type->type_enum;
@@ -751,7 +818,7 @@ var_type: simple_type
751
818
{
752
819
/* No */
753
820
754
- this = get_typedef(name);
821
+ this = get_typedef(name, false );
755
822
$$.type_str = mm_strdup(this->name);
756
823
$$.type_enum = this->type->type_enum;
757
824
$$.type_dimension = this->type->type_dimension;
@@ -1657,17 +1724,14 @@ ColLabel: ECPGColLabel { $$ = $1; }
1657
1724
| ECPGunreserved_interval { $$ = $1; }
1658
1725
;
1659
1726
1660
- ECPGColLabel: ECPGColLabelCommon { $$ = $1; }
1727
+ ECPGColLabel: ecpg_ident { $$ = $1; }
1661
1728
| unreserved_keyword { $$ = $1; }
1662
- | reserved_keyword { $$ = $1; }
1663
- | ECPGKeywords_rest { $$ = $1; }
1664
- | CONNECTION { $$ = mm_strdup("connection"); }
1665
- ;
1666
-
1667
- ECPGColLabelCommon: ecpg_ident { $$ = $1; }
1668
1729
| col_name_keyword { $$ = $1; }
1669
1730
| type_func_name_keyword { $$ = $1; }
1731
+ | reserved_keyword { $$ = $1; }
1670
1732
| ECPGKeywords_vanames { $$ = $1; }
1733
+ | ECPGKeywords_rest { $$ = $1; }
1734
+ | CONNECTION { $$ = mm_strdup("connection"); }
1671
1735
;
1672
1736
1673
1737
ECPGCKeywords: S_AUTO { $$ = mm_strdup("auto"); }
0 commit comments