OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [ParseEnumDeclaration.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
extern TABLE tagtable;
29
extern TYP *head;
30
extern TYP stdconst;
31
 
32
void enumbody(TABLE *table);
33
void ParseEnumerationList(TABLE *table, int amt);
34
 
35
void ParseEnumDeclaration(TABLE *table)
36
{
37
        SYM *sp;
38
    TYP     *tp;
39
        int amt = 1;
40
 
41
    if( lastst == id) {
42
        if((sp = search(lastid,&tagtable)) == NULL) {
43
            sp = allocSYM();
44
            sp->tp = TYP::Make(bt_enum,1);
45
            sp->storage_class = sc_type;
46
            sp->SetName(*(new std::string(lastid)));
47
            sp->tp->sname = new std::string(*sp->name);
48
            NextToken();
49
            if( lastst != begin)
50
                    error(ERR_INCOMPLETE);
51
            else {
52
                                tagtable.insert(sp);
53
                                NextToken();
54
                                ParseEnumerationList(table,amt);
55
            }
56
        }
57
        else
58
            NextToken();
59
        head = sp->tp;
60
    }
61
    else {
62
        tp = allocTYP();        // fix here
63
        tp->type = bt_enum;
64
                tp->size = 2;
65
                if (lastst==openpa) {
66
                        NextToken();
67
                        amt = (int)GetIntegerExpression((ENODE **)NULL);
68
                        needpunc(closepa,10);
69
                }
70
        if( lastst != begin)
71
            error(ERR_INCOMPLETE);
72
        else {
73
            NextToken();
74
            ParseEnumerationList(table,amt);
75
        }
76
    head = tp;
77
    }
78
}
79
 
80
void ParseEnumerationList(TABLE *table, int amt)
81
{
82
        int     evalue;
83
    SYM     *sp;
84
    evalue = 0;
85
    while(lastst == id) {
86
        sp = allocSYM();
87
        sp->SetName(*(new std::string(lastid)));
88
        sp->storage_class = sc_const;
89
        sp->tp = &stdconst;
90
        table->insert(sp);
91
        NextToken();
92
                if (lastst==assign) {
93
                        NextToken();
94
                        sp->value.i = GetIntegerExpression((ENODE **)NULL);
95
                        evalue = (int)sp->value.i+amt;
96
                }
97
                else
98
                        sp->value.i = evalue++;
99
        if( lastst == comma)
100
                NextToken();
101
        else if(lastst != end)
102
                break;
103
    }
104
    needpunc(end,48);
105
}
106
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.