FreeBASIC  0.91.0
parser-compound-extern.bas
Go to the documentation of this file.
1 '' EXTERN..END EXTERN compound statement parsing
2 ''
3 '' chng: may/2006 written [v1ctor]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "parser.bi"
8 
9 '' ExternStmtBegin = EXTERN "mangling_spec" (LIB LITSTR)? .
11  dim as FB_CMPSTMTSTK ptr stk = any
12  dim as integer mangling = any
13  dim as const zstring ptr litstr = any
14 
15  if( fbLangOptIsSet( FB_LANG_OPT_EXTERN ) = FALSE ) then
16  errReportNotAllowed( FB_LANG_OPT_EXTERN )
17  '' error recovery: skip the whole compound stmt
18  hSkipCompound( FB_TK_EXTERN )
19  exit sub
20  end if
21 
22  if( cCompStmtIsAllowed( FB_CMPSTMT_MASK_EXTERN ) = FALSE ) then
23  '' error recovery: skip the whole compound stmt
24  hSkipCompound( FB_TK_EXTERN )
25  exit sub
26  end if
27 
28  '' EXTERN
29  lexSkipToken( )
30 
31  '' "mangling spec"
32  if( lexGetClass( ) <> FB_TKCLASS_STRLITERAL ) then
33  errReport( FB_ERRMSG_SYNTAXERROR )
34  '' error recovery: assume it's "C"
35  litstr = @"c"
36  else
37  litstr = lexGetText( )
38  end if
39 
40  select case lcase( *litstr )
41  case "c"
42  mangling = FB_MANGLING_CDECL
43  lexSkipToken( )
44 
45  case "windows"
46  mangling = FB_MANGLING_STDCALL
47  lexSkipToken( )
48 
49  case "windows-ms"
50  mangling = FB_MANGLING_STDCALL_MS
51  lexSkipToken( )
52 
53  case "c++"
54  mangling = FB_MANGLING_CPP
55  lexSkipToken( )
56 
57  case else
58  errReport( FB_ERRMSG_SYNTAXERROR )
59  '' error recovery: assume it's "C"
60  mangling = FB_MANGLING_CDECL
61  lexSkipToken( )
62 
63  end select
64 
65  '' [LIB "string"]
67 
68  stk = cCompStmtPush( FB_TK_EXTERN, _
69  FB_CMPSTMT_MASK_ALL and (not FB_CMPSTMT_MASK_CODE) _
70  and (not FB_CMPSTMT_MASK_DATA) )
71 
72  stk->ext.lastmang = parser.mangling
73  parser.mangling = mangling
74 end sub
75 
76 '' ExternStmtEnd = END EXTERN .
78  dim as FB_CMPSTMTSTK ptr stk = any
79 
80  stk = cCompStmtGetTOS( FB_TK_EXTERN )
81  if( stk = NULL ) then
82  hSkipStmt( )
83  exit sub
84  end if
85 
86  '' END EXTERN
87  lexSkipToken( )
88  lexSkipToken( )
89 
90  '' pop from stmt stack
91  parser.mangling = stk->ext.lastmang
92  cCompStmtPop( stk )
93 end sub
94