FreeBASIC  0.91.0
parser-quirk-thread.bas
Go to the documentation of this file.
1 '' quick threadcall implementation
2 ''
3 '' chng: oct/2011 written [jofers]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "parser.bi"
8 
9 #include once "ast.bi"
10 #include once "rtl.bi"
11 
12 '':::::
13 '' ThreadCallFunc = THREADCALL proc_call
14 ''
15 function cThreadCallFunc() as ASTNODE ptr
16  dim as FBSYMBOL ptr sym, result
17  dim as FBSYMCHAIN ptr chain_
18  dim as integer check_paren
19  dim as FB_CALL_ARG_LIST arg_list = ( 0, NULL, NULL )
20  dim as ASTNODE ptr childcall
21 
22  function = NULL
23 
24  '' THREADCALL
25  lexSkipToken( )
26 
27  '' proc
28  chain_ = cIdentifier( NULL, FB_IDOPT_DEFAULT or FB_IDOPT_ALLOWSTRUCT )
29  if( chain_ = NULL ) then
30  exit function
31  end if
32 
33  '' get symbol
34  sym = symbFindByClass( chain_, FB_SYMBCLASS_PROC )
35  if sym = NULL then
36  errReport( FB_ERRMSG_EXPECTEDSUB )
37  exit function
38  end if
39 
40  '' must be a sub
41  result = symbGetProcResult( sym )
42  if( result <> NULL ) then
43  if( symbGetType( result ) <> FB_DATATYPE_VOID ) then
44  errReport( FB_ERRMSG_EXPECTEDSUB )
45  exit function
46  end if
47  end if
48 
49  lexSkipToken( )
50 
51  '' '('?
52  if( hMatch( CHAR_LPRNT ) = FALSE ) then
53  dim params as integer
54  params = symbGetProcParams( sym )
55  if( params > 0 ) then
56  errReport( FB_ERRMSG_EXPECTEDLPRNT )
57  exit function
58  end if
59  else
60  check_paren = TRUE
61  end if
62 
63  '' arg_list
64  childcall = cProcArgList( NULL, sym, NULL, @arg_list, 0 )
65 
66  '' ')'?
67  if( check_paren = TRUE ) then
68  if( lexGetToken( ) <> CHAR_RPRNT ) then
69  errReport( FB_ERRMSG_EXPECTEDRPRNT )
70  exit function
71  end if
72  lexSkipToken( )
73  end if
74 
75  '' transform the call into a threadcall
76  function = rtlThreadCall( childcall )
77 end function
78