FreeBASIC  0.91.0
ast-node-var.bas
Go to the documentation of this file.
1 '' AST variable access nodes
2 
3 #include once "fbint.bi"
4 #include once "ast.bi"
5 #include once "ir.bi"
6 
7 function astNewVAR _
8  ( _
9  byval sym as FBSYMBOL ptr, _
10  byval ofs as longint, _
11  byval dtype as integer, _
12  byval subtype as FBSYMBOL ptr _
13  ) as ASTNODE ptr
14 
15  dim as ASTNODE ptr n = any
16 
17  if( dtype = FB_DATATYPE_INVALID ) then
18  select case( symbGetClass( sym ) )
19  case FB_SYMBCLASS_LABEL
20  dtype = FB_DATATYPE_VOID
21  subtype = NULL
22  case FB_SYMBCLASS_PROC
23  dtype = FB_DATATYPE_FUNCTION
24  if( symbGetIsFuncPtr( sym ) ) then
25  subtype = sym
26  else
27  subtype = symbAddProcPtrFromFunction( sym )
28  end if
29  case else
30  dtype = symbGetFullType( sym )
31  subtype = symbGetSubtype( sym )
32  end select
33  end if
34 
35  '' alloc new node
36  n = astNewNode( AST_NODECLASS_VAR, dtype, subtype )
37 
38  if( sym ) then
39  if( symbIsVar( sym ) and symbIsTemp( sym ) ) then
40  astDtorListAddRef( sym )
41  end if
42  end if
43 
44  n->sym = sym
45  n->var_.ofs = ofs
46 
47  function = n
48 end function
49 
50 function astLoadVAR( byval n as ASTNODE ptr ) as IRVREG ptr
51  dim as FBSYMBOL ptr s = any
52  dim as longint ofs = any
53  dim as IRVREG ptr vr = NULL
54 
55  s = n->sym
56  ofs = n->var_.ofs
57  if( s <> NULL ) then
58  symbSetIsAccessed( s )
59  ofs += symbGetOfs( s )
60  end if
61 
62  if( ast.doemit ) then
63  vr = irAllocVRVAR( astGetDataType( n ), n->subtype, s, ofs )
64  vr->vector = n->vector
65  end if
66 
67  function = vr
68 end function
69