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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [ParseStructDeclaration.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
extern int bit_next;
32
extern int bit_offset;
33
extern int bit_width;
34
extern int parsingParameterList;
35
extern int funcdecl;
36
extern int isStructDecl;
37
extern bool isPrivate;
38
 
39
int16_t typeno = bt_last;
40
 
41
int StructDeclaration::Parse(int ztype)
42
{
43
  SYM *sp;
44
  TYP *tp;
45
        int ret;
46
        int psd;
47
        ENODE nd;
48
        ENODE *pnd = &nd;
49
 
50
  sp = nullptr;
51
        psd = isStructDecl;
52
        isStructDecl++;
53
        ret = 0;
54
        bit_offset = 0;
55
        bit_next = 0;
56
        bit_width = -1;
57
  if(lastst == id) {
58
    if((sp = tagtable.Find(lastid,false)) == NULL) {
59
      sp = allocSYM();
60
                sp->SetName(*(new std::string(lastid)));
61
      sp->tp = allocTYP();
62
      sp->tp->type = (e_bt)ztype;
63
                  sp->tp->typeno = typeno++;
64
      sp->tp->lst.Clear();
65
      sp->storage_class = sc_type;
66
      sp->tp->sname = new std::string(*sp->name);
67
      sp->tp->alignment = 0;
68
      NextToken();
69
 
70
                        if (lastst == kw_align) {
71
        NextToken();
72
        sp->tp->alignment = (int)GetIntegerExpression(&pnd);
73
      }
74
 
75
                        // Could be a forward structure declaration like:
76
                        // struct buf;
77
                        if (lastst==semicolon) {
78
                                ret = 1;
79
        tagtable.insert(sp);
80
        NextToken();
81
                        }
82
                        // Defining a pointer to an unknown struct ?
83
                        else if (lastst == star) {
84
        tagtable.insert(sp);
85
                        }
86
      else if(lastst != begin)
87
        error(ERR_INCOMPLETE);
88
      else {
89
        tagtable.insert(sp);
90
        NextToken();
91
        ParseMembers(sp, sp->tp,ztype);
92
      }
93
    }
94
    // Else it is a known structure
95
                else {
96
      NextToken();
97
      if (lastst==kw_align) {
98
        NextToken();
99
        sp->tp->alignment = (int)GetIntegerExpression(&pnd);
100
      }
101
                        if (lastst==begin) {
102
        NextToken();
103
        ParseMembers(sp,sp->tp,ztype);
104
                        }
105
                }
106
    head = sp->tp;
107
  }
108
  // Else there was no tag identifier
109
  else {
110
    tp = allocTYP();
111
    tp->type = (e_bt)ztype;
112
          tp->typeno = typeno++;
113
    tp->sname = new std::string("");
114
 
115
    if (lastst==kw_align) {
116
      NextToken();
117
      tp->alignment = (int)GetIntegerExpression(&pnd);
118
    }
119
 
120
    if( lastst != begin)
121
      error(ERR_INCOMPLETE);
122
    else {
123
                        NextToken();
124
                        ParseMembers(sp,tp,ztype);
125
    }
126
    head = tp;
127
  }
128
        isStructDecl = psd;
129
        return ret;
130
}
131
 
132
void StructDeclaration::ParseMembers(SYM *sym, TYP *tp, int ztype)
133
{
134
        int slc;
135
        bool priv;
136
 
137
        slc = 0;
138
        tp->val_flag = 1;
139
        //      tp->val_flag = FALSE;
140
        while( lastst != end) {
141
                priv = isPrivate;
142
                isPrivate = false;
143
                if(ztype == bt_struct || ztype==bt_class)
144
                        slc += declare(sym,&(tp->lst),sc_member,slc,ztype);
145
                else
146
                        slc = imax(slc,declare(sym,&tp->lst,sc_member,0,ztype));
147
                isPrivate = priv;
148
        }
149
        bit_offset = 0;
150
        bit_next = 0;
151
        bit_width = -1;
152
        tp->size = tp->alignment ? tp->alignment : slc;
153
        NextToken();
154
}
155
 

powered by: WebSVN 2.1.0

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