Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1215 lines
27 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. /* Copyright (C) Microsoft Corporation, 1997-1998. All rights reserved. */
  3. %type <XType> DefinedType
  4. %type <XValueSet> ValueSet<XType>
  5. %type <XType> Type
  6. %type <XType> UndirectivedType
  7. %type <XType> UntaggedType
  8. %type <XType> ConstrainableType
  9. %type <XConstraints> Constraint_ESeq<XType>
  10. %type <XType> BuiltinType
  11. %type <XType> ReferencedType
  12. %type <XNamedType> NamedType
  13. %type <XType> BooleanType
  14. %type <XType> IntegerType
  15. %type <XNamedNumbers> NamedNumberList
  16. %type <XNamedNumbers> NamedNumber
  17. %type <XType> EnumeratedType
  18. %type <XNamedNumbers> Enumerations
  19. %type <XNamedNumbers> EnumerationExtension
  20. %type <XNamedNumbers> Enumeration
  21. %type <XNamedNumbers> EnumerationItem
  22. %type <XType> RealType
  23. %type <XType> BitStringType
  24. %type <XNamedNumbers> NamedBitList
  25. %type <XNamedNumbers> NamedBit
  26. %type <XType> OctetStringType
  27. %type <XType> UTF8StringType
  28. %type <XType> NullType
  29. %type <XType> SequenceType
  30. %type <XComponents> ExtensionAndException
  31. %type <XComponents> ExtendedComponentTypeList
  32. %type <XComponents> ComponentTypeListExtension
  33. %type <XComponents> AdditionalComponentTypeList
  34. %type <XComponents> ComponentTypeList
  35. %type <XComponents> ComponentType
  36. %type <XComponents> ComponentTypePostfix<XType>
  37. %type <XType> SequenceOfType
  38. %type <XType> SetType
  39. %type <XType> SetOfType
  40. %type <XType> ChoiceType
  41. %type <XType> AnyType
  42. %type <XComponents> ExtendedAlternativeTypeList
  43. %type <XComponents> AlternativeTypeListExtension
  44. %type <XComponents> AdditionalAlternativeTypeList
  45. %type <XComponents> AlternativeTypeList
  46. %type <XType> SelectionType
  47. %type <XType> TaggedType
  48. %type <XTagType> TagType
  49. %type <XTags> Tag
  50. %type <XValue> ClassNumber
  51. %type <XTagClass> Class
  52. %type <XType> ObjectIdentifierType
  53. %type <XType> EmbeddedPDVType
  54. %type <XType> ExternalType
  55. %type <XType> CharacterStringType
  56. %type <XType> RestrictedCharacterStringType
  57. %type <XType> UnrestrictedCharacterStringType
  58. %type <XType> UsefulType
  59. %type <XType> TypeWithConstraint
  60. %%
  61. DefinedType
  62. : Externaltypereference
  63. { $$ = $1;
  64. }
  65. | typereference
  66. { $$ = $1;
  67. }
  68. | ParameterizedType
  69. { MyAbort();
  70. }
  71. | ParameterizedValueSetType
  72. { MyAbort();
  73. }
  74. ;
  75. TypeAssignment
  76. : typereference "::=" Type PrivateDirectives
  77. {
  78. PropagatePrivateDirectives($3, $4);
  79. if (!AssignType(&$>>.Assignments, $1, $3))
  80. LLFAILED((&@1, "Type `%s' twice defined",
  81. $1->U.Reference.Identifier));
  82. ($>>.Assignments)->eDefTagType = g_eDefTagType;
  83. }
  84. ;
  85. ValueSetTypeAssignment
  86. : typereference Type "::=" ValueSet($2)
  87. { Type_t *type;
  88. type = GetTypeOfValueSet($>>.Assignments, $4);
  89. if (!AssignType(&$>>.Assignments, $1, type))
  90. LLFAILED((&@1, "Type `%s' twice defined",
  91. $1->U.Reference.Identifier));
  92. }
  93. ;
  94. ValueSet(type)
  95. : '{' ElementSetSpec($type, NULL, 0) '}'
  96. { $$ = NewValueSet();
  97. $$->Elements = $2;
  98. $$->Type = $type;
  99. }
  100. ;
  101. Type
  102. : LocalTypeDirectiveESeq UndirectivedType LocalTypeDirectiveESeq
  103. { Directive_t **dd, *d;
  104. if ($1 || $3) {
  105. $$ = DupType($2);
  106. dd = &$$->Directives;
  107. for (d = $1; d; d = d->Next) {
  108. *dd = DupDirective(d);
  109. dd = &(*dd)->Next;
  110. }
  111. for (d = $3; d; d = d->Next) {
  112. *dd = DupDirective(d);
  113. dd = &(*dd)->Next;
  114. }
  115. *dd = $2->Directives;
  116. } else {
  117. $$ = $2;
  118. }
  119. }
  120. ;
  121. UndirectivedType
  122. : UntaggedType
  123. { $$ = $1;
  124. }
  125. | TaggedType
  126. { $$ = $1;
  127. }
  128. ;
  129. UntaggedType
  130. : ConstrainableType
  131. { $$ = $1;
  132. }
  133. | SequenceOfType
  134. { $$ = $1;
  135. }
  136. | SetOfType
  137. { $$ = $1;
  138. }
  139. | TypeWithConstraint
  140. { $$ = $1;
  141. }
  142. ;
  143. ConstrainableType
  144. : BuiltinType LocalTypeDirectiveESeq PrivateDirectives Constraint_ESeq($1)
  145. LocalTypeDirectiveESeq PrivateDirectives
  146. { Directive_t *d, **dd;
  147. if ($2 || $4 || $5) {
  148. $$ = DupType($1);
  149. IntersectConstraints(&$$->Constraints,
  150. $1->Constraints, $4);
  151. dd = &$$->Directives;
  152. for (d = $2; d; d = d->Next) {
  153. *dd = DupDirective(d);
  154. dd = &(*dd)->Next;
  155. }
  156. for (d = $5; d; d = d->Next) {
  157. *dd = DupDirective(d);
  158. dd = &(*dd)->Next;
  159. }
  160. *dd = NULL;
  161. } else {
  162. $$ = ($3 || $6) ? DupType($1) : $1;
  163. }
  164. PropagatePrivateDirectives($$, $3);
  165. PropagatePrivateDirectives($$, $6);
  166. }
  167. | ReferencedType LocalTypeDirectiveESeq PrivateDirectives Constraint_ESeq($1)
  168. LocalTypeDirectiveESeq PrivateDirectives
  169. { Directive_t *d, **dd;
  170. if ($2 || $4 || $5) {
  171. $$ = DupType($1);
  172. IntersectConstraints(&$$->Constraints,
  173. $1->Constraints, $4);
  174. dd = &$$->Directives;
  175. for (d = $2; d; d = d->Next) {
  176. *dd = DupDirective(d);
  177. dd = &(*dd)->Next;
  178. }
  179. for (d = $5; d; d = d->Next) {
  180. *dd = DupDirective(d);
  181. dd = &(*dd)->Next;
  182. }
  183. *dd = NULL;
  184. } else {
  185. $$ = ($3 || $6) ? DupType($1) : $1;
  186. }
  187. PropagatePrivateDirectives($$, $3);
  188. PropagatePrivateDirectives($$, $6);
  189. }
  190. ;
  191. Constraint_ESeq(type)
  192. : Constraint($type, 0) Constraint_ESeq($type)
  193. { if ($2) {
  194. IntersectConstraints(&$$, $1, $2);
  195. } else {
  196. $$ = $1;
  197. }
  198. }
  199. | /* empty */
  200. { $$ = NULL;
  201. }
  202. ;
  203. BuiltinType
  204. : BitStringType
  205. { $$ = $1;
  206. }
  207. | BooleanType
  208. { $$ = $1;
  209. }
  210. | CharacterStringType
  211. { $$ = $1;
  212. }
  213. | ChoiceType
  214. { $$ = $1;
  215. }
  216. | EmbeddedPDVType
  217. { $$ = $1;
  218. }
  219. | EnumeratedType
  220. { $$ = $1;
  221. }
  222. | ExternalType
  223. { $$ = $1;
  224. }
  225. | InstanceOfType
  226. { $$ = $1;
  227. }
  228. | IntegerType
  229. { $$ = $1;
  230. }
  231. | NullType
  232. { $$ = $1;
  233. }
  234. | ObjectClassFieldType
  235. { $$ = $1;
  236. }
  237. | ObjectIdentifierType
  238. { $$ = $1;
  239. }
  240. | OctetStringType
  241. { $$ = $1;
  242. }
  243. | UTF8StringType
  244. { $$ = $1;
  245. }
  246. | RealType
  247. { $$ = $1;
  248. }
  249. | SequenceType
  250. { $$ = $1;
  251. }
  252. | SetType
  253. { $$ = $1;
  254. }
  255. | AnyType
  256. { $$ = $1;
  257. }
  258. | MacroDefinedType
  259. { $$ = $1;
  260. }
  261. ;
  262. ReferencedType
  263. : DefinedType
  264. { $$ = $1;
  265. }
  266. | UsefulType
  267. { $$ = $1;
  268. }
  269. | SelectionType
  270. { $$ = $1;
  271. }
  272. | TypeFromObject
  273. { $$ = $1;
  274. }
  275. | ValueSetFromObjects
  276. { $$ = GetTypeOfValueSet($>>.Assignments, $1);
  277. }
  278. ;
  279. NamedType
  280. : identifier Type
  281. {
  282. $$ = NewNamedType($2->PrivateDirectives.pszFieldName ? $2->PrivateDirectives.pszFieldName : $1, $2);
  283. $2->PrivateDirectives.pszFieldName = NULL;
  284. }
  285. | identifier '<' Type
  286. { Type_t *type;
  287. type = NewType(eType_Selection);
  288. type->U.Selection.Type = $3;
  289. type->U.Selection.Identifier = $1;
  290. $$ = NewNamedType($3->PrivateDirectives.pszFieldName ? $3->PrivateDirectives.pszFieldName : $1, type);
  291. $3->PrivateDirectives.pszFieldName = NULL;
  292. }
  293. ;
  294. BooleanType
  295. : "BOOLEAN"
  296. { $$ = Builtin_Type_Boolean;
  297. }
  298. ;
  299. IntegerType
  300. : "INTEGER" '{' NamedNumberList '}'
  301. { NamedNumber_t *n, *m;
  302. for (n = $3; n && n->Next; n = n->Next) {
  303. for (m = n->Next; m; m = m->Next) {
  304. if (n->Type == eNamedNumber_Normal &&
  305. m->Type == eNamedNumber_Normal) {
  306. if (!strcmp(n->U.Normal.Identifier,
  307. m->U.Normal.Identifier))
  308. LLFAILED((&@3,
  309. "identifier `%s' has been assigned twice",
  310. n->U.Normal.Identifier));
  311. if (GetValue($>>.Assignments, n->U.Normal.Value) &&
  312. GetValue($>>.Assignments, m->U.Normal.Value) &&
  313. GetTypeType($>>.Assignments,
  314. GetValue($>>.Assignments, n->U.Normal.Value)->Type)
  315. == eType_Integer &&
  316. GetTypeType($>>.Assignments,
  317. GetValue($>>.Assignments, m->U.Normal.Value)->Type)
  318. == eType_Integer &&
  319. !intx_cmp(&GetValue($>>.Assignments,
  320. n->U.Normal.Value)->U.Integer.Value,
  321. &GetValue($>>.Assignments,
  322. m->U.Normal.Value)->U.Integer.Value))
  323. LLFAILED((&@3,
  324. "value `%d' has been assigned twice",
  325. intx2int32(&GetValue($>>.Assignments,
  326. n->U.Normal.Value)->U.Integer.Value)));
  327. }
  328. }
  329. }
  330. $$ = NewType(eType_Integer);
  331. $$->ExtensionDefault = $>>.ExtensionDefault;
  332. $$->U.Integer.NamedNumbers = $3;
  333. }
  334. | "INTEGER"
  335. { $$ = NewType(eType_Integer);
  336. $$->ExtensionDefault = $>>.ExtensionDefault;
  337. }
  338. ;
  339. NamedNumberList
  340. : NamedNumber ',' NamedNumberList
  341. { $$ = DupNamedNumber($1);
  342. $$->Next = $3;
  343. }
  344. | NamedNumber
  345. { $$ = $1;
  346. }
  347. ;
  348. NamedNumber
  349. : identifier '(' SignedNumber(Builtin_Type_Integer) ')'
  350. { $$ = NewNamedNumber(eNamedNumber_Normal);
  351. $$->U.Normal.Identifier = $1;
  352. $$->U.Normal.Value = $3;
  353. }
  354. | identifier '(' DefinedValue ')'
  355. { Value_t *v;
  356. v = GetValue($>>.Assignments, $3);
  357. if (v) {
  358. if (GetTypeType($>>.Assignments, v->Type) != eType_Undefined &&
  359. GetTypeType($>>.Assignments, v->Type) != eType_Integer)
  360. LLFAILED((&@3, "Bad type of value"));
  361. if (GetTypeType($>>.Assignments, v->Type) != eType_Integer &&
  362. intx_cmp(&v->U.Integer.Value, &intx_0) < 0)
  363. LLFAILED((&@3, "Bad value"));
  364. }
  365. $$ = NewNamedNumber(eNamedNumber_Normal);
  366. $$->U.Normal.Identifier = $1;
  367. $$->U.Normal.Value = $3;
  368. }
  369. ;
  370. EnumeratedType
  371. : "ENUMERATED" '{' Enumerations '}'
  372. { NamedNumber_t **nn, *n, *m;
  373. intx_t *ix;
  374. uint32_t num = 0;
  375. $$ = NewType(eType_Enumerated);
  376. $$->ExtensionDefault = $>>.ExtensionDefault;
  377. for (n = $3; n; n = n->Next)
  378. if (n->Type == eNamedNumber_Normal)
  379. KeepEnumNames(n->U.Normal.Identifier); // global conflict check
  380. for (n = $3; n && n->Next; n = n->Next) {
  381. if (n->Type != eNamedNumber_Normal)
  382. continue;
  383. for (m = n->Next; m; m = m->Next) {
  384. if (m->Type != eNamedNumber_Normal)
  385. continue;
  386. if (!strcmp(n->U.Normal.Identifier,
  387. m->U.Normal.Identifier))
  388. LLFAILED((&@3,
  389. "identifier `%s' has been assigned twice",
  390. n->U.Normal.Identifier));
  391. if (GetValue($>>.Assignments, n->U.Normal.Value) &&
  392. GetValue($>>.Assignments, m->U.Normal.Value) &&
  393. GetTypeType($>>.Assignments,
  394. GetValue($>>.Assignments, n->U.Normal.Value)->Type)
  395. == eType_Integer &&
  396. GetTypeType($>>.Assignments,
  397. GetValue($>>.Assignments, m->U.Normal.Value)->Type)
  398. == eType_Integer &&
  399. !intx_cmp(&GetValue($>>.Assignments,
  400. n->U.Normal.Value)->U.Integer.Value,
  401. &GetValue($>>.Assignments,
  402. m->U.Normal.Value)->U.Integer.Value))
  403. LLFAILED((&@3,
  404. "value `%d' has been assigned twice",
  405. intx2int32(&GetValue($>>.Assignments,
  406. n->U.Normal.Value)->U.Integer.Value)));
  407. }
  408. }
  409. nn = &$$->U.Enumerated.NamedNumbers;
  410. for (n = $3; n; n = n->Next) {
  411. *nn = DupNamedNumber(n);
  412. switch (n->Type) {
  413. case eNamedNumber_Normal:
  414. if (n->U.Normal.Value)
  415. break;
  416. for (;; num++) {
  417. for (m = $3; m; m = m->Next) {
  418. switch (m->Type) {
  419. case eNamedNumber_Normal:
  420. if (!m->U.Normal.Value)
  421. continue;
  422. ix = &GetValue($>>.Assignments,
  423. m->U.Normal.Value)->U.Integer.Value;
  424. if (!intxisuint32(ix) ||
  425. intx2uint32(ix) != num)
  426. continue;
  427. break;
  428. default:
  429. continue;
  430. }
  431. break;
  432. }
  433. if (!m)
  434. break;
  435. }
  436. (*nn)->U.Normal.Value = NewValue(NULL,
  437. Builtin_Type_Integer);
  438. intx_setuint32(
  439. &(*nn)->U.Normal.Value->U.Integer.Value,
  440. num++);
  441. break;
  442. case eNamedNumber_ExtensionMarker:
  443. break;
  444. }
  445. nn = &(*nn)->Next;
  446. }
  447. *nn = NULL;
  448. }
  449. ;
  450. Enumerations
  451. : Enumeration EnumerationExtension
  452. { NamedNumber_t **nn, *n;
  453. nn = &$$;
  454. for (n = $1; n; n = n->Next) {
  455. *nn = DupNamedNumber(n);
  456. nn = &(*nn)->Next;
  457. }
  458. *nn = $2;
  459. }
  460. ;
  461. EnumerationExtension
  462. : ',' "..." ',' Enumeration
  463. { $$ = NewNamedNumber(eNamedNumber_ExtensionMarker);
  464. $$->Next = $4;
  465. }
  466. | ',' "..."
  467. { $$ = NewNamedNumber(eNamedNumber_ExtensionMarker);
  468. }
  469. | /* empty */
  470. { $$ = NULL;
  471. }
  472. ;
  473. Enumeration
  474. : EnumerationItem ',' Enumeration
  475. { $$ = DupNamedNumber($1);
  476. $$->Next = $3;
  477. }
  478. | EnumerationItem
  479. { $$ = $1;
  480. }
  481. ;
  482. EnumerationItem
  483. : identifier
  484. { $$ = NewNamedNumber(eNamedNumber_Normal);
  485. $$->U.Normal.Identifier = $1;
  486. }
  487. | NamedNumber
  488. { $$ = $1;
  489. }
  490. ;
  491. RealType
  492. : "REAL"
  493. { $$ = Builtin_Type_Real;
  494. }
  495. ;
  496. BitStringType
  497. : "BIT" "STRING" '{' NamedBitList '}'
  498. { NamedNumber_t *n, *m;
  499. $$ = NewType(eType_BitString);
  500. $$->ExtensionDefault = $>>.ExtensionDefault;
  501. $$->U.BitString.NamedNumbers = $4;
  502. for (n = $4; n; n = n->Next)
  503. KeepEnumNames(n->U.Normal.Identifier); // global conflict check
  504. for (n = $4; n && n->Next; n = n->Next) {
  505. for (m = n->Next; m; m = m->Next) {
  506. if (!strcmp(n->U.Normal.Identifier,
  507. m->U.Normal.Identifier))
  508. LLFAILED((&@4,
  509. "identifier `%s' has been assigned twice",
  510. n->U.Normal.Identifier));
  511. if (GetValue($>>.Assignments, n->U.Normal.Value) &&
  512. GetValue($>>.Assignments, m->U.Normal.Value) &&
  513. GetTypeType($>>.Assignments,
  514. GetValue($>>.Assignments, n->U.Normal.Value)->Type)
  515. == eType_Integer &&
  516. GetTypeType($>>.Assignments,
  517. GetValue($>>.Assignments, m->U.Normal.Value)->Type)
  518. == eType_Integer &&
  519. !intx_cmp(&GetValue($>>.Assignments,
  520. n->U.Normal.Value)->U.Integer.Value,
  521. &GetValue($>>.Assignments,
  522. m->U.Normal.Value)->U.Integer.Value))
  523. LLFAILED((&@4,
  524. "value `%u' has been assigned twice",
  525. intx2uint32(&GetValue($>>.Assignments,
  526. n->U.Normal.Value)->U.Integer.Value)));
  527. }
  528. }
  529. }
  530. | "BIT" "STRING"
  531. { $$ = NewType(eType_BitString);
  532. $$->ExtensionDefault = $>>.ExtensionDefault;
  533. }
  534. ;
  535. NamedBitList
  536. : NamedBit ',' NamedBitList
  537. { $$ = DupNamedNumber($1);
  538. $$->Next = $3;
  539. }
  540. | NamedBit
  541. { $$ = $1;
  542. }
  543. ;
  544. NamedBit
  545. : identifier '(' number ')'
  546. { $$ = NewNamedNumber(eNamedNumber_Normal);
  547. $$->U.Normal.Identifier = $1;
  548. $$->U.Normal.Value = NewValue(NULL, Builtin_Type_Integer);
  549. $$->U.Normal.Value->U.Integer.Value = $3;
  550. }
  551. | identifier '(' DefinedValue ')'
  552. { Value_t *v;
  553. v = GetValue($>>.Assignments, $3);
  554. if (v) {
  555. if (GetTypeType($>>.Assignments, v->Type) != eType_Undefined &&
  556. GetTypeType($>>.Assignments, v->Type) != eType_Integer)
  557. LLFAILED((&@3, "Bad type of value"));
  558. if (GetTypeType($>>.Assignments, v->Type) == eType_Integer &&
  559. intx_cmp(&v->U.Integer.Value, &intx_0) < 0)
  560. LLFAILED((&@3, "Bad value"));
  561. }
  562. $$ = NewNamedNumber(eNamedNumber_Normal);
  563. $$->U.Normal.Identifier = $1;
  564. $$->U.Normal.Value = $3;
  565. }
  566. ;
  567. OctetStringType
  568. : "OCTET" "STRING"
  569. { $$ = Builtin_Type_OctetString;
  570. }
  571. ;
  572. UTF8StringType
  573. : "UTF8String"
  574. { $$ = Builtin_Type_UTF8String;
  575. }
  576. ;
  577. NullType
  578. : "NULL"
  579. { $$ = Builtin_Type_Null;
  580. }
  581. ;
  582. SequenceType
  583. : "SEQUENCE" '{' ExtendedComponentTypeList '}'
  584. { Component_t *c, *d; int fExtended = 0;
  585. for (c = $3; c; c = c->Next)
  586. if (c->Type == eComponent_Optional || c->Type == eComponent_Default || fExtended)
  587. KeepOptNames(c->U.NOD.NamedType->Identifier); // global conflict check
  588. else
  589. if (c->Type == eComponent_ExtensionMarker)
  590. fExtended = 1;
  591. for (c = $3; c && c->Next; c = c->Next) {
  592. if (c->Type != eComponent_Normal &&
  593. c->Type != eComponent_Optional &&
  594. c->Type != eComponent_Default)
  595. continue;
  596. for (d = c->Next; d; d = d->Next) {
  597. if (d->Type != eComponent_Normal &&
  598. d->Type != eComponent_Optional &&
  599. d->Type != eComponent_Default)
  600. continue;
  601. if (!strcmp(c->U.NOD.NamedType->Identifier,
  602. d->U.NOD.NamedType->Identifier))
  603. LLFAILED((&@3, "Component `%s' has been used twice",
  604. c->U.NOD.NamedType->Identifier));
  605. }
  606. }
  607. $$ = NewType(eType_Sequence);
  608. $$->TagDefault = $>>.TagDefault;
  609. $$->ExtensionDefault = $>>.ExtensionDefault;
  610. $$->U.Sequence.Components = $3;
  611. }
  612. | "SEQUENCE" '{' '}'
  613. { $$ = NewType(eType_Sequence);
  614. $$->ExtensionDefault = $>>.ExtensionDefault;
  615. }
  616. ;
  617. ExtensionAndException
  618. : "..." ExceptionSpec
  619. { $$ = NewComponent(eComponent_ExtensionMarker);
  620. /*$$->U.ExtensionMarker.ExceptionSpec = $2;*/
  621. }
  622. | "..."
  623. { $$ = NewComponent(eComponent_ExtensionMarker);
  624. }
  625. ;
  626. ExtendedComponentTypeList
  627. : ComponentTypeList ComponentTypeListExtension
  628. { Component_t **cc, *c;
  629. if ($2) {
  630. cc = &$$;
  631. for (c = $1; c; c = c->Next) {
  632. *cc = DupComponent(c);
  633. cc = &(*cc)->Next;
  634. }
  635. *cc = $2;
  636. } else {
  637. $$ = $1;
  638. }
  639. }
  640. | ExtensionAndException
  641. AdditionalComponentTypeList
  642. { Component_t **cc, *c;
  643. if ($2) {
  644. cc = &$$;
  645. for (c = $1; c; c = c->Next) {
  646. *cc = DupComponent(c);
  647. cc = &(*cc)->Next;
  648. }
  649. *cc = $2;
  650. } else {
  651. $$ = $1;
  652. }
  653. }
  654. ;
  655. ComponentTypeListExtension
  656. : ',' ExtensionAndException AdditionalComponentTypeList
  657. { Component_t **cc, *c;
  658. if ($3) {
  659. cc = &$$;
  660. for (c = $2; c; c = c->Next) {
  661. *cc = DupComponent(c);
  662. cc = &(*cc)->Next;
  663. }
  664. *cc = $3;
  665. } else {
  666. $$ = $2;
  667. }
  668. }
  669. | /* empty */
  670. { $$ = NULL;
  671. }
  672. ;
  673. AdditionalComponentTypeList
  674. : ',' ComponentTypeList
  675. { $$ = $2;
  676. }
  677. | /* empty */
  678. { $$ = NULL;
  679. }
  680. ;
  681. ComponentTypeList
  682. : ComponentType AdditionalComponentTypeList
  683. { if ($2) {
  684. $$ = DupComponent($1);
  685. $$->Next = $2;
  686. } else {
  687. $$ = $1;
  688. }
  689. }
  690. ;
  691. ComponentType
  692. : NamedType ComponentTypePostfix($1->Type)
  693. { $$ = DupComponent($2);
  694. $$->U.NOD.NamedType = $1;
  695. }
  696. | "COMPONENTS" "OF" Type
  697. { $$ = NewComponent(eComponent_ComponentsOf);
  698. $$->U.ComponentsOf.Type = $3;
  699. }
  700. ;
  701. ComponentTypePostfix(type)
  702. : "OPTIONAL"
  703. { $$ = NewComponent(eComponent_Optional);
  704. }
  705. | "DEFAULT" Value($type)
  706. { $$ = NewComponent(eComponent_Default);
  707. $$->U.Default.Value = $2;
  708. }
  709. | /* empty */
  710. { $$ = NewComponent(eComponent_Normal);
  711. }
  712. ;
  713. SequenceOfType
  714. : "SEQUENCE" LocalSizeDirectiveESeq PrivateDirectives "OF" Type
  715. { $$ = NewType(eType_SequenceOf);
  716. $$->ExtensionDefault = $>>.ExtensionDefault;
  717. $$->U.SequenceOf.Type = $5;
  718. $$->U.SequenceOf.Directives = $2;
  719. if ($3)
  720. {
  721. PropagatePrivateDirectives($$, $3);
  722. }
  723. if ($$->PrivateDirectives.pszTypeName &&
  724. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  725. {
  726. $$->PrivateDirectives.pszTypeName++;
  727. }
  728. }
  729. ;
  730. SetType
  731. : "SET" '{' ExtendedComponentTypeList '}'
  732. { Component_t *c, *d;
  733. for (c = $3; c && c->Next; c = c->Next) {
  734. if (c->Type != eComponent_Normal &&
  735. c->Type != eComponent_Optional &&
  736. c->Type != eComponent_Default)
  737. continue;
  738. for (d = c->Next; d; d = d->Next) {
  739. if (d->Type != eComponent_Normal &&
  740. d->Type != eComponent_Optional &&
  741. d->Type != eComponent_Default)
  742. continue;
  743. if (!strcmp(c->U.NOD.NamedType->Identifier,
  744. d->U.NOD.NamedType->Identifier))
  745. LLFAILED((&@3, "Component `%s' has been used twice",
  746. c->U.NOD.NamedType->Identifier));
  747. }
  748. }
  749. $$ = NewType(eType_Set);
  750. $$->TagDefault = $>>.TagDefault;
  751. $$->ExtensionDefault = $>>.ExtensionDefault;
  752. $$->U.Set.Components = $3;
  753. }
  754. | "SET" '{' '}'
  755. { $$ = NewType(eType_Set);
  756. $$->ExtensionDefault = $>>.ExtensionDefault;
  757. }
  758. ;
  759. SetOfType
  760. : "SET" LocalSizeDirectiveESeq PrivateDirectives "OF" Type
  761. { $$ = NewType(eType_SetOf);
  762. $$->ExtensionDefault = $>>.ExtensionDefault;
  763. $$->U.SetOf.Type = $5;
  764. $$->U.SetOf.Directives = $2;
  765. if ($3)
  766. {
  767. PropagatePrivateDirectives($$, $3);
  768. }
  769. if ($$->PrivateDirectives.pszTypeName &&
  770. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  771. {
  772. $$->PrivateDirectives.pszTypeName++;
  773. }
  774. }
  775. ;
  776. ChoiceType
  777. : "CHOICE" '{' ExtendedAlternativeTypeList '}'
  778. { Component_t *c, *d;
  779. for (c = $3; c; c = c->Next)
  780. if (c->Type == eComponent_Normal ||
  781. c->Type == eComponent_Optional ||
  782. c->Type == eComponent_Default)
  783. KeepChoiceNames(c->U.NOD.NamedType->Identifier); // global conflict check
  784. for (c = $3; c && c->Next; c = c->Next) {
  785. if (c->Type != eComponent_Normal &&
  786. c->Type != eComponent_Optional &&
  787. c->Type != eComponent_Default)
  788. continue;
  789. for (d = c->Next; d; d = d->Next) {
  790. if (d->Type != eComponent_Normal &&
  791. d->Type != eComponent_Optional &&
  792. d->Type != eComponent_Default)
  793. continue;
  794. if (!strcmp(c->U.NOD.NamedType->Identifier,
  795. d->U.NOD.NamedType->Identifier))
  796. LLFAILED((&@3, "Component `%s' has been used twice",
  797. c->U.NOD.NamedType->Identifier));
  798. }
  799. }
  800. $$ = NewType(eType_Choice);
  801. $$->TagDefault = $>>.TagDefault;
  802. $$->ExtensionDefault = $>>.ExtensionDefault;
  803. $$->U.Choice.Components = $3;
  804. }
  805. ;
  806. ExtendedAlternativeTypeList
  807. : AlternativeTypeList AlternativeTypeListExtension
  808. { Component_t **cc, *c;
  809. if ($2) {
  810. cc = &$$;
  811. for (c = $1; c; c = c->Next) {
  812. *cc = DupComponent(c);
  813. cc = &(*cc)->Next;
  814. }
  815. *cc = $2;
  816. } else {
  817. $$ = $1;
  818. }
  819. }
  820. ;
  821. AlternativeTypeListExtension
  822. : ',' ExtensionAndException AdditionalAlternativeTypeList
  823. { Component_t **cc, *c;
  824. if ($3) {
  825. cc = &$$;
  826. for (c = $2; c; c = c->Next) {
  827. *cc = DupComponent(c);
  828. cc = &(*cc)->Next;
  829. }
  830. *cc = $3;
  831. } else {
  832. $$ = $2;
  833. }
  834. }
  835. | /* empty */
  836. { $$ = NULL;
  837. }
  838. ;
  839. AdditionalAlternativeTypeList
  840. : ',' AlternativeTypeList
  841. { $$ = $2;
  842. }
  843. | /* empty */
  844. { $$ = NULL;
  845. }
  846. ;
  847. AlternativeTypeList
  848. : NamedType AdditionalAlternativeTypeList
  849. { $$ = NewComponent(eComponent_Normal);
  850. $$->U.Normal.NamedType = $1;
  851. $$->Next = $2;
  852. }
  853. ;
  854. AnyType
  855. : "ANY"
  856. { $$ = Builtin_Type_Open;
  857. }
  858. | "ANY" "DEFINED" "BY" identifier
  859. { $$ = Builtin_Type_Open;
  860. }
  861. ;
  862. SelectionType
  863. : identifier '<' Type
  864. { $$ = NewType(eType_Selection);
  865. $$->U.Selection.Identifier = $1;
  866. $$->U.Selection.Type = $3;
  867. }
  868. ;
  869. TaggedType
  870. : Tag TagType Type
  871. { Tag_t *t;
  872. Type_e eType = GetTypeType($>>.Assignments, $3);
  873. if (eType == eType_Choice || eType == eType_Open)
  874. {
  875. if ($2 == eTagType_Unknown &&
  876. ($>>.TagDefault == eTagType_Implicit || $>>.TagDefault == eTagType_Automatic))
  877. {
  878. $2 = eTagType_Explicit;
  879. }
  880. else
  881. if ($2 == eTagType_Implicit)
  882. {
  883. for (t = $3->Tags; t; t = t->Next) {
  884. if (t->Type == eTagType_Explicit)
  885. break;
  886. }
  887. if (!t)
  888. LLFAILED((&@3, "Bad tag type for choice/open type"));
  889. }
  890. }
  891. $$ = DupType($3);
  892. $$->Tags = DupTag($1);
  893. $$->Tags->Type = $2;
  894. $$->Tags->Next = $3->Tags;
  895. }
  896. ;
  897. TagType
  898. : /* empty */
  899. { $$ = eTagType_Unknown;
  900. }
  901. | "IMPLICIT"
  902. { $$ = eTagType_Implicit;
  903. }
  904. | "EXPLICIT"
  905. { $$ = eTagType_Explicit;
  906. }
  907. ;
  908. Tag
  909. : '[' Class ClassNumber ']'
  910. { $$ = NewTag(eTagType_Unknown);
  911. $$->Class = $2;
  912. $$->Tag = $3;
  913. }
  914. ;
  915. ClassNumber
  916. : number
  917. { if (intx_cmp(&$1, &intx_1G) >= 0)
  918. LLFAILED((&@1, "Bad tag value"));
  919. $$ = NewValue(NULL, Builtin_Type_Integer);
  920. $$->U.Integer.Value = $1;
  921. }
  922. | DefinedValue
  923. { Value_t *v;
  924. v = GetValue($>>.Assignments, $1);
  925. if (v &&
  926. GetTypeType($>>.Assignments, v->Type) != eType_Integer &&
  927. GetTypeType($>>.Assignments, v->Type) != eType_Undefined)
  928. LLFAILED((&@1, "Bad type of tag value"));
  929. if (v &&
  930. GetTypeType($>>.Assignments, v->Type) == eType_Integer &&
  931. (intx_cmp(&v->U.Integer.Value, &intx_0) < 0 ||
  932. intx_cmp(&v->U.Integer.Value, &intx_1G) >= 0))
  933. LLFAILED((&@1, "Bad tag value"));
  934. $$ = $1;
  935. }
  936. ;
  937. Class
  938. : "UNIVERSAL"
  939. { $$ = eTagClass_Universal;
  940. }
  941. | "APPLICATION"
  942. { $$ = eTagClass_Application;
  943. }
  944. | "PRIVATE"
  945. { $$ = eTagClass_Private;
  946. }
  947. | /* empty */
  948. { $$ = eTagClass_Unknown;
  949. }
  950. ;
  951. ObjectIdentifierType
  952. : "OBJECT" "IDENTIFIER"
  953. { $$ = Builtin_Type_ObjectIdentifier;
  954. }
  955. ;
  956. EmbeddedPDVType
  957. : "EMBEDDED" "PDV"
  958. { $$ = Builtin_Type_EmbeddedPdv;
  959. }
  960. ;
  961. ExternalType
  962. : "EXTERNAL"
  963. { $$ = Builtin_Type_External;
  964. }
  965. ;
  966. CharacterStringType
  967. : RestrictedCharacterStringType
  968. { $$ = $1;
  969. }
  970. | UnrestrictedCharacterStringType
  971. { $$ = $1;
  972. }
  973. ;
  974. RestrictedCharacterStringType
  975. : "BMPString"
  976. { $$ = Builtin_Type_BMPString;
  977. }
  978. | "GeneralString"
  979. { $$ = Builtin_Type_GeneralString;
  980. }
  981. | "GraphicString"
  982. { $$ = Builtin_Type_GraphicString;
  983. }
  984. | "IA5String"
  985. { $$ = Builtin_Type_IA5String;
  986. }
  987. | "ISO646String"
  988. { $$ = Builtin_Type_ISO646String;
  989. }
  990. | "NumericString"
  991. { $$ = Builtin_Type_NumericString;
  992. }
  993. | "PrintableString"
  994. { $$ = Builtin_Type_PrintableString;
  995. }
  996. | "TeletexString"
  997. { $$ = Builtin_Type_TeletexString;
  998. }
  999. | "T61String"
  1000. { $$ = Builtin_Type_T61String;
  1001. }
  1002. | "UniversalString"
  1003. { $$ = Builtin_Type_UniversalString;
  1004. }
  1005. | "VideotexString"
  1006. { $$ = Builtin_Type_VideotexString;
  1007. }
  1008. | "VisibleString"
  1009. { $$ = Builtin_Type_VisibleString;
  1010. }
  1011. ;
  1012. UnrestrictedCharacterStringType
  1013. : "CHARACTER" "STRING"
  1014. { $$ = Builtin_Type_CharacterString;
  1015. }
  1016. ;
  1017. UsefulType
  1018. : "GeneralizedTime"
  1019. { $$ = Builtin_Type_GeneralizedTime;
  1020. }
  1021. | "UTCTime"
  1022. { $$ = Builtin_Type_UTCTime;
  1023. }
  1024. | "ObjectDescriptor"
  1025. { $$ = Builtin_Type_ObjectDescriptor;
  1026. }
  1027. ;
  1028. TypeWithConstraint
  1029. : "SET" LocalSizeDirectiveESeq PrivateDirectives Constraint(NULL, 0)
  1030. LocalSizeDirectiveESeq "OF" Type /*XXX*/
  1031. { Directive_t **dd, *d;
  1032. $$ = NewType(eType_SetOf);
  1033. $$->ExtensionDefault = $>>.ExtensionDefault;
  1034. $$->Constraints = $4;
  1035. $$->U.SetOf.Type = $7;
  1036. if ($3)
  1037. {
  1038. PropagatePrivateDirectives($$, $3);
  1039. }
  1040. dd = &$$->U.SetOf.Directives;
  1041. for (d = $2; d; d = d->Next) {
  1042. *dd = DupDirective(d);
  1043. dd = &(*dd)->Next;
  1044. }
  1045. for (d = $5; d; d = d->Next) {
  1046. *dd = DupDirective(d);
  1047. dd = &(*dd)->Next;
  1048. }
  1049. *dd = NULL;
  1050. if ($$->PrivateDirectives.pszTypeName &&
  1051. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  1052. {
  1053. $$->PrivateDirectives.pszTypeName++;
  1054. }
  1055. }
  1056. | "SET" LocalSizeDirectiveESeq PrivateDirectives SizeConstraint
  1057. LocalSizeDirectiveESeq PrivateDirectives "OF" Type
  1058. { Directive_t **dd, *d;
  1059. $$ = NewType(eType_SetOf);
  1060. $$->ExtensionDefault = $>>.ExtensionDefault;
  1061. $$->Constraints = NewConstraint();
  1062. $$->Constraints->Type = eExtension_Unextended;
  1063. $$->Constraints->Root = NewElementSetSpec(
  1064. eElementSetSpec_SubtypeElement);
  1065. $$->Constraints->Root->U.SubtypeElement.SubtypeElement = $4;
  1066. $$->U.SetOf.Type = $8;
  1067. if ($3)
  1068. {
  1069. PropagatePrivateDirectives($$, $3);
  1070. }
  1071. if ($6)
  1072. {
  1073. PropagatePrivateDirectives($$, $6);
  1074. }
  1075. dd = &$$->U.SetOf.Directives;
  1076. for (d = $2; d; d = d->Next) {
  1077. *dd = DupDirective(d);
  1078. dd = &(*dd)->Next;
  1079. }
  1080. for (d = $5; d; d = d->Next) {
  1081. *dd = DupDirective(d);
  1082. dd = &(*dd)->Next;
  1083. }
  1084. *dd = NULL;
  1085. if ($$->PrivateDirectives.pszTypeName &&
  1086. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  1087. {
  1088. $$->PrivateDirectives.pszTypeName++;
  1089. }
  1090. }
  1091. | "SEQUENCE" LocalSizeDirectiveESeq PrivateDirectives Constraint(NULL, 0)
  1092. LocalSizeDirectiveESeq "OF" Type /*XXX*/
  1093. { Directive_t **dd, *d;
  1094. $$ = NewType(eType_SequenceOf);
  1095. $$->ExtensionDefault = $>>.ExtensionDefault;
  1096. $$->Constraints = $4;
  1097. $$->U.SequenceOf.Type = $7;
  1098. if ($3)
  1099. {
  1100. PropagatePrivateDirectives($$, $3);
  1101. }
  1102. dd = &$$->U.SequenceOf.Directives;
  1103. for (d = $2; d; d = d->Next) {
  1104. *dd = DupDirective(d);
  1105. dd = &(*dd)->Next;
  1106. }
  1107. for (d = $5; d; d = d->Next) {
  1108. *dd = DupDirective(d);
  1109. dd = &(*dd)->Next;
  1110. }
  1111. *dd = NULL;
  1112. if ($$->PrivateDirectives.pszTypeName &&
  1113. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  1114. {
  1115. $$->PrivateDirectives.pszTypeName++;
  1116. }
  1117. }
  1118. | "SEQUENCE" LocalSizeDirectiveESeq PrivateDirectives SizeConstraint
  1119. LocalSizeDirectiveESeq PrivateDirectives "OF" Type
  1120. { Directive_t **dd, *d;
  1121. $$ = NewType(eType_SequenceOf);
  1122. $$->ExtensionDefault = $>>.ExtensionDefault;
  1123. $$->Constraints = NewConstraint();
  1124. $$->Constraints->Type = eExtension_Unextended;
  1125. $$->Constraints->Root = NewElementSetSpec(
  1126. eElementSetSpec_SubtypeElement);
  1127. $$->Constraints->Root->U.SubtypeElement.SubtypeElement = $4;
  1128. $$->U.SequenceOf.Type = $8;
  1129. if ($3)
  1130. {
  1131. PropagatePrivateDirectives($$, $3);
  1132. }
  1133. if ($6)
  1134. {
  1135. PropagatePrivateDirectives($$, $6);
  1136. }
  1137. dd = &$$->U.SequenceOf.Directives;
  1138. for (d = $2; d; d = d->Next) {
  1139. *dd = DupDirective(d);
  1140. dd = &(*dd)->Next;
  1141. }
  1142. for (d = $5; d; d = d->Next) {
  1143. *dd = DupDirective(d);
  1144. dd = &(*dd)->Next;
  1145. }
  1146. *dd = NULL;
  1147. if ($$->PrivateDirectives.pszTypeName &&
  1148. strncmp("PSetOf", $$->PrivateDirectives.pszTypeName, 6) == 0)
  1149. {
  1150. $$->PrivateDirectives.pszTypeName++;
  1151. }
  1152. }
  1153. ;