@@ -509,6 +509,7 @@ DeclareConstants(Module *P, AST **conlist_ptr)
509
509
510
510
switch (ast -> kind ) {
511
511
case AST_ASSIGN :
512
+ {
512
513
if (IsConstExpr (ast -> right )) {
513
514
if (!IsIdentifier (ast -> left )) {
514
515
ERROR (ast , "Internal error, bad constant declaration" );
@@ -522,8 +523,20 @@ DeclareConstants(Module *P, AST **conlist_ptr)
522
523
completed_declarations = AddToList (completed_declarations , upper );
523
524
conlist = * conlist_ptr ;
524
525
} else {
526
+ AST * setExpr = ast -> right ;
527
+ // check for declarations of old constants
528
+ if (IsIdentifier (setExpr )) {
529
+ const char * name = GetIdentifierName (setExpr );
530
+ AST * olddecl = FindDeclaration (current -> datblock , name );
531
+ if (olddecl && olddecl -> kind == AST_DECLARE_VAR && olddecl -> left && IsConstType (olddecl -> left )) {
532
+ AST * assign = olddecl -> right ;
533
+ if (assign && assign -> right ) {
534
+ setExpr = ast -> right = assign -> right ;
535
+ }
536
+ }
537
+ }
525
538
AST * typ ;
526
- typ = ExprType (ast -> right );
539
+ typ = ExprType (setExpr );
527
540
if (typ && (IsStringType (typ ) || IsPointerType (typ ))) {
528
541
if (!IsIdentifier (ast -> left )) {
529
542
ERROR (ast , "Internal error, bad constant declaration" );
@@ -538,6 +551,7 @@ DeclareConstants(Module *P, AST **conlist_ptr)
538
551
}
539
552
}
540
553
break ;
554
+ }
541
555
case AST_ENUMSET :
542
556
if (IsConstExpr (ast -> left )) {
543
557
default_val = EvalConstExpr (ast -> left );
@@ -1727,7 +1741,7 @@ GetExprlistLen(AST *list)
1727
1741
//
1728
1742
// find any previous declaration of name
1729
1743
//
1730
- static AST *
1744
+ AST *
1731
1745
FindDeclaration (AST * datlist , const char * name )
1732
1746
{
1733
1747
AST * ident ;
0 commit comments