ILParser.jay 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349
  1. %{
  2. //
  3. // Mono::ILASM::ILParser
  4. //
  5. // (C) Sergey Chaban ([email protected])
  6. // (C) 2003 Jackson Harper, All rights reserved
  7. //
  8. using PEAPI;
  9. using System;
  10. using System.IO;
  11. using System.Collections;
  12. using System.Globalization;
  13. using System.Reflection;
  14. using System.Security;
  15. using System.Security.Permissions;
  16. using MIPermission = Mono.ILASM.Permission;
  17. using MIPermissionSet = Mono.ILASM.PermissionSet;
  18. namespace Mono.ILASM {
  19. public class ILParser {
  20. private CodeGen codegen;
  21. private bool is_value_class;
  22. private bool is_enum_class;
  23. private bool pinvoke_info;
  24. private string pinvoke_mod;
  25. private string pinvoke_meth;
  26. private PEAPI.PInvokeAttr pinvoke_attr;
  27. private ILTokenizer tokenizer;
  28. static int yacc_verbose_flag;
  29. class NameValuePair {
  30. public string Name;
  31. public object Value;
  32. public NameValuePair (string name, object value)
  33. {
  34. this.Name = name;
  35. this.Value = value;
  36. }
  37. }
  38. class PermPair {
  39. public PEAPI.SecurityAction sec_action;
  40. public object perm;
  41. public PermPair (PEAPI.SecurityAction sec_action, object perm)
  42. {
  43. this.sec_action = sec_action;
  44. this.perm = perm;
  45. }
  46. }
  47. public bool CheckSecurityActionValidity (System.Security.Permissions.SecurityAction action, bool for_assembly)
  48. {
  49. if ((action == System.Security.Permissions.SecurityAction.RequestMinimum ||
  50. action == System.Security.Permissions.SecurityAction.RequestOptional ||
  51. action == System.Security.Permissions.SecurityAction.RequestRefuse) && !for_assembly) {
  52. Report.Warning (String.Format ("System.Security.Permissions.SecurityAction '{0}' is not valid for this declaration", action));
  53. return false;
  54. }
  55. return true;
  56. }
  57. public void AddSecDecl (object perm, bool for_assembly)
  58. {
  59. PermPair pp = perm as PermPair;
  60. if (pp == null) {
  61. MIPermissionSet ps_20 = (MIPermissionSet) perm;
  62. codegen.AddPermission (ps_20.SecurityAction, ps_20);
  63. return;
  64. }
  65. if (!CheckSecurityActionValidity ((System.Security.Permissions.SecurityAction) pp.sec_action, for_assembly))
  66. Report.Error (String.Format ("Invalid security action : {0}", pp.sec_action));
  67. codegen.AddPermission (pp.sec_action, pp.perm);
  68. }
  69. public object ClassRefToObject (object class_ref, object val)
  70. {
  71. ExternTypeRef etr = class_ref as ExternTypeRef;
  72. if (etr == null)
  73. /* FIXME: report error? can be PrimitiveTypeRef or TypeRef */
  74. return null;
  75. System.Type t = etr.GetReflectedType ();
  76. return (t.IsEnum ? Enum.Parse (t, String.Format ("{0}", val)) : val);
  77. }
  78. /* Converts a type_spec to a corresponding PermPair */
  79. PermPair TypeSpecToPermPair (object action, object type_spec, ArrayList pairs)
  80. {
  81. ExternTypeRef etr = type_spec as ExternTypeRef;
  82. if (etr == null)
  83. /* FIXME: could be PrimitiveTypeRef or TypeRef
  84. Report what error? */
  85. return null;
  86. System.Type t = etr.GetReflectedType ();
  87. object obj = Activator.CreateInstance (t,
  88. new object [] {(System.Security.Permissions.SecurityAction) (short) action});
  89. if (pairs != null)
  90. foreach (NameValuePair pair in pairs) {
  91. PropertyInfo pi = t.GetProperty (pair.Name);
  92. pi.SetValue (obj, pair.Value, null);
  93. }
  94. IPermission iper = (IPermission) t.GetMethod ("CreatePermission").Invoke (obj, null);
  95. return new PermPair ((PEAPI.SecurityAction) action, iper);
  96. }
  97. public ILParser (CodeGen codegen, ILTokenizer tokenizer)
  98. {
  99. this.codegen = codegen;
  100. this.tokenizer = tokenizer;
  101. }
  102. public CodeGen CodeGen {
  103. get { return codegen; }
  104. }
  105. private BaseTypeRef GetTypeRef (BaseTypeRef b)
  106. {
  107. //FIXME: Caching required..
  108. return b.Clone ();
  109. }
  110. %}
  111. %token EOF
  112. /* ID - alpha-numeric identifier */
  113. %token ID
  114. /* QSTRING - quoted string */
  115. %token QSTRING
  116. /* SQSTRING - single quoted string */
  117. %token SQSTRING
  118. /* COMP_NAME - A name with dots */
  119. %token COMP_NAME
  120. /* INT32 - 32 bit integer */
  121. %token INT32
  122. /* INT64 - 64 bit integer */
  123. %token INT64
  124. /* FLOAT64 - floating point number */
  125. %token FLOAT64
  126. /* HEXBYTE - two digit hex number */
  127. %token HEXBYTE
  128. /* Punctuation */
  129. %token DOT "."
  130. %token OPEN_BRACE "{"
  131. %token CLOSE_BRACE "}"
  132. %token OPEN_BRACKET "["
  133. %token CLOSE_BRACKET "]"
  134. %token OPEN_PARENS "("
  135. %token CLOSE_PARENS ")"
  136. %token COMMA ","
  137. %token COLON ":"
  138. %token DOUBLE_COLON "::"
  139. %token SEMICOLON ";"
  140. %token ASSIGN "="
  141. %token STAR "*"
  142. %token AMPERSAND "&"
  143. %token PLUS "+"
  144. %token SLASH "/"
  145. %token BANG "!"
  146. %token ELLIPSIS "..."
  147. %token DASH "-"
  148. %token OPEN_ANGLE_BRACKET "<"
  149. %token CLOSE_ANGLE_BRACKET ">"
  150. %token UNKNOWN
  151. /* INSTR_* instruction types */
  152. %token INSTR_NONE
  153. %token INSTR_VAR
  154. %token INSTR_I
  155. %token INSTR_I8
  156. %token INSTR_R
  157. %token INSTR_BRTARGET
  158. %token INSTR_METHOD
  159. %token INSTR_NEWOBJ
  160. %token INSTR_FIELD
  161. %token INSTR_TYPE
  162. %token INSTR_STRING
  163. %token INSTR_SIG
  164. %token INSTR_RVA
  165. %token INSTR_TOK
  166. %token INSTR_SWITCH
  167. %token INSTR_PHI
  168. %token INSTR_LOCAL
  169. %token INSTR_PARAM
  170. /* Mechanically generated - DO NOT EDIT! */
  171. /* Directives */
  172. %token D_ADDON
  173. %token D_ALGORITHM
  174. %token D_ASSEMBLY
  175. %token D_BACKING
  176. %token D_BLOB
  177. %token D_CAPABILITY
  178. %token D_CCTOR
  179. %token D_CLASS
  180. %token D_COMTYPE
  181. %token D_CONFIG
  182. %token D_IMAGEBASE
  183. %token D_CORFLAGS
  184. %token D_CTOR
  185. %token D_CUSTOM
  186. %token D_DATA
  187. %token D_EMITBYTE
  188. %token D_ENTRYPOINT
  189. %token D_EVENT
  190. %token D_EXELOC
  191. %token D_EXPORT
  192. %token D_FIELD
  193. %token D_FILE
  194. %token D_FIRE
  195. %token D_GET
  196. %token D_HASH
  197. %token D_IMPLICITCOM
  198. %token D_LANGUAGE
  199. %token D_LINE
  200. %token D_XLINE
  201. %token D_LOCALE
  202. %token D_LOCALS
  203. %token D_MANIFESTRES
  204. %token D_MAXSTACK
  205. %token D_METHOD
  206. %token D_MIME
  207. %token D_MODULE
  208. %token D_MRESOURCE
  209. %token D_NAMESPACE
  210. %token D_ORIGINATOR
  211. %token D_OS
  212. %token D_OTHER
  213. %token D_OVERRIDE
  214. %token D_PACK
  215. %token D_PARAM
  216. %token D_PERMISSION
  217. %token D_PERMISSIONSET
  218. %token D_PROCESSOR
  219. %token D_PROPERTY
  220. %token D_PUBLICKEY
  221. %token D_PUBLICKEYTOKEN
  222. %token D_REMOVEON
  223. %token D_SET
  224. %token D_SIZE
  225. %token D_STACKRESERVE
  226. %token D_SUBSYSTEM
  227. %token D_TITLE
  228. %token D_TRY
  229. %token D_VER
  230. %token D_VTABLE
  231. %token D_VTENTRY
  232. %token D_VTFIXUP
  233. %token D_ZEROINIT
  234. /* Keywords */
  235. %token K_AT
  236. %token K_AS
  237. %token K_IMPLICITCOM
  238. %token K_IMPLICITRES
  239. %token K_NOAPPDOMAIN
  240. %token K_NOPROCESS
  241. %token K_NOMACHINE
  242. %token K_EXTERN
  243. %token K_INSTANCE
  244. %token K_EXPLICIT
  245. %token K_DEFAULT
  246. %token K_VARARG
  247. %token K_UNMANAGED
  248. %token K_CDECL
  249. %token K_STDCALL
  250. %token K_THISCALL
  251. %token K_FASTCALL
  252. %token K_MARSHAL
  253. %token K_IN
  254. %token K_OUT
  255. %token K_OPT
  256. // %token K_LCID
  257. %token K_RETVAL
  258. %token K_STATIC
  259. %token K_PUBLIC
  260. %token K_PRIVATE
  261. %token K_FAMILY
  262. %token K_INITONLY
  263. %token K_RTSPECIALNAME
  264. %token K_SPECIALNAME
  265. %token K_ASSEMBLY
  266. %token K_FAMANDASSEM
  267. %token K_FAMORASSEM
  268. %token K_PRIVATESCOPE
  269. %token K_LITERAL
  270. %token K_NOTSERIALIZED
  271. %token K_VALUE
  272. %token K_NOT_IN_GC_HEAP
  273. %token K_INTERFACE
  274. %token K_SEALED
  275. %token K_ABSTRACT
  276. %token K_AUTO
  277. %token K_SEQUENTIAL
  278. %token K_ANSI
  279. %token K_UNICODE
  280. %token K_AUTOCHAR
  281. %token K_BESTFIT
  282. %token K_IMPORT
  283. %token K_SERIALIZABLE
  284. %token K_NESTED
  285. %token K_LATEINIT
  286. %token K_EXTENDS
  287. %token K_IMPLEMENTS
  288. %token K_FINAL
  289. %token K_VIRTUAL
  290. %token K_HIDEBYSIG
  291. %token K_NEWSLOT
  292. %token K_UNMANAGEDEXP
  293. %token K_PINVOKEIMPL
  294. %token K_NOMANGLE
  295. %token K_OLE
  296. %token K_LASTERR
  297. %token K_WINAPI
  298. %token K_NATIVE
  299. %token K_IL
  300. %token K_CIL
  301. %token K_OPTIL
  302. %token K_MANAGED
  303. %token K_FORWARDREF
  304. %token K_RUNTIME
  305. %token K_INTERNALCALL
  306. %token K_SYNCHRONIZED
  307. %token K_NOINLINING
  308. %token K_CUSTOM
  309. %token K_FIXED
  310. %token K_SYSSTRING
  311. %token K_ARRAY
  312. %token K_VARIANT
  313. %token K_CURRENCY
  314. %token K_SYSCHAR
  315. %token K_VOID
  316. %token K_BOOL
  317. %token K_INT8
  318. %token K_INT16
  319. %token K_INT32
  320. %token K_INT64
  321. %token K_FLOAT32
  322. %token K_FLOAT64
  323. %token K_ERROR
  324. %token K_UNSIGNED
  325. %token K_UINT
  326. %token K_UINT8
  327. %token K_UINT16
  328. %token K_UINT32
  329. %token K_UINT64
  330. %token K_DECIMAL
  331. %token K_DATE
  332. %token K_BSTR
  333. %token K_LPSTR
  334. %token K_LPWSTR
  335. %token K_LPTSTR
  336. %token K_OBJECTREF
  337. %token K_IUNKNOWN
  338. %token K_IDISPATCH
  339. %token K_STRUCT
  340. %token K_SAFEARRAY
  341. %token K_INT
  342. %token K_BYVALSTR
  343. %token K_TBSTR
  344. %token K_LPVOID
  345. %token K_ANY
  346. %token K_FLOAT
  347. %token K_LPSTRUCT
  348. %token K_NULL
  349. %token K_PTR
  350. %token K_VECTOR
  351. %token K_HRESULT
  352. %token K_CARRAY
  353. %token K_USERDEFINED
  354. %token K_RECORD
  355. %token K_FILETIME
  356. %token K_BLOB
  357. %token K_STREAM
  358. %token K_STORAGE
  359. %token K_STREAMED_OBJECT
  360. %token K_STORED_OBJECT
  361. %token K_BLOB_OBJECT
  362. %token K_CF
  363. %token K_CLSID
  364. %token K_METHOD
  365. %token K_CLASS
  366. %token K_PINNED
  367. %token K_MODREQ
  368. %token K_MODOPT
  369. %token K_TYPEDREF
  370. %token K_TYPE
  371. %token K_WCHAR
  372. %token K_CHAR
  373. %token K_FROMUNMANAGED
  374. %token K_CALLMOSTDERIVED
  375. %token K_BYTEARRAY
  376. %token K_WITH
  377. %token K_INIT
  378. %token K_TO
  379. %token K_CATCH
  380. %token K_FILTER
  381. %token K_FINALLY
  382. %token K_FAULT
  383. %token K_HANDLER
  384. %token K_TLS
  385. %token K_FIELD
  386. %token K_PROPERTY
  387. %token K_REQUEST
  388. %token K_DEMAND
  389. %token K_ASSERT
  390. %token K_DENY
  391. %token K_PERMITONLY
  392. %token K_LINKCHECK
  393. %token K_INHERITCHECK
  394. %token K_REQMIN
  395. %token K_REQOPT
  396. %token K_REQREFUSE
  397. %token K_PREJITGRANT
  398. %token K_PREJITDENY
  399. %token K_NONCASDEMAND
  400. %token K_NONCASLINKDEMAND
  401. %token K_NONCASINHERITANCE
  402. %token K_READONLY
  403. %token K_NOMETADATA
  404. %token K_ALGORITHM
  405. %token K_FULLORIGIN
  406. // %token K_NAN
  407. // %token K_INF
  408. // %token K_PUBLICKEY
  409. %token K_ENABLEJITTRACKING
  410. %token K_DISABLEJITOPTIMIZER
  411. %token K_RETARGETABLE
  412. %token K_PRESERVESIG
  413. %token K_BEFOREFIELDINIT
  414. %token K_ALIGNMENT
  415. %token K_NULLREF
  416. %token K_VALUETYPE
  417. %token K_COMPILERCONTROLLED
  418. %token K_REQSECOBJ
  419. %token K_ENUM
  420. %token K_OBJECT
  421. %token K_STRING
  422. %token K_TRUE
  423. %token K_FALSE
  424. %token K_IS
  425. %token K_ON
  426. %token K_OFF
  427. %token K_CHARMAPERROR
  428. /* end generated */
  429. %start il_file
  430. %%
  431. il_file : decls
  432. ;
  433. decls : /* EMPTY */
  434. | decls decl
  435. ;
  436. decl : class_all
  437. | namespace_all
  438. | method_all
  439. | field_decl
  440. | data_decl
  441. | vtfixup_decl
  442. | file_decl
  443. | assembly_all
  444. | assemblyref_all
  445. | exptype_all
  446. | manifestres_all
  447. | module_head
  448. | sec_decl
  449. | customattr_decl
  450. {
  451. if (codegen.CurrentCustomAttrTarget != null)
  452. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  453. }
  454. | D_SUBSYSTEM int32
  455. {
  456. codegen.SetSubSystem ((int) $2);
  457. }
  458. | D_CORFLAGS int32
  459. {
  460. codegen.SetCorFlags ((int) $2);
  461. }
  462. | D_FILE K_ALIGNMENT int32
  463. | D_IMAGEBASE int64
  464. {
  465. codegen.SetImageBase ((long) $2);
  466. }
  467. | D_STACKRESERVE int64
  468. {
  469. codegen.SetStackReserve ((long) $2);
  470. }
  471. | extsource_spec
  472. | language_decl
  473. ;
  474. extsource_spec : D_LINE int32 SQSTRING
  475. | D_LINE int32
  476. | D_LINE int32 COLON int32 SQSTRING
  477. | D_LINE int32 COLON int32
  478. ;
  479. language_decl : D_LANGUAGE SQSTRING
  480. | D_LANGUAGE SQSTRING COMMA SQSTRING
  481. | D_LANGUAGE SQSTRING COMMA SQSTRING COMMA SQSTRING
  482. ;
  483. vtfixup_decl : D_VTFIXUP OPEN_BRACKET int32 CLOSE_BRACKET
  484. vtfixup_attr K_AT id
  485. ;
  486. vtfixup_attr : /* EMPTY */
  487. | vtfixup_attr K_INT32
  488. | vtfixup_attr K_INT64
  489. | vtfixup_attr K_FROMUNMANAGED
  490. | vtfixup_attr K_CALLMOSTDERIVED
  491. ;
  492. namespace_all : namespace_head OPEN_BRACE decls CLOSE_BRACE
  493. {
  494. codegen.CurrentNameSpace = null;
  495. }
  496. ;
  497. namespace_head : D_NAMESPACE comp_name
  498. {
  499. codegen.CurrentNameSpace = (string) $2;
  500. }
  501. ;
  502. class_all : class_head OPEN_BRACE class_decls CLOSE_BRACE
  503. {
  504. codegen.EndTypeDef ();
  505. }
  506. ;
  507. class_head : D_CLASS class_attr comp_name formal_typars_clause extends_clause
  508. impl_clause
  509. {
  510. codegen.BeginTypeDef ((TypeAttr) $2, (string) $3,
  511. $5 as BaseClassRef, $6 as ArrayList, null, (GenericParameters) $4);
  512. if (is_value_class)
  513. codegen.CurrentTypeDef.MakeValueClass ();
  514. if (is_enum_class)
  515. codegen.CurrentTypeDef.MakeEnumClass ();
  516. }
  517. ;
  518. class_attrs : class_attrs class_attr
  519. ;
  520. class_attr : /* EMPTY */
  521. {
  522. // Reset some flags
  523. is_value_class = false;
  524. is_enum_class = false;
  525. $$ = new TypeAttr ();
  526. }
  527. | class_attr K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.Public; }
  528. | class_attr K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.Private; }
  529. | class_attr K_NESTED K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.NestedPrivate; }
  530. | class_attr K_NESTED K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.NestedPublic; }
  531. | class_attr K_NESTED K_FAMILY { $$ = (TypeAttr)$1 | TypeAttr.NestedFamily; }
  532. | class_attr K_NESTED K_ASSEMBLY { $$ = (TypeAttr)$1 | TypeAttr.NestedAssembly;}
  533. | class_attr K_NESTED K_FAMANDASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamAndAssem; }
  534. | class_attr K_NESTED K_FAMORASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamOrAssem; }
  535. | class_attr K_VALUE { is_value_class = true; }
  536. | class_attr K_ENUM { is_enum_class = true; is_value_class = true;
  537. }
  538. | class_attr K_INTERFACE { $$ = (TypeAttr)$1 | TypeAttr.Interface; }
  539. | class_attr K_SEALED { $$ = (TypeAttr)$1 | TypeAttr.Sealed; }
  540. | class_attr K_ABSTRACT { $$ = (TypeAttr)$1 | TypeAttr.Abstract; }
  541. | class_attr K_AUTO { }
  542. | class_attr K_SEQUENTIAL { $$ = (TypeAttr)$1 | TypeAttr.SequentialLayout; }
  543. | class_attr K_EXPLICIT { $$ = (TypeAttr)$1 | TypeAttr.ExplicitLayout; }
  544. | class_attr K_ANSI { }
  545. | class_attr K_UNICODE { $$ = (TypeAttr)$1 | TypeAttr.UnicodeClass; }
  546. | class_attr K_AUTOCHAR { $$ = (TypeAttr)$1 | TypeAttr.AutoClass; }
  547. | class_attr K_IMPORT { $$ = (TypeAttr)$1 | TypeAttr.Import; }
  548. | class_attr K_SERIALIZABLE { $$ = (TypeAttr)$1 | TypeAttr.Serializable; }
  549. | class_attr K_BEFOREFIELDINIT { $$ = (TypeAttr)$1 | TypeAttr.BeforeFieldInit; }
  550. | class_attr K_SPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.SpecialName; }
  551. | class_attr K_RTSPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.RTSpecialName; }
  552. ;
  553. extends_clause : /* EMPTY */
  554. | K_EXTENDS generic_class_ref
  555. {
  556. $$ = $2;
  557. }
  558. ;
  559. impl_clause : /* EMPTY */
  560. | impl_class_refs
  561. ;
  562. impl_class_refs : K_IMPLEMENTS generic_class_ref
  563. {
  564. ArrayList al = new ArrayList ();
  565. al.Add ($2);
  566. $$ = al;
  567. }
  568. | impl_class_refs COMMA generic_class_ref
  569. {
  570. ArrayList al = (ArrayList) $1;
  571. al.Insert (0, $3);
  572. $$ = al;
  573. }
  574. ;
  575. formal_typars_clause : /* EMPTY */
  576. | OPEN_ANGLE_BRACKET formal_typars CLOSE_ANGLE_BRACKET
  577. {
  578. #if NET_2_0 || BOOTSTRAP_NET_2_0
  579. $$ = $2;
  580. #else
  581. Report.Error ("Use ilasm2 for generics support.");
  582. #endif
  583. }
  584. ;
  585. typars_clause : /* EMPTY */
  586. | OPEN_ANGLE_BRACKET typars CLOSE_ANGLE_BRACKET
  587. {
  588. #if NET_2_0 || BOOTSTRAP_NET_2_0
  589. $$ = $2;
  590. #else
  591. Report.Error ("Use ilasm2 for generics support.");
  592. #endif
  593. }
  594. ;
  595. typars : type
  596. {
  597. GenericArguments ga = new GenericArguments ();
  598. ga.Add ((BaseTypeRef) $1);
  599. $$ = ga;
  600. }
  601. | typars COMMA type
  602. {
  603. ((GenericArguments) $1).Add ((BaseTypeRef) $3);
  604. $$ = $1;
  605. }
  606. ;
  607. constraints_clause : /* EMTPY */
  608. | OPEN_PARENS constraints CLOSE_PARENS
  609. {
  610. $$ = $2;
  611. }
  612. ;
  613. constraints : generic_class_ref
  614. {
  615. ArrayList al = new ArrayList ();
  616. al.Add ($1);
  617. $$ = al;
  618. }
  619. | constraints COMMA generic_class_ref
  620. {
  621. ArrayList al = (ArrayList) $1;
  622. al.Add ($3);
  623. $$ = al;
  624. }
  625. ;
  626. generic_class_ref : class_ref
  627. {
  628. $$ = $1;
  629. }
  630. | K_CLASS class_ref typars_clause
  631. {
  632. if ($3 != null)
  633. $$ = ((BaseClassRef) $2).GetGenericTypeInst ((GenericArguments) $3);
  634. else
  635. $$ = $2;
  636. }
  637. | BANG int32
  638. {
  639. GenParam gpar = new GenParam ((int) $2, "", GenParamType.Var);
  640. $$ = new GenericParamRef (gpar, $2.ToString ());
  641. }
  642. | BANG BANG int32
  643. {
  644. GenParam gpar = new GenParam ((int) $3, "", GenParamType.MVar);
  645. $$ = new GenericParamRef (gpar, $3.ToString ());
  646. }
  647. | BANG id
  648. {
  649. int num = -1;
  650. string name = (string) $2;
  651. if (codegen.CurrentTypeDef != null)
  652. num = codegen.CurrentTypeDef.GetGenericParamNum (name);
  653. GenParam gpar = new GenParam (num, name, GenParamType.Var);
  654. $$ = new GenericParamRef (gpar, name);
  655. }
  656. | BANG BANG id
  657. {
  658. int num = -1;
  659. string name = (string) $3;
  660. if (codegen.CurrentMethodDef != null)
  661. num = codegen.CurrentMethodDef.GetGenericParamNum (name);
  662. GenParam gpar = new GenParam (num, name, GenParamType.MVar);
  663. $$ = new GenericParamRef (gpar, name);
  664. }
  665. ;
  666. formal_typars : formal_typar_attr constraints_clause formal_typar
  667. {
  668. GenericParameter gp = new GenericParameter ((string) $3, (PEAPI.GenericParamAttributes) $1, (ArrayList) $2);
  669. GenericParameters colln = new GenericParameters ();
  670. colln.Add (gp);
  671. $$ = colln;
  672. }
  673. | formal_typars COMMA formal_typar_attr constraints_clause formal_typar
  674. {
  675. GenericParameters colln = (GenericParameters) $1;
  676. colln.Add (new GenericParameter ((string) $5, (PEAPI.GenericParamAttributes) $3, (ArrayList) $4));
  677. $$ = colln;
  678. }
  679. ;
  680. formal_typar_attr : /* EMPTY */
  681. {
  682. $$ = new PEAPI.GenericParamAttributes ();
  683. }
  684. | formal_typar_attr PLUS
  685. {
  686. $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.Covariant;
  687. }
  688. | formal_typar_attr DASH
  689. {
  690. $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.Contravariant;
  691. }
  692. | formal_typar_attr D_CTOR
  693. {
  694. $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.DefaultConstructorConstrait;
  695. }
  696. | formal_typar_attr K_VALUETYPE
  697. {
  698. $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.NotNullableValueTypeConstraint;
  699. }
  700. | formal_typar_attr K_CLASS
  701. {
  702. $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.ReferenceTypeConstraint;
  703. }
  704. ;
  705. formal_typar : id
  706. {
  707. $$ = $1;
  708. }
  709. ;
  710. param_type_decl : D_PARAM K_TYPE id
  711. {
  712. if (codegen.CurrentMethodDef != null)
  713. codegen.CurrentCustomAttrTarget = codegen.CurrentMethodDef.GetGenericParam ((string) $3);
  714. else
  715. codegen.CurrentCustomAttrTarget = codegen.CurrentTypeDef.GetGenericParam ((string) $3);
  716. if (codegen.CurrentCustomAttrTarget == null)
  717. Report.Error (String.Format ("Type parameter '{0}' undefined.", (string) $3));
  718. }
  719. | D_PARAM K_TYPE OPEN_BRACKET int32 CLOSE_BRACKET
  720. {
  721. int index = ((int) $4);
  722. if (codegen.CurrentMethodDef != null)
  723. codegen.CurrentCustomAttrTarget = codegen.CurrentMethodDef.GetGenericParam (index - 1);
  724. else
  725. codegen.CurrentCustomAttrTarget = codegen.CurrentTypeDef.GetGenericParam (index - 1);
  726. if (codegen.CurrentCustomAttrTarget == null)
  727. Report.Error (String.Format ("Type parameter '{0}' index out of range.", index));
  728. }
  729. ;
  730. class_refs : class_ref
  731. {
  732. ArrayList class_list = new ArrayList ();
  733. class_list.Add ($1);
  734. $$ = class_list;
  735. }
  736. | class_refs COMMA class_ref
  737. {
  738. ArrayList class_list = (ArrayList) $1;
  739. class_list.Add ($3);
  740. }
  741. ;
  742. slashed_name : comp_name
  743. | slashed_name SLASH comp_name
  744. {
  745. $$ = String.Format ("{0}/{1}", $1, $3);
  746. }
  747. ;
  748. class_ref : OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name
  749. {
  750. if (codegen.IsThisAssembly ((string) $2)) {
  751. $$ = codegen.GetTypeRef ((string) $4);
  752. } else {
  753. $$ = codegen.ExternTable.GetTypeRef ((string) $2, (string) $4, false);
  754. }
  755. }
  756. | OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET slashed_name
  757. {
  758. if (codegen.IsThisModule ((string) $3)) {
  759. $$ = codegen.GetTypeRef ((string) $5);
  760. } else {
  761. $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, (string) $5, false);
  762. }
  763. }
  764. | slashed_name
  765. {
  766. PrimitiveTypeRef prim = PrimitiveTypeRef.GetPrimitiveType ((string) $1);
  767. if (prim != null && !codegen.IsThisAssembly ("mscorlib"))
  768. $$ = prim;
  769. else
  770. $$ = codegen.GetTypeRef ((string) $1);
  771. }
  772. ;
  773. class_decls : /* EMPTY */
  774. | class_decls class_decl
  775. ;
  776. class_decl : method_all
  777. | class_all
  778. | event_all
  779. | prop_all
  780. | field_decl
  781. | data_decl
  782. | sec_decl
  783. {
  784. AddSecDecl ($1, false);
  785. }
  786. | extsource_spec
  787. | customattr_decl
  788. {
  789. if (codegen.CurrentCustomAttrTarget != null)
  790. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  791. }
  792. | param_type_decl
  793. | D_SIZE int32
  794. {
  795. codegen.CurrentTypeDef.SetSize ((int) $2);
  796. }
  797. | D_PACK int32
  798. {
  799. codegen.CurrentTypeDef.SetPack ((int) $2);
  800. }
  801. | D_OVERRIDE type_spec DOUBLE_COLON method_name K_WITH call_conv type
  802. type_spec DOUBLE_COLON method_name type_list
  803. {
  804. //
  805. // My copy of the spec didn't have a type_list but
  806. // it seems pretty crucial
  807. //
  808. BaseTypeRef owner = (BaseTypeRef) $2;
  809. ArrayList arg_list = (ArrayList) $11;
  810. BaseTypeRef[] param_list;
  811. BaseMethodRef decl;
  812. if (arg_list != null)
  813. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  814. else
  815. param_list = new BaseTypeRef[0];
  816. decl = owner.GetMethodRef ((BaseTypeRef) $7,
  817. (CallConv) $6, (string) $4, param_list, 0);
  818. // NOTICE: `owner' here might be wrong
  819. string sig = MethodDef.CreateSignature (owner, (CallConv) $6, (string) $10,
  820. param_list, 0, false);
  821. codegen.CurrentTypeDef.AddOverride (sig, decl);
  822. }
  823. OPEN_PARENS sig_args CLOSE_PARENS
  824. | language_decl
  825. ;
  826. type : generic_class_ref
  827. {
  828. $$ = $1;
  829. }
  830. | K_OBJECT
  831. {
  832. $$ = new PrimitiveTypeRef (PrimitiveType.Object, "System.Object");
  833. }
  834. | K_VALUE K_CLASS class_ref
  835. {
  836. BaseClassRef class_ref = (BaseClassRef) $3;
  837. class_ref.MakeValueClass ();
  838. $$ = class_ref;
  839. }
  840. | K_VALUETYPE OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name typars_clause
  841. {
  842. ExternTypeRef ext_ref = codegen.ExternTable.GetTypeRef ((string) $3, (string) $5, true);
  843. if ($6 != null)
  844. $$ = ext_ref.GetGenericTypeInst ((GenericArguments) $6);
  845. else
  846. $$ = ext_ref;
  847. }
  848. | K_VALUETYPE slashed_name typars_clause
  849. {
  850. TypeRef t_ref = codegen.GetTypeRef ((string) $2);
  851. t_ref.MakeValueClass ();
  852. if ($3 != null)
  853. $$ = t_ref.GetGenericTypeInst ((GenericArguments) $3);
  854. else
  855. $$ = t_ref;
  856. }
  857. | type OPEN_BRACKET CLOSE_BRACKET
  858. {
  859. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  860. base_type.MakeArray ();
  861. $$ = base_type;
  862. }
  863. | type OPEN_BRACKET bounds CLOSE_BRACKET
  864. {
  865. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  866. ArrayList bound_list = (ArrayList) $3;
  867. base_type.MakeBoundArray (bound_list);
  868. $$ = base_type;
  869. }
  870. | type AMPERSAND
  871. {
  872. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  873. base_type.MakeManagedPointer ();
  874. $$ = base_type;
  875. }
  876. | type STAR
  877. {
  878. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  879. base_type.MakeUnmanagedPointer ();
  880. $$ = base_type;
  881. }
  882. | type K_PINNED
  883. {
  884. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  885. base_type.MakePinned ();
  886. $$ = base_type;
  887. }
  888. | type K_MODREQ OPEN_PARENS class_ref CLOSE_PARENS
  889. {
  890. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  891. BaseClassRef class_ref = (BaseClassRef) $4;
  892. base_type.MakeCustomModified (codegen,
  893. CustomModifier.modreq, class_ref);
  894. $$ = base_type;
  895. }
  896. | type K_MODOPT OPEN_PARENS class_ref CLOSE_PARENS
  897. {
  898. BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1);
  899. BaseClassRef class_ref = (BaseClassRef) $4;
  900. base_type.MakeCustomModified (codegen,
  901. CustomModifier.modopt, class_ref);
  902. $$ = base_type;
  903. }
  904. | K_METHOD call_conv type STAR OPEN_PARENS sig_args CLOSE_PARENS
  905. {
  906. $$ = new MethodPointerTypeRef ((CallConv) $2, (BaseTypeRef) $3, (ArrayList) $6);
  907. }
  908. | primitive_type
  909. ;
  910. ;
  911. primitive_type : K_INT8
  912. {
  913. $$ = new PrimitiveTypeRef (PrimitiveType.Int8, "System.SByte");
  914. }
  915. | K_INT16
  916. {
  917. $$ = new PrimitiveTypeRef (PrimitiveType.Int16, "System.Int16");
  918. }
  919. | K_INT32
  920. {
  921. $$ = new PrimitiveTypeRef (PrimitiveType.Int32, "System.Int32");
  922. }
  923. | K_INT64
  924. {
  925. $$ = new PrimitiveTypeRef (PrimitiveType.Int64, "System.Int64");
  926. }
  927. | K_FLOAT32
  928. {
  929. $$ = new PrimitiveTypeRef (PrimitiveType.Float32, "System.Single");
  930. }
  931. | K_FLOAT64
  932. {
  933. $$ = new PrimitiveTypeRef (PrimitiveType.Float64, "System.Double");
  934. }
  935. | K_UNSIGNED K_INT8
  936. {
  937. $$ = new PrimitiveTypeRef (PrimitiveType.UInt8, "System.Byte");
  938. }
  939. | K_UINT8
  940. {
  941. $$ = new PrimitiveTypeRef (PrimitiveType.UInt8, "System.Byte");
  942. }
  943. | K_UNSIGNED K_INT16
  944. {
  945. $$ = new PrimitiveTypeRef (PrimitiveType.UInt16, "System.UInt16");
  946. }
  947. | K_UINT16
  948. {
  949. $$ = new PrimitiveTypeRef (PrimitiveType.UInt16, "System.UInt16");
  950. }
  951. | K_UNSIGNED K_INT32
  952. {
  953. $$ = new PrimitiveTypeRef (PrimitiveType.UInt32, "System.UInt32");
  954. }
  955. | K_UINT32
  956. {
  957. $$ = new PrimitiveTypeRef (PrimitiveType.UInt32, "System.UInt32");
  958. }
  959. | K_UNSIGNED K_INT64
  960. {
  961. $$ = new PrimitiveTypeRef (PrimitiveType.UInt64, "System.UInt64");
  962. }
  963. | K_UINT64
  964. {
  965. $$ = new PrimitiveTypeRef (PrimitiveType.UInt64, "System.UInt64");
  966. }
  967. | K_NATIVE K_INT
  968. {
  969. // TODO: Is this the proper full name
  970. $$ = new PrimitiveTypeRef (PrimitiveType.NativeInt, "System.IntPtr");
  971. }
  972. | K_NATIVE K_UNSIGNED K_INT
  973. {
  974. $$ = new PrimitiveTypeRef (PrimitiveType.NativeUInt, "System.UIntPtr");
  975. }
  976. | K_NATIVE K_UINT
  977. {
  978. $$ = new PrimitiveTypeRef (PrimitiveType.NativeUInt, "System.UIntPtr");
  979. }
  980. | K_TYPEDREF
  981. {
  982. $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef,
  983. "System.TypedReference");
  984. }
  985. | K_CHAR
  986. {
  987. $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
  988. }
  989. | K_WCHAR
  990. {
  991. $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
  992. }
  993. | K_VOID
  994. {
  995. $$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void");
  996. }
  997. | K_BOOL
  998. {
  999. $$ = new PrimitiveTypeRef (PrimitiveType.Boolean, "System.Boolean");
  1000. }
  1001. | K_STRING
  1002. {
  1003. $$ = new PrimitiveTypeRef (PrimitiveType.String, "System.String");
  1004. }
  1005. ;
  1006. bounds : bound
  1007. {
  1008. ArrayList bound_list = new ArrayList ();
  1009. bound_list.Add ($1);
  1010. $$ = bound_list;
  1011. }
  1012. | bounds COMMA bound
  1013. {
  1014. ArrayList bound_list = (ArrayList) $1;
  1015. bound_list.Add ($3);
  1016. }
  1017. ;
  1018. bound : /* EMPTY */
  1019. {
  1020. // This is shortref for no lowerbound or size
  1021. $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis);
  1022. }
  1023. | ELLIPSIS
  1024. {
  1025. // No lower bound or size
  1026. $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis);
  1027. }
  1028. | int32
  1029. {
  1030. /* Only size specified */
  1031. int size = (int) $1;
  1032. if (size < 0)
  1033. /* size cannot be < 0, so emit as (0, ...)
  1034. ilasm.net emits it like this */
  1035. $$ = new DictionaryEntry (0, TypeRef.Ellipsis);
  1036. else
  1037. $$ = new DictionaryEntry (TypeRef.Ellipsis, size);
  1038. }
  1039. | int32 ELLIPSIS int32
  1040. {
  1041. // lower and upper bound
  1042. int lower = (int) $1;
  1043. int upper = (int) $3;
  1044. if (lower > upper)
  1045. Report.Error ("Lower bound " + lower + " must be <= upper bound " + upper);
  1046. $$ = new DictionaryEntry ($1, $3);
  1047. }
  1048. | int32 ELLIPSIS
  1049. {
  1050. // Just lower bound
  1051. $$ = new DictionaryEntry ($1, TypeRef.Ellipsis);
  1052. }
  1053. ;
  1054. call_conv : K_INSTANCE call_conv
  1055. {
  1056. $$ = (CallConv) $2 | CallConv.Instance;
  1057. }
  1058. | K_EXPLICIT call_conv
  1059. {
  1060. $$ = (CallConv) $2 | CallConv.InstanceExplicit;
  1061. }
  1062. | call_kind
  1063. ;
  1064. call_kind : /* EMPTY */
  1065. {
  1066. $$ = new CallConv ();
  1067. }
  1068. | K_DEFAULT
  1069. {
  1070. $$ = CallConv.Default;
  1071. }
  1072. | K_VARARG
  1073. {
  1074. $$ = CallConv.Vararg;
  1075. }
  1076. | K_UNMANAGED K_CDECL
  1077. {
  1078. $$ = CallConv.Cdecl;
  1079. }
  1080. | K_UNMANAGED K_STDCALL
  1081. {
  1082. $$ = CallConv.Stdcall;
  1083. }
  1084. | K_UNMANAGED K_THISCALL
  1085. {
  1086. $$ = CallConv.Thiscall;
  1087. }
  1088. | K_UNMANAGED K_FASTCALL
  1089. {
  1090. $$ = CallConv.Fastcall;
  1091. }
  1092. ;
  1093. native_type : /* EMPTY */
  1094. | K_CUSTOM OPEN_PARENS comp_qstring COMMA comp_qstring CLOSE_PARENS
  1095. {
  1096. $$ = new CustomMarshaller ((string) $3, (string) $5);
  1097. }
  1098. | K_FIXED K_SYSSTRING OPEN_BRACKET int32 CLOSE_BRACKET
  1099. {
  1100. $$ = new FixedSysString ((uint) (int)$4);
  1101. }
  1102. | K_FIXED K_ARRAY OPEN_BRACKET int32 CLOSE_BRACKET
  1103. {
  1104. $$ = new FixedArray ((int) $4);
  1105. }
  1106. | K_VARIANT
  1107. | K_CURRENCY
  1108. {
  1109. $$ = NativeType.Currency;
  1110. }
  1111. | K_SYSCHAR
  1112. | K_VOID
  1113. {
  1114. $$ = NativeType.Void;
  1115. }
  1116. | K_BOOL
  1117. {
  1118. $$ = NativeType.Boolean;
  1119. }
  1120. | K_INT8
  1121. {
  1122. $$ = NativeType.Int8;
  1123. }
  1124. | K_INT16
  1125. {
  1126. $$ = NativeType.Int16;
  1127. }
  1128. | K_INT32
  1129. {
  1130. $$ = NativeType.Int32;
  1131. }
  1132. | K_INT64
  1133. {
  1134. $$ = NativeType.Int64;
  1135. }
  1136. | K_FLOAT32
  1137. {
  1138. $$ = NativeType.Float32;
  1139. }
  1140. | K_FLOAT64
  1141. {
  1142. $$ = NativeType.Float64;
  1143. }
  1144. | K_ERROR
  1145. {
  1146. $$ = NativeType.Error;
  1147. }
  1148. | K_UNSIGNED K_INT8
  1149. {
  1150. $$ = NativeType.UInt8;
  1151. }
  1152. | K_UINT8
  1153. {
  1154. $$ = NativeType.UInt8;
  1155. }
  1156. | K_UNSIGNED K_INT16
  1157. {
  1158. $$ = NativeType.UInt16;
  1159. }
  1160. | K_UINT16
  1161. {
  1162. $$ = NativeType.UInt16;
  1163. }
  1164. | K_UNSIGNED K_INT32
  1165. {
  1166. $$ = NativeType.UInt32;
  1167. }
  1168. | K_UINT32
  1169. {
  1170. $$ = NativeType.UInt32;
  1171. }
  1172. | K_UNSIGNED K_INT64
  1173. {
  1174. $$ = NativeType.UInt64;
  1175. }
  1176. | K_UINT64
  1177. {
  1178. $$ = NativeType.UInt64;
  1179. }
  1180. | native_type STAR
  1181. | native_type OPEN_BRACKET CLOSE_BRACKET
  1182. {
  1183. $$ = new NativeArray ((NativeType) $1);
  1184. }
  1185. | native_type OPEN_BRACKET int32 CLOSE_BRACKET
  1186. {
  1187. $$ = new NativeArray ((NativeType) $1, (int) $3, 0, 0);
  1188. }
  1189. | native_type OPEN_BRACKET int32 PLUS int32 CLOSE_BRACKET
  1190. {
  1191. //FIXME: Allowed only for methods, !fields
  1192. $$ = new NativeArray ((NativeType) $1, (int) $3, (int) $5);
  1193. }
  1194. | native_type OPEN_BRACKET PLUS int32 CLOSE_BRACKET
  1195. {
  1196. //FIXME: Allowed only for methods, !fields
  1197. $$ = new NativeArray ((NativeType) $1, -1, (int) $4);
  1198. }
  1199. | K_DECIMAL
  1200. | K_DATE
  1201. | K_BSTR
  1202. {
  1203. $$ = NativeType.BStr;
  1204. }
  1205. | K_LPSTR
  1206. {
  1207. $$ = NativeType.LPStr;
  1208. }
  1209. | K_LPWSTR
  1210. {
  1211. $$ = NativeType.LPWStr;
  1212. }
  1213. | K_LPTSTR
  1214. {
  1215. $$ = NativeType.LPTStr;
  1216. }
  1217. | K_OBJECTREF
  1218. | K_IUNKNOWN
  1219. {
  1220. $$ = NativeType.IUnknown;
  1221. }
  1222. | K_IDISPATCH
  1223. {
  1224. $$ = NativeType.IDispatch;
  1225. }
  1226. | K_STRUCT
  1227. {
  1228. $$ = NativeType.Struct;
  1229. }
  1230. | K_INTERFACE
  1231. {
  1232. $$ = NativeType.Interface;
  1233. }
  1234. | K_SAFEARRAY variant_type
  1235. {
  1236. if ($2 == null)
  1237. $$ = new SafeArray ();
  1238. else
  1239. $$ = new SafeArray ((SafeArrayType) $2);
  1240. }
  1241. | K_SAFEARRAY variant_type COMMA comp_qstring
  1242. | K_INT
  1243. {
  1244. $$ = NativeType.Int;
  1245. }
  1246. | K_UNSIGNED K_INT
  1247. {
  1248. $$ = NativeType.UInt;
  1249. }
  1250. | K_NESTED K_STRUCT
  1251. | K_BYVALSTR
  1252. {
  1253. $$ = NativeType.ByValStr;
  1254. }
  1255. | K_ANSI K_BSTR
  1256. {
  1257. $$ = NativeType.AnsiBStr;
  1258. }
  1259. | K_TBSTR
  1260. {
  1261. $$ = NativeType.TBstr;
  1262. }
  1263. | K_VARIANT K_BOOL
  1264. {
  1265. $$ = NativeType.VariantBool;
  1266. }
  1267. | K_METHOD
  1268. {
  1269. $$ = NativeType.FuncPtr;
  1270. }
  1271. | K_AS K_ANY
  1272. {
  1273. $$ = NativeType.AsAny;
  1274. }
  1275. | K_LPSTRUCT
  1276. {
  1277. $$ = NativeType.LPStruct;
  1278. }
  1279. ;
  1280. variant_type : /* EMPTY */
  1281. | K_NULL
  1282. | K_VARIANT
  1283. {
  1284. $$ = SafeArrayType.variant;
  1285. }
  1286. | K_CURRENCY
  1287. {
  1288. $$ = SafeArrayType.currency;
  1289. }
  1290. | K_VOID
  1291. | K_BOOL
  1292. {
  1293. $$ = SafeArrayType.boolean;
  1294. }
  1295. | K_INT8
  1296. {
  1297. $$ = SafeArrayType.int8;
  1298. }
  1299. | K_INT16
  1300. {
  1301. $$ = SafeArrayType.int16;
  1302. }
  1303. | K_INT32
  1304. {
  1305. $$ = SafeArrayType.int32;
  1306. }
  1307. | K_INT64
  1308. | K_FLOAT32
  1309. {
  1310. $$ = SafeArrayType.float32;
  1311. }
  1312. | K_FLOAT64
  1313. {
  1314. $$ = SafeArrayType.float64;
  1315. }
  1316. | K_UNSIGNED K_INT8
  1317. {
  1318. $$ = SafeArrayType.uint8;
  1319. }
  1320. | K_UNSIGNED K_INT16
  1321. {
  1322. $$ = SafeArrayType.uint16;
  1323. }
  1324. | K_UNSIGNED K_INT32
  1325. {
  1326. $$ = SafeArrayType.uint32;
  1327. }
  1328. | K_UNSIGNED K_INT64
  1329. | STAR
  1330. | variant_type OPEN_BRACKET CLOSE_BRACKET
  1331. | variant_type K_VECTOR
  1332. | variant_type AMPERSAND
  1333. | K_DECIMAL
  1334. {
  1335. $$ = SafeArrayType.Decimal;
  1336. }
  1337. | K_DATE
  1338. {
  1339. $$ = SafeArrayType.date;
  1340. }
  1341. | K_BSTR
  1342. {
  1343. $$ = SafeArrayType.bstr;
  1344. }
  1345. | K_LPSTR
  1346. | K_LPWSTR
  1347. | K_IUNKNOWN
  1348. {
  1349. $$ = SafeArrayType.unknown;
  1350. }
  1351. | K_IDISPATCH
  1352. {
  1353. $$ = SafeArrayType.unknown;
  1354. }
  1355. | K_SAFEARRAY
  1356. | K_INT
  1357. {
  1358. $$ = SafeArrayType.Int;
  1359. }
  1360. | K_UNSIGNED K_INT
  1361. {
  1362. $$ = SafeArrayType.UInt;
  1363. }
  1364. | K_ERROR
  1365. {
  1366. $$ = SafeArrayType.error;
  1367. }
  1368. | K_HRESULT
  1369. | K_CARRAY
  1370. | K_USERDEFINED
  1371. | K_RECORD
  1372. | K_FILETIME
  1373. | K_BLOB
  1374. | K_STREAM
  1375. | K_STORAGE
  1376. | K_STREAMED_OBJECT
  1377. | K_STORED_OBJECT
  1378. | K_BLOB_OBJECT
  1379. | K_CF
  1380. | K_CLSID
  1381. ;
  1382. field_decl : D_FIELD repeat_opt field_attr type id at_opt init_opt
  1383. {
  1384. FieldDef field_def = new FieldDef((FieldAttr) $3,
  1385. (string) $5, (BaseTypeRef) $4);
  1386. codegen.AddFieldDef (field_def);
  1387. codegen.CurrentCustomAttrTarget = field_def;
  1388. if ($2 != null) {
  1389. field_def.SetOffset ((uint) (int)$2);
  1390. }
  1391. if ($6 != null) {
  1392. field_def.AddDataValue ((string) $6);
  1393. }
  1394. if ($7 != null) {
  1395. field_def.SetValue ((Constant) $7);
  1396. }
  1397. }
  1398. ;
  1399. repeat_opt : /* EMPTY */
  1400. | OPEN_BRACKET int32 CLOSE_BRACKET
  1401. {
  1402. $$ = $2;
  1403. }
  1404. ;
  1405. field_attr : /* EMPTY */
  1406. {
  1407. $$ = new FieldAttr ();
  1408. }
  1409. | field_attr K_PUBLIC
  1410. {
  1411. $$ = (FieldAttr) $1 | FieldAttr.Public;
  1412. }
  1413. | field_attr K_PRIVATE
  1414. {
  1415. $$ = (FieldAttr) $1 | FieldAttr.Private;
  1416. }
  1417. | field_attr K_FAMILY
  1418. {
  1419. $$ = (FieldAttr) $1 | FieldAttr.Family;
  1420. }
  1421. | field_attr K_ASSEMBLY
  1422. {
  1423. $$ = (FieldAttr) $1 | FieldAttr.Assembly;
  1424. }
  1425. | field_attr K_FAMANDASSEM
  1426. {
  1427. $$ = (FieldAttr) $1 | FieldAttr.FamAndAssem;
  1428. }
  1429. | field_attr K_FAMORASSEM
  1430. {
  1431. $$ = (FieldAttr) $1 | FieldAttr.FamOrAssem;
  1432. }
  1433. | field_attr K_PRIVATESCOPE
  1434. {
  1435. // This is just 0x0000
  1436. }
  1437. | field_attr K_STATIC
  1438. {
  1439. $$ = (FieldAttr) $1 | FieldAttr.Static;
  1440. }
  1441. | field_attr K_INITONLY
  1442. {
  1443. $$ = (FieldAttr) $1 | FieldAttr.Initonly;
  1444. }
  1445. | field_attr K_RTSPECIALNAME
  1446. {
  1447. $$ = (FieldAttr) $1 | FieldAttr.RTSpecialName;
  1448. }
  1449. | field_attr K_SPECIALNAME
  1450. {
  1451. $$ = (FieldAttr) $1 | FieldAttr.SpecialName;
  1452. }
  1453. | field_attr K_MARSHAL OPEN_PARENS native_type CLOSE_PARENS
  1454. {
  1455. codegen.AddFieldMarshalInfo ((NativeType) $4);
  1456. $$ = (FieldAttr) $1 | FieldAttr.HasFieldMarshal;
  1457. }
  1458. | field_attr K_LITERAL
  1459. {
  1460. $$ = (FieldAttr) $1 | FieldAttr.Literal;
  1461. }
  1462. | field_attr K_NOTSERIALIZED
  1463. {
  1464. $$ = (FieldAttr) $1 | FieldAttr.Notserialized;
  1465. }
  1466. ;
  1467. at_opt : /* EMPTY */
  1468. | K_AT id
  1469. {
  1470. $$ = $2;
  1471. }
  1472. ;
  1473. init_opt : /* EMPTY */
  1474. | ASSIGN field_init
  1475. {
  1476. $$ = $2;
  1477. }
  1478. ;
  1479. field_init_primitive : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
  1480. {
  1481. $$ = new FloatConst (Convert.ToSingle ($3));
  1482. }
  1483. | K_FLOAT64 OPEN_PARENS float64 CLOSE_PARENS
  1484. {
  1485. $$ = new DoubleConst (Convert.ToDouble ($3));
  1486. }
  1487. | K_FLOAT32 OPEN_PARENS int64 CLOSE_PARENS
  1488. {
  1489. $$ = new FloatConst (BitConverter.ToSingle (BitConverter.GetBytes ((long)$3), BitConverter.IsLittleEndian ? 0 : 4));
  1490. }
  1491. | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS
  1492. {
  1493. $$ = new DoubleConst (BitConverter.Int64BitsToDouble ((long)$3));
  1494. }
  1495. | K_INT64 OPEN_PARENS int64 CLOSE_PARENS
  1496. {
  1497. $$ = new IntConst (Convert.ToInt64 ($3));
  1498. }
  1499. | K_UINT64 OPEN_PARENS int64 CLOSE_PARENS
  1500. {
  1501. $$ = new UIntConst (Convert.ToUInt64 ((ulong)(long) $3));
  1502. }
  1503. | K_INT32 OPEN_PARENS int64 CLOSE_PARENS
  1504. {
  1505. $$ = new IntConst ((int)((long)$3));
  1506. }
  1507. | K_UINT32 OPEN_PARENS int64 CLOSE_PARENS
  1508. {
  1509. $$ = new UIntConst ((uint)((long)$3));
  1510. }
  1511. | K_INT16 OPEN_PARENS int64 CLOSE_PARENS
  1512. {
  1513. $$ = new IntConst ((short)((long) $3));
  1514. }
  1515. | K_UINT16 OPEN_PARENS int64 CLOSE_PARENS
  1516. {
  1517. $$ = new UIntConst ((ushort)((long) $3));
  1518. }
  1519. | K_CHAR OPEN_PARENS int64 CLOSE_PARENS
  1520. {
  1521. $$ = new CharConst (Convert.ToChar ($3));
  1522. }
  1523. | K_WCHAR OPEN_PARENS int64 CLOSE_PARENS
  1524. {
  1525. $$ = new CharConst (Convert.ToChar ($3));
  1526. }
  1527. | K_INT8 OPEN_PARENS int64 CLOSE_PARENS
  1528. {
  1529. $$ = new IntConst ((sbyte)((long) ($3)));
  1530. }
  1531. | K_UINT8 OPEN_PARENS int64 CLOSE_PARENS
  1532. {
  1533. $$ = new UIntConst ((byte)((long) ($3)));
  1534. }
  1535. | K_BOOL OPEN_PARENS truefalse CLOSE_PARENS
  1536. {
  1537. $$ = new BoolConst ((bool) $3);
  1538. }
  1539. ;
  1540. field_init : field_init_primitive
  1541. | K_BYTEARRAY bytes_list
  1542. {
  1543. $$ = new ByteArrConst ((byte[]) $2);
  1544. }
  1545. | comp_qstring
  1546. {
  1547. // ******** THIS IS NOT IN THE DOCUMENTATION ******** //
  1548. $$ = new StringConst ((string) $1);
  1549. }
  1550. | K_NULLREF
  1551. {
  1552. $$ = new NullConst ();
  1553. }
  1554. ;
  1555. data_decl : data_head data_body
  1556. {
  1557. DataDef datadef = (DataDef) $1;
  1558. if ($2 is ArrayList) {
  1559. ArrayList const_list = (ArrayList) $2;
  1560. DataConstant[] const_arr = new DataConstant[const_list.Count];
  1561. for (int i=0; i<const_arr.Length; i++)
  1562. const_arr[i] = (DataConstant) const_list[i];
  1563. datadef.PeapiConstant = new ArrayConstant (const_arr);
  1564. } else {
  1565. datadef.PeapiConstant = (PEAPI.Constant) $2;
  1566. }
  1567. codegen.AddDataDef (datadef);
  1568. }
  1569. ;
  1570. data_head : D_DATA tls id ASSIGN
  1571. {
  1572. $$ = new DataDef ((string) $3, (bool) $2);
  1573. }
  1574. | D_DATA tls
  1575. {
  1576. $$ = new DataDef (String.Empty, (bool) $2);
  1577. }
  1578. ;
  1579. tls : /* EMPTY */ { $$ = false; }
  1580. | K_TLS { $$ = true; }
  1581. ;
  1582. data_body : OPEN_BRACE dataitem_list CLOSE_BRACE
  1583. {
  1584. $$ = $2;
  1585. }
  1586. | dataitem
  1587. ;
  1588. dataitem_list : dataitem
  1589. {
  1590. ArrayList dataitem_list = new ArrayList ();
  1591. dataitem_list.Add ($1);
  1592. $$ = dataitem_list;
  1593. }
  1594. | dataitem_list COMMA dataitem
  1595. {
  1596. ArrayList list = (ArrayList) $1;
  1597. list.Add ($3);
  1598. }
  1599. ;
  1600. dataitem : K_CHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
  1601. {
  1602. $$ = new StringConst ((string) $4);
  1603. }
  1604. | K_WCHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
  1605. {
  1606. $$ = new StringConst ((string) $4);
  1607. }
  1608. | AMPERSAND OPEN_PARENS id CLOSE_PARENS
  1609. {
  1610. // DataDef def = codegen.CurrentTypeDef.GetDataDef ((string) $3);
  1611. // $$ = new AddressConstant ((DataConstant) def.PeapiConstant);
  1612. }
  1613. | K_BYTEARRAY ASSIGN bytes_list
  1614. {
  1615. $$ = new ByteArrConst ((byte[]) $3);
  1616. }
  1617. | K_BYTEARRAY bytes_list
  1618. {
  1619. // ******** THIS IS NOT IN THE SPECIFICATION ******** //
  1620. $$ = new ByteArrConst ((byte[]) $2);
  1621. }
  1622. | K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS repeat_opt
  1623. {
  1624. double d = (double) $3;
  1625. FloatConst float_const = new FloatConst ((float) d);
  1626. if ($5 != null)
  1627. $$ = new RepeatedConstant (float_const, (int) $5);
  1628. else
  1629. $$ = float_const;
  1630. }
  1631. | K_FLOAT64 OPEN_PARENS float64 CLOSE_PARENS repeat_opt
  1632. {
  1633. DoubleConst double_const = new DoubleConst ((double) $3);
  1634. if ($5 != null)
  1635. $$ = new RepeatedConstant (double_const, (int) $5);
  1636. else
  1637. $$ = double_const;
  1638. }
  1639. | K_INT64 OPEN_PARENS int64 CLOSE_PARENS repeat_opt
  1640. {
  1641. IntConst int_const = new IntConst ((long) $3);
  1642. if ($5 != null)
  1643. $$ = new RepeatedConstant (int_const, (int) $5);
  1644. else
  1645. $$ = int_const;
  1646. }
  1647. | K_INT32 OPEN_PARENS int32 CLOSE_PARENS repeat_opt
  1648. {
  1649. IntConst int_const = new IntConst ((int) $3);
  1650. if ($5 != null)
  1651. $$ = new RepeatedConstant (int_const, (int) $5);
  1652. else
  1653. $$ = int_const;
  1654. }
  1655. | K_INT16 OPEN_PARENS int32 CLOSE_PARENS repeat_opt
  1656. {
  1657. int i = (int) $3;
  1658. IntConst int_const = new IntConst ((short) i);
  1659. if ($5 != null)
  1660. $$ = new RepeatedConstant (int_const, (int) $5);
  1661. else
  1662. $$ = int_const;
  1663. }
  1664. | K_INT8 OPEN_PARENS int32 CLOSE_PARENS repeat_opt
  1665. {
  1666. int i = (int) $3;
  1667. IntConst int_const = new IntConst ((sbyte) i);
  1668. if ($5 != null)
  1669. $$ = new RepeatedConstant (int_const, (int) $5);
  1670. else
  1671. $$ = int_const;
  1672. }
  1673. | K_FLOAT32 repeat_opt
  1674. {
  1675. FloatConst float_const = new FloatConst (0F);
  1676. if ($2 != null)
  1677. $$ = new RepeatedConstant (float_const, (int) $2);
  1678. else
  1679. $$ = float_const;
  1680. }
  1681. | K_FLOAT64 repeat_opt
  1682. {
  1683. DoubleConst double_const = new DoubleConst (0);
  1684. if ($2 != null)
  1685. $$ = new RepeatedConstant (double_const, (int) $2);
  1686. else
  1687. $$ = double_const;
  1688. }
  1689. | K_INT64 repeat_opt
  1690. {
  1691. IntConst int_const = new IntConst ((long) 0);
  1692. if ($2 != null)
  1693. $$ = new RepeatedConstant (int_const, (int) $2);
  1694. else
  1695. $$ = int_const;
  1696. }
  1697. | K_INT32 repeat_opt
  1698. {
  1699. IntConst int_const = new IntConst ((int) 0);
  1700. if ($2 != null)
  1701. $$ = new RepeatedConstant (int_const, (int) $2);
  1702. else
  1703. $$ = int_const;
  1704. }
  1705. | K_INT16 repeat_opt
  1706. {
  1707. IntConst int_const = new IntConst ((short) 0);
  1708. if ($2 != null)
  1709. $$ = new RepeatedConstant (int_const, (int) $2);
  1710. else
  1711. $$ = int_const;
  1712. }
  1713. | K_INT8 repeat_opt
  1714. {
  1715. IntConst int_const = new IntConst ((sbyte) 0);
  1716. if ($2 != null)
  1717. $$ = new RepeatedConstant (int_const, (int) $2);
  1718. else
  1719. $$ = int_const;
  1720. }
  1721. ;
  1722. method_all : method_head OPEN_BRACE method_decls CLOSE_BRACE
  1723. {
  1724. codegen.EndMethodDef (tokenizer.Location);
  1725. }
  1726. ;
  1727. method_head : D_METHOD meth_attr call_conv param_attr type method_name
  1728. formal_typars_clause OPEN_PARENS sig_args CLOSE_PARENS impl_attr
  1729. {
  1730. CallConv cc = (CallConv) $3;
  1731. if ($7 != null)
  1732. cc |= CallConv.Generic;
  1733. MethodDef methdef = new MethodDef (
  1734. codegen, (MethAttr) $2, cc,
  1735. (ImplAttr) $11, (string) $6, (BaseTypeRef) $5,
  1736. (ArrayList) $9, tokenizer.Reader.Location, (GenericParameters) $7, codegen.CurrentTypeDef);
  1737. if (pinvoke_info) {
  1738. ExternModule mod = codegen.ExternTable.AddModule (pinvoke_mod);
  1739. methdef.AddPInvokeInfo (pinvoke_attr, mod, pinvoke_meth);
  1740. pinvoke_info = false;
  1741. }
  1742. }
  1743. | D_METHOD meth_attr call_conv param_attr type
  1744. K_MARSHAL OPEN_PARENS native_type CLOSE_PARENS method_name
  1745. OPEN_PARENS sig_args CLOSE_PARENS impl_attr
  1746. {
  1747. MethodDef methdef = new MethodDef (
  1748. codegen, (MethAttr) $2, (CallConv) $3,
  1749. (ImplAttr) $14, (string) $10, (BaseTypeRef) $5,
  1750. (ArrayList) $12, tokenizer.Reader.Location, null, codegen.CurrentTypeDef);
  1751. if (pinvoke_info) {
  1752. ExternModule mod = codegen.ExternTable.AddModule (pinvoke_mod);
  1753. methdef.AddPInvokeInfo (pinvoke_attr, mod, pinvoke_meth);
  1754. pinvoke_info = false;
  1755. }
  1756. methdef.AddRetTypeMarshalInfo ((NativeType) $8);
  1757. }
  1758. ;
  1759. meth_attr : /* EMPTY */ { $$ = new MethAttr (); }
  1760. | meth_attr K_STATIC { $$ = (MethAttr) $1 | MethAttr.Static; }
  1761. | meth_attr K_PUBLIC { $$ = (MethAttr) $1 | MethAttr.Public; }
  1762. | meth_attr K_PRIVATE { $$ = (MethAttr) $1 | MethAttr.Private; }
  1763. | meth_attr K_FAMILY { $$ = (MethAttr) $1 | MethAttr.Family; }
  1764. | meth_attr K_ASSEMBLY { $$ = (MethAttr) $1 | MethAttr.Assembly; }
  1765. | meth_attr K_FAMANDASSEM { $$ = (MethAttr) $1 | MethAttr.FamAndAssem; }
  1766. | meth_attr K_FAMORASSEM { $$ = (MethAttr) $1 | MethAttr.FamOrAssem; }
  1767. | meth_attr K_PRIVATESCOPE { /* CHECK HEADERS */ }
  1768. | meth_attr K_FINAL { $$ = (MethAttr) $1 | MethAttr.Final; }
  1769. | meth_attr K_VIRTUAL { $$ = (MethAttr) $1 | MethAttr.Virtual; }
  1770. | meth_attr K_ABSTRACT { $$ = (MethAttr) $1 | MethAttr.Abstract; }
  1771. | meth_attr K_HIDEBYSIG { $$ = (MethAttr) $1 | MethAttr.HideBySig; }
  1772. | meth_attr K_NEWSLOT { $$ = (MethAttr) $1 | MethAttr.NewSlot; }
  1773. | meth_attr K_REQSECOBJ { $$ = (MethAttr) $1 | MethAttr.RequireSecObject; }
  1774. | meth_attr K_SPECIALNAME { $$ = (MethAttr) $1 | MethAttr.SpecialName; }
  1775. | meth_attr K_RTSPECIALNAME { $$ = (MethAttr) $1 | MethAttr.RTSpecialName; }
  1776. | meth_attr K_COMPILERCONTROLLED { /* Do nothing */ }
  1777. | meth_attr K_UNMANAGEDEXP
  1778. | meth_attr K_PINVOKEIMPL OPEN_PARENS comp_qstring K_AS
  1779. comp_qstring pinv_attr CLOSE_PARENS
  1780. {
  1781. pinvoke_info = true;
  1782. pinvoke_mod = (string) $4;
  1783. pinvoke_meth = (string) $6;
  1784. pinvoke_attr = (PInvokeAttr) $7;
  1785. }
  1786. | meth_attr K_PINVOKEIMPL OPEN_PARENS comp_qstring pinv_attr CLOSE_PARENS
  1787. {
  1788. pinvoke_info = true;
  1789. pinvoke_mod = (string) $4;
  1790. pinvoke_meth = null;
  1791. pinvoke_attr = (PInvokeAttr) $5;
  1792. }
  1793. | meth_attr K_PINVOKEIMPL OPEN_PARENS pinv_attr CLOSE_PARENS
  1794. {
  1795. pinvoke_info = true;
  1796. pinvoke_mod = null;
  1797. pinvoke_meth = null;
  1798. pinvoke_attr = (PInvokeAttr) $4;
  1799. }
  1800. ;
  1801. pinv_attr : /* EMPTY */ { $$ = new PInvokeAttr (); }
  1802. | pinv_attr K_NOMANGLE { $$ = (PInvokeAttr) $1 | PInvokeAttr.nomangle; }
  1803. | pinv_attr K_ANSI { $$ = (PInvokeAttr) $1 | PInvokeAttr.ansi; }
  1804. | pinv_attr K_UNICODE { $$ = (PInvokeAttr) $1 | PInvokeAttr.unicode; }
  1805. | pinv_attr K_AUTOCHAR { $$ = (PInvokeAttr) $1 | PInvokeAttr.autochar; }
  1806. | pinv_attr K_LASTERR { $$ = (PInvokeAttr) $1 | PInvokeAttr.lasterr; }
  1807. | pinv_attr K_WINAPI { $$ = (PInvokeAttr) $1 | PInvokeAttr.winapi; }
  1808. | pinv_attr K_CDECL { $$ = (PInvokeAttr) $1 | PInvokeAttr.cdecl; }
  1809. | pinv_attr K_STDCALL { $$ = (PInvokeAttr) $1 | PInvokeAttr.stdcall; }
  1810. | pinv_attr K_THISCALL { $$ = (PInvokeAttr) $1 | PInvokeAttr.thiscall; }
  1811. | pinv_attr K_FASTCALL { $$ = (PInvokeAttr) $1 | PInvokeAttr.fastcall; }
  1812. | pinv_attr K_BESTFIT COLON K_ON { $$ = (PInvokeAttr) $1 | PInvokeAttr.bestfit_on; }
  1813. | pinv_attr K_BESTFIT COLON K_OFF { $$ = (PInvokeAttr) $1 | PInvokeAttr.bestfit_off; }
  1814. | pinv_attr K_CHARMAPERROR COLON K_ON { $$ = (PInvokeAttr) $1 | PInvokeAttr.charmaperror_on; }
  1815. | pinv_attr K_CHARMAPERROR COLON K_OFF { $$ = (PInvokeAttr) $1 | PInvokeAttr.charmaperror_off; }
  1816. ;
  1817. method_name : D_CTOR
  1818. | D_CCTOR
  1819. | comp_name
  1820. ;
  1821. param_attr : /* EMPTY */ { $$ = new ParamAttr (); }
  1822. | param_attr OPEN_BRACKET K_IN CLOSE_BRACKET { $$ = (ParamAttr) $1 | ParamAttr.In; }
  1823. | param_attr OPEN_BRACKET K_OUT CLOSE_BRACKET { $$ = (ParamAttr) $1 | ParamAttr.Out; }
  1824. | param_attr OPEN_BRACKET K_OPT CLOSE_BRACKET { $$ = (ParamAttr) $1 | ParamAttr.Opt; }
  1825. ;
  1826. impl_attr : /* EMPTY */ { $$ = new ImplAttr (); }
  1827. | impl_attr K_NATIVE { $$ = (ImplAttr) $1 | ImplAttr.Native; }
  1828. | impl_attr K_CIL { $$ = (ImplAttr) $1 | ImplAttr.IL; }
  1829. | impl_attr K_IL { $$ = (ImplAttr) $1 | ImplAttr.IL; }
  1830. | impl_attr K_OPTIL { $$ = (ImplAttr) $1 | ImplAttr.Optil; }
  1831. | impl_attr K_MANAGED { /* should this reset? */ }
  1832. | impl_attr K_UNMANAGED { $$ = (ImplAttr) $1 | ImplAttr.Unmanaged; }
  1833. | impl_attr K_FORWARDREF { $$ = (ImplAttr) $1 | ImplAttr.ForwardRef; }
  1834. | impl_attr K_PRESERVESIG { $$ = (ImplAttr) $1 | ImplAttr.PreserveSig; }
  1835. | impl_attr K_RUNTIME { $$ = (ImplAttr) $1 | ImplAttr.Runtime; }
  1836. | impl_attr K_INTERNALCALL { $$ = (ImplAttr) $1 | ImplAttr.InternalCall; }
  1837. | impl_attr K_SYNCHRONIZED { $$ = (ImplAttr) $1 | ImplAttr.Synchronised; }
  1838. | impl_attr K_NOINLINING { $$ = (ImplAttr) $1 | ImplAttr.NoInLining; }
  1839. ;
  1840. sig_args : /* EMPTY */
  1841. | sig_arg_list
  1842. ;
  1843. sig_arg_list : sig_arg
  1844. {
  1845. ArrayList sig_list = new ArrayList ();
  1846. sig_list.Add ($1);
  1847. $$ = sig_list;
  1848. }
  1849. | sig_arg_list COMMA sig_arg
  1850. {
  1851. ArrayList sig_list = (ArrayList) $1;
  1852. sig_list.Add ($3);
  1853. $$ = sig_list;
  1854. }
  1855. ;
  1856. sig_arg : param_attr type
  1857. {
  1858. $$ = new ParamDef ((ParamAttr) $1, null, (BaseTypeRef) $2);
  1859. }
  1860. | param_attr type id
  1861. {
  1862. $$ = new ParamDef ((ParamAttr) $1, (string) $3, (BaseTypeRef) $2);
  1863. }
  1864. | ELLIPSIS
  1865. {
  1866. $$ = new ParamDef ((ParamAttr) 0, "...", new SentinelTypeRef ());
  1867. // $$ = ParamDef.Ellipsis;
  1868. }
  1869. | param_attr type K_MARSHAL OPEN_PARENS native_type CLOSE_PARENS
  1870. {
  1871. ParamDef param_def = new ParamDef ((ParamAttr) $1, null, (BaseTypeRef) $2);
  1872. param_def.AddMarshalInfo ((PEAPI.NativeType) $5);
  1873. $$ = param_def;
  1874. }
  1875. | param_attr type K_MARSHAL OPEN_PARENS native_type CLOSE_PARENS id
  1876. {
  1877. ParamDef param_def = new ParamDef ((ParamAttr) $1, (string) $7, (BaseTypeRef) $2);
  1878. param_def.AddMarshalInfo ((PEAPI.NativeType) $5);
  1879. $$ = param_def;
  1880. }
  1881. ;
  1882. type_list : /* EMPTY */
  1883. {
  1884. $$ = new ArrayList (0);
  1885. }
  1886. | ELLIPSIS
  1887. {
  1888. ArrayList type_list = new ArrayList ();
  1889. // type_list.Add (TypeRef.Ellipsis);
  1890. type_list.Add (new SentinelTypeRef ());
  1891. $$ = type_list;
  1892. }
  1893. | type_list COMMA ELLIPSIS
  1894. {
  1895. ArrayList type_list = (ArrayList) $1;
  1896. // type_list.Add (TypeRef.Ellipsis);
  1897. type_list.Add (new SentinelTypeRef ());
  1898. $$ = type_list;
  1899. }
  1900. | param_attr type opt_id
  1901. {
  1902. ArrayList type_list = new ArrayList ();
  1903. type_list.Add ($2);
  1904. $$ = type_list;
  1905. }
  1906. | type_list COMMA param_attr type opt_id
  1907. {
  1908. ArrayList type_list = (ArrayList) $1;
  1909. type_list.Add ($4);
  1910. }
  1911. ;
  1912. opt_id : /* EMPTY */
  1913. | id
  1914. ;
  1915. method_decls : /* EMPTY */
  1916. | method_decls method_decl
  1917. ;
  1918. method_decl : D_EMITBYTE int32
  1919. {
  1920. codegen.CurrentMethodDef.AddInstr (new
  1921. EmitByteInstr ((int) $2, tokenizer.Location));
  1922. }
  1923. | D_MAXSTACK int32
  1924. {
  1925. codegen.CurrentMethodDef.SetMaxStack ((int) $2);
  1926. }
  1927. | D_LOCALS OPEN_PARENS local_list CLOSE_PARENS
  1928. {
  1929. if ($3 != null) {
  1930. codegen.CurrentMethodDef.AddLocals (
  1931. (ArrayList) $3);
  1932. }
  1933. }
  1934. | D_LOCALS K_INIT OPEN_PARENS local_list CLOSE_PARENS
  1935. {
  1936. if ($4 != null) {
  1937. codegen.CurrentMethodDef.AddLocals (
  1938. (ArrayList) $4);
  1939. codegen.CurrentMethodDef.InitLocals ();
  1940. }
  1941. }
  1942. | D_ENTRYPOINT
  1943. {
  1944. codegen.CurrentMethodDef.EntryPoint ();
  1945. codegen.HasEntryPoint = true;
  1946. }
  1947. | D_ZEROINIT
  1948. {
  1949. codegen.CurrentMethodDef.ZeroInit ();
  1950. }
  1951. | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET
  1952. | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET K_AS id
  1953. | D_VTENTRY int32 COLON int32
  1954. | D_OVERRIDE type_spec DOUBLE_COLON method_name
  1955. {
  1956. codegen.CurrentTypeDef.AddOverride (codegen.CurrentMethodDef,
  1957. (BaseTypeRef) $2, (string) $4);
  1958. }
  1959. | D_OVERRIDE K_METHOD method_ref
  1960. {
  1961. codegen.CurrentTypeDef.AddOverride (codegen.CurrentMethodDef.Signature,
  1962. (BaseMethodRef) $3);
  1963. }
  1964. | D_OVERRIDE K_METHOD call_conv type type_spec DOUBLE_COLON method_name
  1965. OPEN_ANGLE_BRACKET OPEN_BRACKET int32 CLOSE_BRACKET CLOSE_ANGLE_BRACKET
  1966. OPEN_PARENS type_list CLOSE_PARENS
  1967. {
  1968. BaseTypeRef owner = (BaseTypeRef) $5;
  1969. ArrayList arg_list = (ArrayList) $14;
  1970. BaseTypeRef[] param_list;
  1971. BaseMethodRef methref;
  1972. if (arg_list != null)
  1973. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  1974. else
  1975. param_list = new BaseTypeRef[0];
  1976. if (owner.UseTypeSpec) {
  1977. methref = new TypeSpecMethodRef (owner, (CallConv) $3, (BaseTypeRef) $4,
  1978. (string) $7, param_list, (int) $10);
  1979. } else {
  1980. methref = owner.GetMethodRef ((BaseTypeRef) $4,
  1981. (CallConv) $3, (string) $7, param_list, (int) $10);
  1982. }
  1983. codegen.CurrentTypeDef.AddOverride (codegen.CurrentMethodDef.Signature,
  1984. methref);
  1985. }
  1986. | scope_block
  1987. | D_PARAM OPEN_BRACKET int32 CLOSE_BRACKET init_opt
  1988. {
  1989. int index = (int) $3;
  1990. ParamDef param = codegen.CurrentMethodDef.GetParam (index);
  1991. codegen.CurrentCustomAttrTarget = param;
  1992. if (param == null) {
  1993. Report.Warning (tokenizer.Location, String.Format ("invalid param index ({0}) with .param", index));
  1994. break;
  1995. }
  1996. if ($5 != null)
  1997. param.AddDefaultValue ((Constant) $5);
  1998. }
  1999. | param_type_decl
  2000. | id COLON
  2001. {
  2002. codegen.CurrentMethodDef.AddLabel ((string) $1);
  2003. }
  2004. | seh_block
  2005. | instr
  2006. | sec_decl
  2007. {
  2008. AddSecDecl ($1, false);
  2009. }
  2010. | extsource_spec
  2011. | language_decl
  2012. | customattr_decl
  2013. {
  2014. if (codegen.CurrentCustomAttrTarget != null)
  2015. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  2016. }
  2017. | data_decl
  2018. ;
  2019. local_list : /* EMPTY */
  2020. | local
  2021. {
  2022. ArrayList local_list = new ArrayList ();
  2023. local_list.Add ($1);
  2024. $$ = local_list;
  2025. }
  2026. | local_list COMMA local
  2027. {
  2028. ArrayList local_list = (ArrayList) $1;
  2029. local_list.Add ($3);
  2030. }
  2031. ;
  2032. local : type
  2033. {
  2034. $$ = new Local (-1, (BaseTypeRef) $1);
  2035. }
  2036. | type id
  2037. {
  2038. $$ = new Local (-1, (string) $2, (BaseTypeRef) $1);
  2039. }
  2040. | slot_num type
  2041. {
  2042. $$ = new Local ((int) $1, (BaseTypeRef) $2);
  2043. }
  2044. | slot_num type id
  2045. {
  2046. $$ = new Local ((int) $1, (string) $3, (BaseTypeRef) $2);
  2047. }
  2048. ;
  2049. slot_num : OPEN_BRACKET int32 CLOSE_BRACKET
  2050. {
  2051. $$ = $2;
  2052. }
  2053. ;
  2054. type_spec : OPEN_BRACKET slashed_name CLOSE_BRACKET
  2055. {
  2056. // This is a reference to a global method in another
  2057. // assembly. This is not supported in the MS version of ilasm
  2058. }
  2059. | OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET
  2060. {
  2061. string module = (string) $3;
  2062. if (codegen.IsThisModule (module)) {
  2063. // This is not handled yet.
  2064. } else {
  2065. $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, "<Module>", false);
  2066. }
  2067. }
  2068. | type
  2069. ;
  2070. scope_block : scope_block_begin method_decls CLOSE_BRACE
  2071. {
  2072. $$ = new HandlerBlock ((LabelInfo) $1,
  2073. codegen.CurrentMethodDef.AddLabel ());
  2074. }
  2075. ;
  2076. scope_block_begin : OPEN_BRACE
  2077. {
  2078. $$ = codegen.CurrentMethodDef.AddLabel ();
  2079. }
  2080. ;
  2081. seh_block : try_block seh_clauses
  2082. {
  2083. TryBlock try_block = (TryBlock) $1;
  2084. ArrayList clause_list = (ArrayList) $2;
  2085. foreach (object clause in clause_list)
  2086. try_block.AddSehClause ((ISehClause) clause);
  2087. codegen.CurrentMethodDef.AddInstr (try_block);
  2088. }
  2089. ;
  2090. try_block : D_TRY scope_block
  2091. {
  2092. $$ = new TryBlock ((HandlerBlock) $2, tokenizer.Location);
  2093. }
  2094. | D_TRY id K_TO id
  2095. {
  2096. LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2);
  2097. LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4);
  2098. $$ = new TryBlock (new HandlerBlock (from, to), tokenizer.Location);
  2099. }
  2100. | D_TRY int32 K_TO int32
  2101. {
  2102. LabelInfo from = codegen.CurrentMethodDef.AddLabel ((int) $2);
  2103. LabelInfo to = codegen.CurrentMethodDef.AddLabel ((int) $4);
  2104. $$ = new TryBlock (new HandlerBlock (from, to), tokenizer.Location);
  2105. }
  2106. ;
  2107. seh_clauses : seh_clause
  2108. {
  2109. ArrayList clause_list = new ArrayList ();
  2110. clause_list.Add ($1);
  2111. $$ = clause_list;
  2112. }
  2113. | seh_clauses seh_clause
  2114. {
  2115. ArrayList clause_list = (ArrayList) $1;
  2116. clause_list.Add ($2);
  2117. }
  2118. ;
  2119. seh_clause : K_CATCH type handler_block
  2120. {
  2121. if ($2.GetType () == typeof (PrimitiveTypeRef))
  2122. Report.Error ("Exception not be of a primitive type.");
  2123. BaseTypeRef type = (BaseTypeRef) $2;
  2124. CatchBlock cb = new CatchBlock (type);
  2125. cb.SetHandlerBlock ((HandlerBlock) $3);
  2126. $$ = cb;
  2127. }
  2128. | K_FINALLY handler_block
  2129. {
  2130. FinallyBlock fb = new FinallyBlock ();
  2131. fb.SetHandlerBlock ((HandlerBlock) $2);
  2132. $$ = fb;
  2133. }
  2134. | K_FAULT handler_block
  2135. {
  2136. FaultBlock fb = new FaultBlock ();
  2137. fb.SetHandlerBlock ((HandlerBlock) $2);
  2138. $$ = fb;
  2139. }
  2140. | filter_clause handler_block
  2141. {
  2142. FilterBlock fb = (FilterBlock) $1;
  2143. fb.SetHandlerBlock ((HandlerBlock) $2);
  2144. }
  2145. ;
  2146. filter_clause : K_FILTER scope_block
  2147. {
  2148. HandlerBlock block = (HandlerBlock) $2;
  2149. FilterBlock fb = new FilterBlock (block);
  2150. $$ = fb;
  2151. }
  2152. | K_FILTER id
  2153. {
  2154. LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2);
  2155. FilterBlock fb = new FilterBlock (new HandlerBlock (from, null));
  2156. $$ = fb;
  2157. }
  2158. | K_FILTER int32
  2159. {
  2160. LabelInfo from = codegen.CurrentMethodDef.AddLabel ((int) $2);
  2161. FilterBlock fb = new FilterBlock (new HandlerBlock (from, null));
  2162. $$ = fb;
  2163. }
  2164. ;
  2165. handler_block : scope_block
  2166. {
  2167. }
  2168. | K_HANDLER id K_TO id
  2169. {
  2170. LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2);
  2171. LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4);
  2172. $$ = new HandlerBlock (from, to);
  2173. }
  2174. | K_HANDLER int32 K_TO int32
  2175. {
  2176. LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2);
  2177. LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4);
  2178. $$ = new HandlerBlock (from, to);
  2179. }
  2180. ;
  2181. instr : INSTR_NONE
  2182. {
  2183. codegen.CurrentMethodDef.AddInstr (
  2184. new SimpInstr ((Op) $1, tokenizer.Location));
  2185. }
  2186. | INSTR_LOCAL int32
  2187. {
  2188. codegen.CurrentMethodDef.AddInstr (
  2189. new IntInstr ((IntOp) $1, (int) $2, tokenizer.Location));
  2190. }
  2191. | INSTR_LOCAL id
  2192. {
  2193. int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2);
  2194. codegen.CurrentMethodDef.AddInstr (
  2195. new IntInstr ((IntOp) $1, slot, tokenizer.Location));
  2196. }
  2197. | INSTR_PARAM int32
  2198. {
  2199. codegen.CurrentMethodDef.AddInstr (
  2200. new IntInstr ((IntOp) $1, (int) $2, tokenizer.Location));
  2201. }
  2202. | INSTR_PARAM id
  2203. {
  2204. int pos = codegen.CurrentMethodDef.GetNamedParamPos ((string) $2);
  2205. if (pos < 0)
  2206. Report.Error (String.Format ("Undeclared identifier '{0}'", (string) $2));
  2207. codegen.CurrentMethodDef.AddInstr (
  2208. new IntInstr ((IntOp) $1, pos, tokenizer.Location));
  2209. }
  2210. | INSTR_I int32
  2211. {
  2212. codegen.CurrentMethodDef.AddInstr (new
  2213. IntInstr ((IntOp) $1, (int) $2, tokenizer.Location));
  2214. }
  2215. | INSTR_I id
  2216. {
  2217. int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2);
  2218. codegen.CurrentMethodDef.AddInstr (new
  2219. IntInstr ((IntOp) $1, slot, tokenizer.Location));
  2220. }
  2221. | INSTR_I8 int64
  2222. {
  2223. if ($1 is MiscInstr) {
  2224. switch ((MiscInstr) $1) {
  2225. case MiscInstr.ldc_i8:
  2226. codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1,
  2227. (long) $2, tokenizer.Location));
  2228. break;
  2229. }
  2230. }
  2231. }
  2232. | INSTR_R float64
  2233. {
  2234. switch ((MiscInstr) $1) {
  2235. case MiscInstr.ldc_r4:
  2236. case MiscInstr.ldc_r8:
  2237. codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, (double) $2, tokenizer.Location));
  2238. break;
  2239. }
  2240. }
  2241. | INSTR_R int64
  2242. {
  2243. long l = (long) $2;
  2244. switch ((MiscInstr) $1) {
  2245. case MiscInstr.ldc_r4:
  2246. case MiscInstr.ldc_r8:
  2247. codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, (double) l, tokenizer.Location));
  2248. break;
  2249. }
  2250. }
  2251. | INSTR_R bytes_list
  2252. {
  2253. byte[] fpdata;
  2254. switch ((MiscInstr) $1) {
  2255. case MiscInstr.ldc_r4:
  2256. fpdata = (byte []) $2;
  2257. if (!BitConverter.IsLittleEndian) {
  2258. System.Array.Reverse (fpdata, 0, 4);
  2259. }
  2260. float s = BitConverter.ToSingle (fpdata, 0);
  2261. codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, s, tokenizer.Location));
  2262. break;
  2263. case MiscInstr.ldc_r8:
  2264. fpdata = (byte []) $2;
  2265. if (!BitConverter.IsLittleEndian) {
  2266. // FIXME: handle the stupid ARM FPA format
  2267. System.Array.Reverse (fpdata, 0, 8);
  2268. }
  2269. double d = BitConverter.ToDouble (fpdata, 0);
  2270. codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, d, tokenizer.Location));
  2271. break;
  2272. }
  2273. }
  2274. | INSTR_BRTARGET int32
  2275. {
  2276. LabelInfo target = codegen.CurrentMethodDef.AddLabel ((int) $2);
  2277. codegen.CurrentMethodDef.AddInstr (new BranchInstr ((BranchOp) $1,
  2278. target, tokenizer.Location));
  2279. }
  2280. | INSTR_BRTARGET id
  2281. {
  2282. LabelInfo target = codegen.CurrentMethodDef.AddLabelRef ((string) $2);
  2283. codegen.CurrentMethodDef.AddInstr (new BranchInstr ((BranchOp) $1,
  2284. target, tokenizer.Location));
  2285. }
  2286. | INSTR_METHOD method_ref
  2287. {
  2288. codegen.CurrentMethodDef.AddInstr (new MethodInstr ((MethodOp) $1,
  2289. (BaseMethodRef) $2, tokenizer.Location));
  2290. }
  2291. | INSTR_FIELD type type_spec DOUBLE_COLON id
  2292. {
  2293. BaseTypeRef owner = (BaseTypeRef) $3;
  2294. GenericParamRef gpr = $2 as GenericParamRef;
  2295. if (gpr != null && codegen.CurrentMethodDef != null)
  2296. codegen.CurrentMethodDef.ResolveGenParam ((PEAPI.GenParam) gpr.PeapiType);
  2297. IFieldRef fieldref = owner.GetFieldRef (
  2298. (BaseTypeRef) $2, (string) $5);
  2299. codegen.CurrentMethodDef.AddInstr (new FieldInstr ((FieldOp) $1, fieldref, tokenizer.Location));
  2300. }
  2301. | INSTR_FIELD type id
  2302. {
  2303. GlobalFieldRef fieldref = codegen.GetGlobalFieldRef ((BaseTypeRef) $2, (string) $3);
  2304. codegen.CurrentMethodDef.AddInstr (new FieldInstr ((FieldOp) $1, fieldref, tokenizer.Location));
  2305. }
  2306. | INSTR_TYPE type_spec
  2307. {
  2308. codegen.CurrentMethodDef.AddInstr (new TypeInstr ((TypeOp) $1,
  2309. (BaseTypeRef) $2, tokenizer.Location));
  2310. }
  2311. | INSTR_STRING comp_qstring
  2312. {
  2313. if ((MiscInstr) $1 == MiscInstr.ldstr)
  2314. codegen.CurrentMethodDef.AddInstr (new LdstrInstr ((string) $2, tokenizer.Location));
  2315. }
  2316. | INSTR_STRING K_BYTEARRAY ASSIGN bytes_list
  2317. {
  2318. byte[] bs = (byte[]) $4;
  2319. if ((MiscInstr) $1 == MiscInstr.ldstr)
  2320. codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs, tokenizer.Location));
  2321. }
  2322. | INSTR_STRING K_BYTEARRAY bytes_list
  2323. {
  2324. byte[] bs = (byte[]) $3;
  2325. if ((MiscInstr) $1 == MiscInstr.ldstr)
  2326. codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs, tokenizer.Location));
  2327. }
  2328. | INSTR_SIG call_conv type OPEN_PARENS type_list CLOSE_PARENS
  2329. {
  2330. ArrayList arg_list = (ArrayList) $5;
  2331. BaseTypeRef[] arg_array = null;
  2332. if (arg_list != null)
  2333. arg_array = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  2334. codegen.CurrentMethodDef.AddInstr (new CalliInstr ((CallConv) $2,
  2335. (BaseTypeRef) $3, arg_array, tokenizer.Location));
  2336. }
  2337. | INSTR_TOK owner_type
  2338. {
  2339. if ((MiscInstr) $1 == MiscInstr.ldtoken) {
  2340. if ($2 is BaseMethodRef)
  2341. codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((BaseMethodRef) $2, tokenizer.Location));
  2342. else if ($2 is IFieldRef)
  2343. codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((IFieldRef) $2, tokenizer.Location));
  2344. else
  2345. codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((BaseTypeRef) $2, tokenizer.Location));
  2346. }
  2347. }
  2348. | INSTR_SWITCH OPEN_PARENS labels CLOSE_PARENS
  2349. {
  2350. codegen.CurrentMethodDef.AddInstr (new SwitchInstr ((ArrayList) $3, tokenizer.Location));
  2351. }
  2352. ;
  2353. method_ref : call_conv type method_name typars_clause
  2354. OPEN_PARENS type_list CLOSE_PARENS
  2355. {
  2356. ArrayList arg_list = (ArrayList) $6;
  2357. GenericArguments ga = (GenericArguments) $4;
  2358. BaseTypeRef[] param_list;
  2359. if (arg_list != null)
  2360. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  2361. else
  2362. param_list = new BaseTypeRef[0];
  2363. BaseMethodRef methref = codegen.GetGlobalMethodRef ((BaseTypeRef) $2, (CallConv) $1,
  2364. (string) $3, param_list, (ga != null ? ga.Count : 0));
  2365. if (ga != null)
  2366. methref = methref.GetGenericMethodRef (ga);
  2367. $$ = methref;
  2368. }
  2369. | call_conv type type_spec DOUBLE_COLON method_name
  2370. typars_clause OPEN_PARENS type_list CLOSE_PARENS
  2371. {
  2372. BaseTypeRef owner = (BaseTypeRef) $3;
  2373. ArrayList arg_list = (ArrayList) $8;
  2374. GenericArguments ga = (GenericArguments) $6;
  2375. BaseTypeRef[] param_list;
  2376. BaseMethodRef methref;
  2377. if (arg_list != null)
  2378. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  2379. else
  2380. param_list = new BaseTypeRef[0];
  2381. if (codegen.IsThisAssembly ("mscorlib")) {
  2382. PrimitiveTypeRef prim = owner as PrimitiveTypeRef;
  2383. if (prim != null && prim.SigMod == "")
  2384. owner = codegen.GetTypeRef (prim.Name);
  2385. }
  2386. if (owner.UseTypeSpec) {
  2387. methref = new TypeSpecMethodRef (owner, (CallConv) $1, (BaseTypeRef) $2,
  2388. (string) $5, param_list, (ga != null ? ga.Count : 0));
  2389. } else {
  2390. methref = owner.GetMethodRef ((BaseTypeRef) $2,
  2391. (CallConv) $1, (string) $5, param_list, (ga != null ? ga.Count : 0));
  2392. }
  2393. if (ga != null)
  2394. methref = methref.GetGenericMethodRef (ga);
  2395. $$ = methref;
  2396. }
  2397. ;
  2398. labels : /* EMPTY */
  2399. | id
  2400. {
  2401. ArrayList label_list = new ArrayList ();
  2402. label_list.Add (codegen.CurrentMethodDef.AddLabelRef ((string) $1));
  2403. $$ = label_list;
  2404. }
  2405. | int32
  2406. {
  2407. ArrayList label_list = new ArrayList ();
  2408. label_list.Add ($1);
  2409. $$ = label_list;
  2410. }
  2411. | labels COMMA id
  2412. {
  2413. ArrayList label_list = (ArrayList) $1;
  2414. label_list.Add (codegen.CurrentMethodDef.AddLabelRef ((string) $3));
  2415. }
  2416. | labels COMMA int32
  2417. {
  2418. ArrayList label_list = (ArrayList) $1;
  2419. label_list.Add ($3);
  2420. }
  2421. ;
  2422. owner_type : type_spec
  2423. | member_ref
  2424. ;
  2425. member_ref : K_METHOD method_ref
  2426. {
  2427. $$ = $2;
  2428. }
  2429. | K_FIELD type type_spec DOUBLE_COLON id
  2430. {
  2431. BaseTypeRef owner = (BaseTypeRef) $3;
  2432. $$ = owner.GetFieldRef (
  2433. (BaseTypeRef) $2, (string) $5);
  2434. }
  2435. | K_FIELD type id
  2436. {
  2437. $$ = codegen.GetGlobalFieldRef ((BaseTypeRef) $2, (string) $3);
  2438. }
  2439. ;
  2440. event_all : event_head OPEN_BRACE event_decls CLOSE_BRACE
  2441. {
  2442. codegen.CurrentTypeDef.EndEventDef ();
  2443. }
  2444. ;
  2445. event_head : D_EVENT event_attr type_spec comp_name
  2446. {
  2447. EventDef event_def = new EventDef ((FeatureAttr) $2,
  2448. (BaseTypeRef) $3, (string) $4);
  2449. codegen.CurrentTypeDef.BeginEventDef (event_def);
  2450. codegen.CurrentCustomAttrTarget = event_def;
  2451. }
  2452. | D_EVENT event_attr id
  2453. ;
  2454. event_attr : /* EMPTY */
  2455. {
  2456. $$ = new FeatureAttr ();
  2457. }
  2458. | event_attr K_RTSPECIALNAME
  2459. {
  2460. $$ = (FeatureAttr) $1 & FeatureAttr.Rtspecialname;
  2461. }
  2462. | event_attr K_SPECIALNAME
  2463. {
  2464. $$ = (FeatureAttr) $1 & FeatureAttr.Specialname;
  2465. }
  2466. ;
  2467. event_decls : /* EMPTY */
  2468. | event_decls event_decl
  2469. ;
  2470. event_decl : D_ADDON method_ref
  2471. {
  2472. codegen.CurrentTypeDef.CurrentEvent.AddAddon (
  2473. (MethodRef) $2);
  2474. }
  2475. | D_REMOVEON method_ref
  2476. {
  2477. codegen.CurrentTypeDef.CurrentEvent.AddRemoveon (
  2478. (MethodRef) $2);
  2479. }
  2480. | D_FIRE method_ref
  2481. {
  2482. codegen.CurrentTypeDef.CurrentEvent.AddFire (
  2483. (MethodRef) $2);
  2484. }
  2485. | D_OTHER method_ref
  2486. {
  2487. codegen.CurrentTypeDef.CurrentEvent.AddOther (
  2488. (MethodRef) $2);
  2489. }
  2490. | customattr_decl
  2491. {
  2492. if (codegen.CurrentCustomAttrTarget != null)
  2493. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  2494. }
  2495. | extsource_spec
  2496. | language_decl
  2497. ;
  2498. prop_all : prop_head OPEN_BRACE prop_decls CLOSE_BRACE
  2499. {
  2500. codegen.CurrentTypeDef.EndPropertyDef ();
  2501. }
  2502. ;
  2503. prop_head : D_PROPERTY prop_attr type comp_name OPEN_PARENS type_list CLOSE_PARENS init_opt
  2504. {
  2505. PropertyDef prop_def = new PropertyDef ((FeatureAttr) $2, (BaseTypeRef) $3,
  2506. (string) $4, (ArrayList) $6);
  2507. codegen.CurrentTypeDef.BeginPropertyDef (prop_def);
  2508. codegen.CurrentCustomAttrTarget = prop_def;
  2509. if ($8 != null) {
  2510. prop_def.AddInitValue ((Constant) $8);
  2511. }
  2512. }
  2513. ;
  2514. prop_attr : /* EMPTY */
  2515. {
  2516. $$ = new FeatureAttr ();
  2517. }
  2518. | prop_attr K_RTSPECIALNAME
  2519. {
  2520. $$ = (FeatureAttr) $1 | FeatureAttr.Rtspecialname;
  2521. }
  2522. | prop_attr K_SPECIALNAME
  2523. {
  2524. $$ = (FeatureAttr) $1 | FeatureAttr.Specialname;
  2525. }
  2526. | prop_attr K_INSTANCE
  2527. {
  2528. $$ = (FeatureAttr) $1 | FeatureAttr.Instance;
  2529. }
  2530. ;
  2531. prop_decls : /* EMPTY */
  2532. | prop_decls prop_decl
  2533. ;
  2534. prop_decl : D_SET method_ref
  2535. {
  2536. codegen.CurrentTypeDef.CurrentProperty.AddSet ((MethodRef) $2);
  2537. }
  2538. | D_GET method_ref
  2539. {
  2540. codegen.CurrentTypeDef.CurrentProperty.AddGet ((MethodRef) $2);
  2541. }
  2542. | D_OTHER method_ref
  2543. {
  2544. codegen.CurrentTypeDef.CurrentProperty.AddOther ((MethodRef) $2);
  2545. }
  2546. | customattr_decl
  2547. {
  2548. if (codegen.CurrentCustomAttrTarget != null)
  2549. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  2550. }
  2551. | extsource_spec
  2552. | language_decl
  2553. ;
  2554. customattr_decl : D_CUSTOM custom_type
  2555. {
  2556. $$ = new CustomAttr ((BaseMethodRef) $2, null);
  2557. }
  2558. | D_CUSTOM custom_type ASSIGN comp_qstring
  2559. | D_CUSTOM custom_type ASSIGN bytes_list
  2560. {
  2561. $$ = new CustomAttr ((BaseMethodRef) $2,
  2562. (byte[]) $4);
  2563. }
  2564. | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type
  2565. | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN comp_qstring
  2566. | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN
  2567. bytes_list
  2568. ;
  2569. custom_type : call_conv type type_spec DOUBLE_COLON method_name OPEN_PARENS type_list CLOSE_PARENS
  2570. {
  2571. BaseTypeRef owner = (BaseTypeRef) $3;
  2572. ArrayList arg_list = (ArrayList) $7;
  2573. BaseTypeRef[] param_list;
  2574. if (arg_list != null)
  2575. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  2576. else
  2577. param_list = new BaseTypeRef[0];
  2578. $$ = owner.GetMethodRef ((BaseTypeRef) $2,
  2579. (CallConv) $1, (string) $5, param_list, 0);
  2580. }
  2581. | call_conv type method_name OPEN_PARENS type_list CLOSE_PARENS
  2582. {
  2583. ArrayList arg_list = (ArrayList) $5;
  2584. BaseTypeRef[] param_list;
  2585. if (arg_list != null)
  2586. param_list = (BaseTypeRef[]) arg_list.ToArray (typeof (BaseTypeRef));
  2587. else
  2588. param_list = new BaseTypeRef[0];
  2589. $$ = codegen.GetGlobalMethodRef ((BaseTypeRef) $2, (CallConv) $1,
  2590. (string) $3, param_list, 0);
  2591. }
  2592. ;
  2593. sec_decl : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PARENS
  2594. {
  2595. $$ = TypeSpecToPermPair ($2, $3, (ArrayList) $5);
  2596. }
  2597. | D_PERMISSION sec_action type_spec
  2598. {
  2599. $$ = TypeSpecToPermPair ($2, $3, null);
  2600. }
  2601. | D_PERMISSIONSET sec_action ASSIGN bytes_list
  2602. {
  2603. System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding ();
  2604. PermissionSetAttribute psa = new PermissionSetAttribute ((System.Security.Permissions.SecurityAction) (short) $2);
  2605. psa.XML = ue.GetString ((byte []) $4);
  2606. $$ = new PermPair ((PEAPI.SecurityAction) $2, psa.CreatePermissionSet ());
  2607. }
  2608. | D_PERMISSIONSET sec_action comp_qstring
  2609. {
  2610. PermissionSetAttribute psa = new PermissionSetAttribute ((System.Security.Permissions.SecurityAction) (short) $2);
  2611. psa.XML = (string) $3;
  2612. $$ = new PermPair ((PEAPI.SecurityAction) $2, psa.CreatePermissionSet ());
  2613. }
  2614. | D_PERMISSIONSET sec_action ASSIGN OPEN_BRACE permissions CLOSE_BRACE
  2615. {
  2616. #if NET_2_0
  2617. $$ = new MIPermissionSet ((PEAPI.SecurityAction) $2, (ArrayList) $5);
  2618. #else
  2619. Report.Error ("Use ilasm2 for 2.0 style declarative security attributes.");
  2620. #endif
  2621. }
  2622. ;
  2623. permissions : permission
  2624. {
  2625. ArrayList list = new ArrayList ();
  2626. list.Add ($1);
  2627. $$ = list;
  2628. }
  2629. | permissions COMMA permission
  2630. {
  2631. ArrayList list = (ArrayList) $1;
  2632. list.Add ($3);
  2633. $$ = list;
  2634. }
  2635. ;
  2636. permission : class_ref ASSIGN OPEN_BRACE permission_members CLOSE_BRACE
  2637. {
  2638. $$ = new MIPermission ((BaseTypeRef) $1, (ArrayList) $4);
  2639. }
  2640. ;
  2641. permission_members : permission_member
  2642. {
  2643. ArrayList list = new ArrayList ();
  2644. list.Add ($1);
  2645. $$ = list;
  2646. }
  2647. | permission_members permission_member
  2648. {
  2649. ArrayList list = (ArrayList) $1;
  2650. list.Add ($2);
  2651. $$ = list;
  2652. }
  2653. ;
  2654. permission_member : prop_or_field primitive_type perm_mbr_nameval_pair
  2655. {
  2656. NameValuePair pair = (NameValuePair) $3;
  2657. $$ = new PermissionMember ((MemberTypes) $1, (BaseTypeRef) $2, pair.Name, pair.Value);
  2658. }
  2659. | prop_or_field K_ENUM class_ref perm_mbr_nameval_pair
  2660. {
  2661. NameValuePair pair = (NameValuePair) $4;
  2662. $$ = new PermissionMember ((MemberTypes) $1, (BaseTypeRef) $3, pair.Name, pair.Value);
  2663. }
  2664. ;
  2665. perm_mbr_nameval_pair : SQSTRING ASSIGN field_init_primitive
  2666. {
  2667. $$ = new NameValuePair ((string) $1, (PEAPI.Constant) $3);
  2668. }
  2669. | SQSTRING ASSIGN K_BYTEARRAY bytes_list
  2670. {
  2671. $$ = new NameValuePair ((string) $1, new ByteArrConst ((byte[]) $4));
  2672. }
  2673. | SQSTRING ASSIGN K_STRING OPEN_PARENS SQSTRING CLOSE_PARENS
  2674. {
  2675. $$ = new NameValuePair ((string) $1, new StringConst ((string) $5));
  2676. }
  2677. ;
  2678. prop_or_field : K_PROPERTY
  2679. {
  2680. $$ = MemberTypes.Property;
  2681. }
  2682. | K_FIELD
  2683. {
  2684. $$ = MemberTypes.Field;
  2685. }
  2686. ;
  2687. nameval_pairs : nameval_pair
  2688. {
  2689. ArrayList pairs = new ArrayList ();
  2690. pairs.Add ($1);
  2691. $$ = pairs;
  2692. }
  2693. | nameval_pairs COMMA nameval_pair
  2694. {
  2695. ArrayList pairs = (ArrayList) $1;
  2696. pairs.Add ($3);
  2697. $$ = pairs;
  2698. }
  2699. ;
  2700. nameval_pair : comp_qstring ASSIGN cavalue
  2701. {
  2702. $$ = new NameValuePair ((string) $1, $3);
  2703. }
  2704. ;
  2705. cavalue : truefalse
  2706. | int32
  2707. | int32 OPEN_PARENS int32 CLOSE_PARENS
  2708. {
  2709. $$ = $3;
  2710. }
  2711. | comp_qstring
  2712. | class_ref OPEN_PARENS K_INT8 COLON int32 CLOSE_PARENS
  2713. {
  2714. $$ = ClassRefToObject ($1, (byte) (int) $5);
  2715. }
  2716. | class_ref OPEN_PARENS K_INT16 COLON int32 CLOSE_PARENS
  2717. {
  2718. $$ = ClassRefToObject ($1, (short) (int) $5);
  2719. }
  2720. | class_ref OPEN_PARENS K_INT32 COLON int32 CLOSE_PARENS
  2721. {
  2722. $$ = ClassRefToObject ($1, (int) $5);
  2723. }
  2724. | class_ref OPEN_PARENS int32 CLOSE_PARENS
  2725. {
  2726. $$ = ClassRefToObject ($1, (int) $3);
  2727. }
  2728. ;
  2729. sec_action : K_REQUEST
  2730. {
  2731. $$ = PEAPI.SecurityAction.Request;
  2732. }
  2733. | K_DEMAND
  2734. {
  2735. $$ = PEAPI.SecurityAction.Demand;
  2736. }
  2737. | K_ASSERT
  2738. {
  2739. $$ = PEAPI.SecurityAction.Assert;
  2740. }
  2741. | K_DENY
  2742. {
  2743. $$ = PEAPI.SecurityAction.Deny;
  2744. }
  2745. | K_PERMITONLY
  2746. {
  2747. $$ = PEAPI.SecurityAction.PermitOnly;
  2748. }
  2749. | K_LINKCHECK
  2750. {
  2751. $$ = PEAPI.SecurityAction.LinkDemand;
  2752. }
  2753. | K_INHERITCHECK
  2754. {
  2755. $$ = PEAPI.SecurityAction.InheritDemand;
  2756. }
  2757. | K_REQMIN
  2758. {
  2759. $$ = PEAPI.SecurityAction.RequestMinimum;
  2760. }
  2761. | K_REQOPT
  2762. {
  2763. $$ = PEAPI.SecurityAction.RequestOptional;
  2764. }
  2765. | K_REQREFUSE
  2766. {
  2767. $$ = PEAPI.SecurityAction.RequestRefuse;
  2768. }
  2769. | K_PREJITGRANT
  2770. {
  2771. $$ = PEAPI.SecurityAction.PreJitGrant;
  2772. }
  2773. | K_PREJITDENY
  2774. {
  2775. $$ = PEAPI.SecurityAction.PreJitDeny;
  2776. }
  2777. | K_NONCASDEMAND
  2778. {
  2779. $$ = PEAPI.SecurityAction.NonCasDemand;
  2780. }
  2781. | K_NONCASLINKDEMAND
  2782. {
  2783. $$ = PEAPI.SecurityAction.NonCasLinkDemand;
  2784. }
  2785. | K_NONCASINHERITANCE
  2786. {
  2787. $$ = PEAPI.SecurityAction.NonCasInheritance;
  2788. }
  2789. /* FIXME: Should we have LinkDemandChoice, InheritDemandChoice and DemandChoice ? */
  2790. ;
  2791. module_head : D_MODULE
  2792. {
  2793. }
  2794. | D_MODULE comp_name
  2795. {
  2796. codegen.SetModuleName ((string) $2);
  2797. }
  2798. | D_MODULE K_EXTERN comp_name
  2799. {
  2800. codegen.ExternTable.AddModule ((string) $3);
  2801. }
  2802. ;
  2803. file_decl : D_FILE file_attr comp_name file_entry D_HASH ASSIGN
  2804. bytes_list file_entry
  2805. {
  2806. codegen.SetFileRef (new FileRef ((string) $3, (byte []) $7, (bool) $2, (bool) $8));
  2807. }
  2808. | D_FILE file_attr comp_name file_entry
  2809. {
  2810. // We need to compute the hash ourselves. :-(
  2811. // AssemblyName an = AssemblyName.GetName ((string) $3);
  2812. }
  2813. ;
  2814. file_attr : /* EMPTY */
  2815. {
  2816. $$ = true;
  2817. }
  2818. | file_attr K_NOMETADATA
  2819. {
  2820. $$ = false;
  2821. }
  2822. ;
  2823. file_entry : /* EMPTY */
  2824. {
  2825. $$ = false;
  2826. }
  2827. | D_ENTRYPOINT
  2828. {
  2829. $$ = true;
  2830. }
  2831. ;
  2832. assembly_all : assembly_head OPEN_BRACE assembly_decls CLOSE_BRACE
  2833. {
  2834. codegen.CurrentCustomAttrTarget = null;
  2835. codegen.CurrentDeclSecurityTarget = null;
  2836. }
  2837. ;
  2838. assembly_head : D_ASSEMBLY asm_attr slashed_name
  2839. {
  2840. codegen.SetThisAssembly ((string) $3, (PEAPI.AssemAttr) $2);
  2841. codegen.CurrentCustomAttrTarget = codegen.ThisAssembly;
  2842. codegen.CurrentDeclSecurityTarget = codegen.ThisAssembly;
  2843. }
  2844. ;
  2845. asm_attr : /* EMPTY */
  2846. {
  2847. $$ = new PEAPI.AssemAttr ();
  2848. }
  2849. /*| asm_attr K_NOAPPDOMAIN
  2850. | asm_attr K_NOPROCESS
  2851. | asm_attr K_NOMACHINE*/
  2852. | asm_attr K_RETARGETABLE
  2853. {
  2854. $$ = ((PEAPI.AssemAttr) $1) | PEAPI.AssemAttr.Retargetable;
  2855. }
  2856. ;
  2857. assembly_decls : /* EMPTY */
  2858. | assembly_decls assembly_decl
  2859. ;
  2860. assembly_decl : D_PUBLICKEY ASSIGN bytes_list
  2861. {
  2862. codegen.ThisAssembly.SetPublicKey ((byte []) $3);
  2863. }
  2864. | D_VER int32 COLON int32 COLON int32 COLON int32
  2865. {
  2866. codegen.ThisAssembly.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8);
  2867. }
  2868. | D_LOCALE comp_qstring
  2869. {
  2870. codegen.ThisAssembly.SetLocale ((string) $2);
  2871. }
  2872. | D_LOCALE ASSIGN bytes_list
  2873. | D_HASH K_ALGORITHM int32
  2874. {
  2875. codegen.ThisAssembly.SetHashAlgorithm ((int) $3);
  2876. }
  2877. | customattr_decl
  2878. {
  2879. codegen.ThisAssembly.AddCustomAttribute ((CustomAttr) $1);
  2880. }
  2881. | sec_decl
  2882. {
  2883. AddSecDecl ($1, true);
  2884. }
  2885. ;
  2886. asm_or_ref_decl : D_PUBLICKEY ASSIGN bytes_list
  2887. | D_VER int32 COLON int32 COLON int32 COLON int32
  2888. | D_LOCALE comp_qstring
  2889. | D_LOCALE ASSIGN bytes_list
  2890. | customattr_decl
  2891. ;
  2892. assemblyref_all : assemblyref_head OPEN_BRACE assemblyref_decls CLOSE_BRACE
  2893. ;
  2894. assemblyref_head : D_ASSEMBLY K_EXTERN asm_attr slashed_name
  2895. {
  2896. System.Reflection.AssemblyName asmb_name =
  2897. new System.Reflection.AssemblyName ();
  2898. asmb_name.Name = (string) $4;
  2899. codegen.BeginAssemblyRef ((string) $4, asmb_name, (PEAPI.AssemAttr) $3);
  2900. }
  2901. | D_ASSEMBLY K_EXTERN asm_attr slashed_name K_AS slashed_name
  2902. {
  2903. System.Reflection.AssemblyName asmb_name =
  2904. new System.Reflection.AssemblyName ();
  2905. asmb_name.Name = (string) $4;
  2906. codegen.BeginAssemblyRef ((string) $6, asmb_name, (PEAPI.AssemAttr) $3);
  2907. }
  2908. ;
  2909. assemblyref_decls : /* EMPTY */
  2910. | assemblyref_decls assemblyref_decl
  2911. ;
  2912. assemblyref_decl : D_VER int32 COLON int32 COLON int32 COLON int32
  2913. {
  2914. codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8);
  2915. }
  2916. | D_PUBLICKEY ASSIGN bytes_list
  2917. {
  2918. codegen.CurrentAssemblyRef.SetPublicKey ((byte []) $3);
  2919. }
  2920. | D_PUBLICKEYTOKEN ASSIGN bytes_list
  2921. {
  2922. codegen.CurrentAssemblyRef.SetPublicKeyToken ((byte []) $3);
  2923. }
  2924. | D_LOCALE comp_qstring
  2925. {
  2926. codegen.CurrentAssemblyRef.SetLocale ((string) $2);
  2927. }
  2928. | D_LOCALE ASSIGN bytes_list
  2929. | D_HASH ASSIGN bytes_list
  2930. {
  2931. codegen.CurrentAssemblyRef.SetHash ((byte []) $3);
  2932. }
  2933. | customattr_decl
  2934. {
  2935. if (codegen.CurrentCustomAttrTarget != null)
  2936. codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1);
  2937. }
  2938. ;
  2939. exptype_all : exptype_head OPEN_BRACE exptype_decls CLOSE_BRACE
  2940. ;
  2941. exptype_head : D_CLASS K_EXTERN expt_attr comp_name
  2942. ;
  2943. expt_attr : /* EMPTY */
  2944. | expt_attr K_PRIVATE
  2945. | expt_attr K_PUBLIC
  2946. | expt_attr K_NESTED K_PUBLIC
  2947. | expt_attr K_NESTED K_PRIVATE
  2948. | expt_attr K_NESTED K_FAMILY
  2949. | expt_attr K_NESTED K_ASSEMBLY
  2950. | expt_attr K_NESTED K_FAMANDASSEM
  2951. | expt_attr K_NESTED K_FAMORASSEM
  2952. ;
  2953. exptype_decls : /* EMPTY */
  2954. | exptype_decls exptype_decl
  2955. ;
  2956. exptype_decl : D_FILE comp_name
  2957. | D_CLASS K_EXTERN comp_name
  2958. | D_CLASS int32
  2959. | customattr_decl
  2960. ;
  2961. manifestres_all : manifestres_head OPEN_BRACE manifestres_decls CLOSE_BRACE
  2962. ;
  2963. manifestres_head : D_MRESOURCE manres_attr comp_name
  2964. {
  2965. FileStream s = new FileStream ((string) $3, FileMode.Open, FileAccess.Read);
  2966. byte [] buff = new byte [s.Length];
  2967. s.Read (buff, 0, (int) s.Length);
  2968. s.Close ();
  2969. codegen.AddManifestResource (new ManifestResource ((string) $3, buff, ($2 == null) ? 0 : (uint) $2));
  2970. }
  2971. ;
  2972. manres_attr : /* EMPTY */
  2973. | manres_attr K_PUBLIC { $$ = ManifestResource.PublicResource; }
  2974. | manres_attr K_PRIVATE { $$ = ManifestResource.PrivateResource; }
  2975. ;
  2976. manifestres_decls : /* EMPTY */
  2977. | manifestres_decls manifestres_decl
  2978. ;
  2979. manifestres_decl : D_FILE comp_name K_AT int32
  2980. | D_ASSEMBLY K_EXTERN slashed_name
  2981. | customattr_decl
  2982. ;
  2983. comp_qstring : QSTRING
  2984. | comp_qstring PLUS QSTRING { $$ = String.Format ("{0}{1}", $1, $3); }
  2985. ;
  2986. int32 : INT64
  2987. {
  2988. long l = (long) $1;
  2989. byte[] intb = BitConverter.GetBytes (l);
  2990. $$ = BitConverter.ToInt32 (intb, BitConverter.IsLittleEndian ? 0 : 4);
  2991. }
  2992. ;
  2993. int64 : INT64
  2994. ;
  2995. float64 : FLOAT64
  2996. | K_FLOAT32 OPEN_PARENS INT32 CLOSE_PARENS
  2997. {
  2998. int i = (int) $3;
  2999. byte[] intb = BitConverter.GetBytes (i);
  3000. $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);
  3001. }
  3002. | K_FLOAT32 OPEN_PARENS INT64 CLOSE_PARENS
  3003. {
  3004. long l = (long) $3;
  3005. byte[] intb = BitConverter.GetBytes (l);
  3006. $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);
  3007. }
  3008. | K_FLOAT64 OPEN_PARENS INT64 CLOSE_PARENS
  3009. {
  3010. byte[] intb = BitConverter.GetBytes ((long) $3);
  3011. $$ = BitConverter.ToDouble (intb, BitConverter.IsLittleEndian ? 0 : 4);
  3012. }
  3013. | K_FLOAT64 OPEN_PARENS INT32 CLOSE_PARENS
  3014. {
  3015. byte[] intb = BitConverter.GetBytes ((int) $3);
  3016. $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);
  3017. }
  3018. ;
  3019. hexbyte : HEXBYTE { }
  3020. ;
  3021. bytes_list : OPEN_PARENS
  3022. {
  3023. tokenizer.InByteArray = true;
  3024. }
  3025. bytes CLOSE_PARENS
  3026. {
  3027. $$ = $3;
  3028. tokenizer.InByteArray = false;
  3029. }
  3030. ;
  3031. bytes : /* EMPTY */ { $$ = new byte[0]; }
  3032. | hexbytes
  3033. {
  3034. ArrayList byte_list = (ArrayList) $1;
  3035. $$ = byte_list.ToArray (typeof (byte));
  3036. }
  3037. ;
  3038. hexbytes : hexbyte
  3039. {
  3040. ArrayList byte_list = new ArrayList ();
  3041. byte_list.Add (Convert.ToByte ($1));
  3042. $$ = byte_list;
  3043. }
  3044. | hexbytes hexbyte
  3045. {
  3046. ArrayList byte_list = (ArrayList) $1;
  3047. byte_list.Add (Convert.ToByte ($2));
  3048. }
  3049. ;
  3050. truefalse : K_TRUE
  3051. {
  3052. $$ = true;
  3053. }
  3054. | K_FALSE
  3055. {
  3056. $$ = false;
  3057. }
  3058. ;
  3059. id : ID
  3060. | SQSTRING
  3061. ;
  3062. comp_name : id
  3063. | comp_name DOT comp_name
  3064. {
  3065. $$ = (string) $1 + '.' + (string) $3;
  3066. }
  3067. | COMP_NAME
  3068. ;
  3069. %%
  3070. }