1/* $ANTLR 2.7.7 (20120228): "requirements.grammar" -> "RequirementParser.cpp"$ */
2#include "RequirementParser.hpp"
3#include <antlr/NoViableAltException.hpp>
4#include <antlr/SemanticException.hpp>
5#include <antlr/ASTFactory.hpp>
6
7#include "requirement.h"
8#include "reqmaker.h"
9#include "csutilities.h"
10#include <security_utilities/cfutilities.h>
11#include <security_utilities/hashing.h>
12#include <security_cdsa_utilities/cssmdata.h>	// OID coding
13using namespace CodeSigning;
14typedef Requirement::Maker Maker;
15
16ANTLR_BEGIN_NAMESPACE(Security_CodeSigning)
17
18	//
19	// Collect error messages.
20	// Note that the immediate caller takes the absence of collected error messages
21	// to indicate compilation success.
22	//
23	void RequirementParser::reportError(const antlr::RecognitionException &ex)
24	{
25		errors += ex.toString() + "\n";
26	}
27
28	void RequirementParser::reportError(const std::string &s)
29	{
30		errors += s + "\n";
31	}
32
33
34	//
35	// Parser helper functions
36	//
37	string RequirementParser::hexString(const string &s)
38	{
39		if (s.size() % 2)
40			throw antlr::SemanticException("odd number of digits");
41		const char *p = s.data();
42		string result;
43		for (unsigned n = 0; n < s.length(); n += 2) {
44			char c;
45			sscanf(p+n, "%2hhx", &c);
46			result.push_back(c);
47		}
48		return result;
49	}
50
51	void RequirementParser::hashString(const string &s, SHA1::Digest hash)
52	{
53		if (s.size() != 2 * SHA1::digestLength)
54			throw antlr::SemanticException("invalid hash length");
55		memcpy(hash, hexString(s).data(), SHA1::digestLength);
56	}
57
58	static const char *matchPrefix(const string &key, const char *prefix)
59	{
60		size_t pLength = strlen(prefix);
61		if (!key.compare(0, pLength, prefix, 0, pLength))
62			return key.c_str() + pLength;
63		else
64			return NULL;
65	}
66
67	void RequirementParser::certMatchOperation(Maker &maker, int32_t slot, string key)
68	{
69		if (matchPrefix(key, "subject.")) {
70			maker.put(opCertField);
71			maker.put(slot);
72			maker.put(key);
73		} else if (const char *oids = matchPrefix(key, "field.")) {
74			maker.put(opCertGeneric);
75			maker.put(slot);
76			CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
77			maker.putData(oid.data(), oid.length());
78		} else if (const char *oids = matchPrefix(key, "extension.")) {
79			maker.put(opCertGeneric);
80			maker.put(slot);
81			CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
82			maker.putData(oid.data(), oid.length());
83		} else if (const char *oids = matchPrefix(key, "policy.")) {
84			maker.put(opCertPolicy);
85			maker.put(slot);
86			CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
87			maker.putData(oid.data(), oid.length());
88		} else {
89			throw antlr::SemanticException(key + ": unrecognized certificate field");
90		}
91	}
92
93RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf, int k)
94: antlr::LLkParser(tokenBuf,k)
95{
96}
97
98RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf)
99: antlr::LLkParser(tokenBuf,2)
100{
101}
102
103RequirementParser::RequirementParser(antlr::TokenStream& lexer, int k)
104: antlr::LLkParser(lexer,k)
105{
106}
107
108RequirementParser::RequirementParser(antlr::TokenStream& lexer)
109: antlr::LLkParser(lexer,2)
110{
111}
112
113RequirementParser::RequirementParser(const antlr::ParserSharedInputState& state)
114: antlr::LLkParser(state,2)
115{
116}
117
118BlobCore * RequirementParser::autosense() {
119	BlobCore *result = NULL;
120
121	try {      // for error handling
122		switch ( LA(1)) {
123		case LPAREN:
124		case NOT:
125		case LITERAL_always:
126		case LITERAL_true:
127		case LITERAL_never:
128		case LITERAL_false:
129		case LITERAL_identifier:
130		case LITERAL_cdhash:
131		case LITERAL_anchor:
132		case LITERAL_certificate:
133		case LITERAL_cert:
134		case LITERAL_info:
135		case LITERAL_entitlement:
136		{
137			result=requirement();
138			break;
139		}
140		case LITERAL_guest:
141		case LITERAL_host:
142		case LITERAL_designated:
143		case LITERAL_library:
144		case LITERAL_plugin:
145		case INTEGER:
146		{
147			result=requirementSet();
148			break;
149		}
150		default:
151		{
152			throw antlr::NoViableAltException(LT(1), getFilename());
153		}
154		}
155	}
156	catch (antlr::RecognitionException& ex) {
157		reportError(ex);
158		recover(ex,_tokenSet_0);
159	}
160	return result;
161}
162
163Requirement * RequirementParser::requirement() {
164	Requirement *result = NULL;
165
166	try {      // for error handling
167		result=requirementElement();
168		match(antlr::Token::EOF_TYPE);
169	}
170	catch (antlr::RecognitionException& ex) {
171		reportError(ex);
172		recover(ex,_tokenSet_0);
173	}
174	return result;
175}
176
177Requirements * RequirementParser::requirementSet() {
178	Requirements *result = NULL;
179	Requirements::Maker maker;
180
181	try {      // for error handling
182		{ // ( ... )+
183		int _cnt4=0;
184		for (;;) {
185			if (((LA(1) >= LITERAL_guest && LA(1) <= INTEGER))) {
186				uint32_t t; Requirement *req;
187				t=requirementType();
188				match(ARROW);
189				req=requirementElement();
190				maker.add(t, req);
191			}
192			else {
193				if ( _cnt4>=1 ) { goto _loop4; } else {throw antlr::NoViableAltException(LT(1), getFilename());}
194			}
195
196			_cnt4++;
197		}
198		_loop4:;
199		}  // ( ... )+
200		result = errors.empty() ? maker() : NULL;
201		match(antlr::Token::EOF_TYPE);
202	}
203	catch (antlr::RecognitionException& ex) {
204		reportError(ex);
205		recover(ex,_tokenSet_0);
206	}
207	return result;
208}
209
210uint32_t  RequirementParser::requirementType() {
211	uint32_t type = kSecInvalidRequirementType;
212	antlr::RefToken  stype = antlr::nullToken;
213
214	try {      // for error handling
215		switch ( LA(1)) {
216		case LITERAL_guest:
217		{
218			match(LITERAL_guest);
219			type = kSecGuestRequirementType;
220			break;
221		}
222		case LITERAL_host:
223		{
224			match(LITERAL_host);
225			type = kSecHostRequirementType;
226			break;
227		}
228		case LITERAL_designated:
229		{
230			match(LITERAL_designated);
231			type = kSecDesignatedRequirementType;
232			break;
233		}
234		case LITERAL_library:
235		{
236			match(LITERAL_library);
237			type = kSecLibraryRequirementType;
238			break;
239		}
240		case LITERAL_plugin:
241		{
242			match(LITERAL_plugin);
243			type = kSecPluginRequirementType;
244			break;
245		}
246		case INTEGER:
247		{
248			stype = LT(1);
249			match(INTEGER);
250			type = (uint32_t)atol(stype->getText().c_str());
251			break;
252		}
253		default:
254		{
255			throw antlr::NoViableAltException(LT(1), getFilename());
256		}
257		}
258	}
259	catch (antlr::RecognitionException& ex) {
260		reportError(ex);
261		recover(ex,_tokenSet_1);
262	}
263	return type;
264}
265
266Requirement * RequirementParser::requirementElement() {
267	Requirement *result = NULL;
268	Requirement::Maker maker;
269
270	try {      // for error handling
271		expr(maker);
272		result = maker();
273		{ // ( ... )*
274		for (;;) {
275			if ((LA(1) == SEMI)) {
276				fluff();
277			}
278			else {
279				goto _loop9;
280			}
281
282		}
283		_loop9:;
284		} // ( ... )*
285	}
286	catch (antlr::RecognitionException& ex) {
287		reportError(ex);
288		recover(ex,_tokenSet_2);
289	}
290	return result;
291}
292
293void RequirementParser::expr(
294	Maker &maker
295) {
296	Maker::Label label(maker);
297
298	try {      // for error handling
299		term(maker);
300		{ // ( ... )*
301		for (;;) {
302			if ((LA(1) == LITERAL_or)) {
303				match(LITERAL_or);
304				maker.insert<ExprOp>(label) = opOr;
305				term(maker);
306			}
307			else {
308				goto _loop12;
309			}
310
311		}
312		_loop12:;
313		} // ( ... )*
314	}
315	catch (antlr::RecognitionException& ex) {
316		reportError(ex);
317		recover(ex,_tokenSet_3);
318	}
319}
320
321void RequirementParser::fluff() {
322
323	try {      // for error handling
324		match(SEMI);
325	}
326	catch (antlr::RecognitionException& ex) {
327		reportError(ex);
328		recover(ex,_tokenSet_4);
329	}
330}
331
332void RequirementParser::term(
333	Maker &maker
334) {
335	Maker::Label label(maker);
336
337	try {      // for error handling
338		primary(maker);
339		{ // ( ... )*
340		for (;;) {
341			if ((LA(1) == LITERAL_and)) {
342				match(LITERAL_and);
343				maker.insert<ExprOp>(label) = opAnd;
344				primary(maker);
345			}
346			else {
347				goto _loop15;
348			}
349
350		}
351		_loop15:;
352		} // ( ... )*
353	}
354	catch (antlr::RecognitionException& ex) {
355		reportError(ex);
356		recover(ex,_tokenSet_5);
357	}
358}
359
360void RequirementParser::primary(
361	Maker &maker
362) {
363
364	try {      // for error handling
365		switch ( LA(1)) {
366		case NOT:
367		{
368			match(NOT);
369			maker.put(opNot);
370			primary(maker);
371			break;
372		}
373		case LITERAL_always:
374		case LITERAL_true:
375		{
376			{
377			switch ( LA(1)) {
378			case LITERAL_always:
379			{
380				match(LITERAL_always);
381				break;
382			}
383			case LITERAL_true:
384			{
385				match(LITERAL_true);
386				break;
387			}
388			default:
389			{
390				throw antlr::NoViableAltException(LT(1), getFilename());
391			}
392			}
393			}
394			maker.put(opTrue);
395			break;
396		}
397		case LITERAL_never:
398		case LITERAL_false:
399		{
400			{
401			switch ( LA(1)) {
402			case LITERAL_never:
403			{
404				match(LITERAL_never);
405				break;
406			}
407			case LITERAL_false:
408			{
409				match(LITERAL_false);
410				break;
411			}
412			default:
413			{
414				throw antlr::NoViableAltException(LT(1), getFilename());
415			}
416			}
417			}
418			maker.put(opFalse);
419			break;
420		}
421		case LITERAL_anchor:
422		case LITERAL_certificate:
423		case LITERAL_cert:
424		{
425			certspec(maker);
426			break;
427		}
428		case LITERAL_info:
429		{
430			infospec(maker);
431			break;
432		}
433		case LITERAL_entitlement:
434		{
435			entitlementspec(maker);
436			break;
437		}
438		case LITERAL_identifier:
439		{
440			match(LITERAL_identifier);
441			string code;
442			eql();
443			code=identifierString();
444			maker.ident(code);
445			break;
446		}
447		case LITERAL_cdhash:
448		{
449			match(LITERAL_cdhash);
450			SHA1::Digest digest;
451			eql();
452			hash(digest);
453			maker.cdhash(digest);
454			break;
455		}
456		default:
457			if ((LA(1) == LPAREN) && (_tokenSet_6.member(LA(2)))) {
458				match(LPAREN);
459				expr(maker);
460				match(RPAREN);
461			}
462			else if ((LA(1) == LPAREN) && (LA(2) == DOTKEY || LA(2) == STRING)) {
463				match(LPAREN);
464				string name;
465				name=identifierString();
466				match(RPAREN);
467				maker.put(opNamedCode); maker.put(name);
468			}
469		else {
470			throw antlr::NoViableAltException(LT(1), getFilename());
471		}
472		}
473	}
474	catch (antlr::RecognitionException& ex) {
475		reportError(ex);
476		recover(ex,_tokenSet_7);
477	}
478}
479
480void RequirementParser::certspec(
481	Maker &maker
482) {
483
484	try {      // for error handling
485		if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_apple)) {
486			match(LITERAL_anchor);
487			match(LITERAL_apple);
488			appleanchor(maker);
489		}
490		else if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_generic)) {
491			match(LITERAL_anchor);
492			match(LITERAL_generic);
493			match(LITERAL_apple);
494			maker.put(opAppleGenericAnchor);
495		}
496		else if ((LA(1) == LITERAL_anchor || LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (LA(2) == LITERAL_trusted)) {
497			{
498			switch ( LA(1)) {
499			case LITERAL_certificate:
500			{
501				match(LITERAL_certificate);
502				break;
503			}
504			case LITERAL_cert:
505			{
506				match(LITERAL_cert);
507				break;
508			}
509			case LITERAL_anchor:
510			{
511				match(LITERAL_anchor);
512				break;
513			}
514			default:
515			{
516				throw antlr::NoViableAltException(LT(1), getFilename());
517			}
518			}
519			}
520			match(LITERAL_trusted);
521			maker.trustedAnchor();
522		}
523		else if ((LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (_tokenSet_8.member(LA(2)))) {
524			{
525			switch ( LA(1)) {
526			case LITERAL_certificate:
527			{
528				match(LITERAL_certificate);
529				break;
530			}
531			case LITERAL_cert:
532			{
533				match(LITERAL_cert);
534				break;
535			}
536			default:
537			{
538				throw antlr::NoViableAltException(LT(1), getFilename());
539			}
540			}
541			}
542			int32_t slot;
543			slot=certSlot();
544			{
545			switch ( LA(1)) {
546			case EQL:
547			case EQQL:
548			case LBRACK:
549			case HASHCONSTANT:
550			case DOTKEY:
551			case STRING:
552			case PATHNAME:
553			{
554				certslotspec(maker, slot);
555				break;
556			}
557			case LITERAL_trusted:
558			{
559				match(LITERAL_trusted);
560				maker.trustedAnchor(slot);
561				break;
562			}
563			default:
564			{
565				throw antlr::NoViableAltException(LT(1), getFilename());
566			}
567			}
568			}
569		}
570		else if ((LA(1) == LITERAL_anchor) && (_tokenSet_9.member(LA(2)))) {
571			match(LITERAL_anchor);
572			certslotspec(maker, Requirement::anchorCert);
573		}
574		else {
575			throw antlr::NoViableAltException(LT(1), getFilename());
576		}
577
578	}
579	catch (antlr::RecognitionException& ex) {
580		reportError(ex);
581		recover(ex,_tokenSet_7);
582	}
583}
584
585void RequirementParser::infospec(
586	Maker &maker
587) {
588	string key;
589
590	try {      // for error handling
591		match(LITERAL_info);
592		key=bracketKey();
593		maker.put(opInfoKeyField); maker.put(key);
594		match_suffix(maker);
595	}
596	catch (antlr::RecognitionException& ex) {
597		reportError(ex);
598		recover(ex,_tokenSet_7);
599	}
600}
601
602void RequirementParser::entitlementspec(
603	Maker &maker
604) {
605	string key;
606
607	try {      // for error handling
608		match(LITERAL_entitlement);
609		key=bracketKey();
610		maker.put(opEntitlementField); maker.put(key);
611		match_suffix(maker);
612	}
613	catch (antlr::RecognitionException& ex) {
614		reportError(ex);
615		recover(ex,_tokenSet_7);
616	}
617}
618
619void RequirementParser::eql() {
620
621	try {      // for error handling
622		switch ( LA(1)) {
623		case EQL:
624		{
625			match(EQL);
626			break;
627		}
628		case EQQL:
629		{
630			match(EQQL);
631			break;
632		}
633		case HASHCONSTANT:
634		case DOTKEY:
635		case STRING:
636		case PATHNAME:
637		{
638			empty();
639			break;
640		}
641		default:
642		{
643			throw antlr::NoViableAltException(LT(1), getFilename());
644		}
645		}
646	}
647	catch (antlr::RecognitionException& ex) {
648		reportError(ex);
649		recover(ex,_tokenSet_10);
650	}
651}
652
653string  RequirementParser::identifierString() {
654	string result;
655	antlr::RefToken  dk = antlr::nullToken;
656	antlr::RefToken  s = antlr::nullToken;
657
658	try {      // for error handling
659		switch ( LA(1)) {
660		case DOTKEY:
661		{
662			dk = LT(1);
663			match(DOTKEY);
664			result = dk->getText();
665			break;
666		}
667		case STRING:
668		{
669			s = LT(1);
670			match(STRING);
671			result = s->getText();
672			break;
673		}
674		default:
675		{
676			throw antlr::NoViableAltException(LT(1), getFilename());
677		}
678		}
679	}
680	catch (antlr::RecognitionException& ex) {
681		reportError(ex);
682		recover(ex,_tokenSet_7);
683	}
684	return result;
685}
686
687void RequirementParser::hash(
688	SHA1::Digest digest
689) {
690	antlr::RefToken  hash = antlr::nullToken;
691
692	try {      // for error handling
693		hash = LT(1);
694		match(HASHCONSTANT);
695		hashString(hash->getText(), digest);
696	}
697	catch (antlr::RecognitionException& ex) {
698		reportError(ex);
699		recover(ex,_tokenSet_7);
700	}
701}
702
703void RequirementParser::appleanchor(
704	Maker &maker
705) {
706
707	try {      // for error handling
708		switch ( LA(1)) {
709		case antlr::Token::EOF_TYPE:
710		case LITERAL_guest:
711		case LITERAL_host:
712		case LITERAL_designated:
713		case LITERAL_library:
714		case LITERAL_plugin:
715		case INTEGER:
716		case LITERAL_or:
717		case LITERAL_and:
718		case RPAREN:
719		case SEMI:
720		{
721			empty();
722			maker.put(opAppleAnchor);
723			break;
724		}
725		case LITERAL_generic:
726		{
727			match(LITERAL_generic);
728			maker.put(opAppleGenericAnchor);
729			break;
730		}
731		case DOTKEY:
732		case STRING:
733		{
734			string name;
735			name=identifierString();
736			maker.put(opNamedAnchor); maker.put(name);
737			break;
738		}
739		default:
740		{
741			throw antlr::NoViableAltException(LT(1), getFilename());
742		}
743		}
744	}
745	catch (antlr::RecognitionException& ex) {
746		reportError(ex);
747		recover(ex,_tokenSet_7);
748	}
749}
750
751int32_t  RequirementParser::certSlot() {
752	int32_t slot = 0;
753	antlr::RefToken  s = antlr::nullToken;
754	antlr::RefToken  ss = antlr::nullToken;
755
756	try {      // for error handling
757		switch ( LA(1)) {
758		case INTEGER:
759		{
760			s = LT(1);
761			match(INTEGER);
762			slot = (int32_t)atol(s->getText().c_str());
763			break;
764		}
765		case NEG:
766		{
767			match(NEG);
768			ss = LT(1);
769			match(INTEGER);
770			slot = (int32_t)-atol(ss->getText().c_str());
771			break;
772		}
773		case LITERAL_leaf:
774		{
775			match(LITERAL_leaf);
776			slot = Requirement::leafCert;
777			break;
778		}
779		case LITERAL_root:
780		{
781			match(LITERAL_root);
782			slot = Requirement::anchorCert;
783			break;
784		}
785		default:
786		{
787			throw antlr::NoViableAltException(LT(1), getFilename());
788		}
789		}
790	}
791	catch (antlr::RecognitionException& ex) {
792		reportError(ex);
793		recover(ex,_tokenSet_11);
794	}
795	return slot;
796}
797
798void RequirementParser::certslotspec(
799	Maker &maker, int32_t slot
800) {
801	string key;
802
803	try {      // for error handling
804		switch ( LA(1)) {
805		case EQL:
806		case EQQL:
807		case HASHCONSTANT:
808		case DOTKEY:
809		case STRING:
810		case PATHNAME:
811		{
812			eql();
813			SHA1::Digest digest;
814			certificateDigest(digest);
815			maker.anchor(slot, digest);
816			break;
817		}
818		case LBRACK:
819		{
820			key=bracketKey();
821			certMatchOperation(maker, slot, key);
822			match_suffix(maker);
823			break;
824		}
825		default:
826		{
827			throw antlr::NoViableAltException(LT(1), getFilename());
828		}
829		}
830	}
831	catch (antlr::RecognitionException& ex) {
832		reportError(ex);
833		recover(ex,_tokenSet_7);
834	}
835}
836
837void RequirementParser::empty() {
838
839	try {      // for error handling
840	}
841	catch (antlr::RecognitionException& ex) {
842		reportError(ex);
843		recover(ex,_tokenSet_12);
844	}
845}
846
847void RequirementParser::certificateDigest(
848	SHA1::Digest digest
849) {
850
851	try {      // for error handling
852		switch ( LA(1)) {
853		case HASHCONSTANT:
854		{
855			hash(digest);
856			break;
857		}
858		case DOTKEY:
859		case STRING:
860		case PATHNAME:
861		{
862			string path;
863			path=pathstring();
864			if (CFRef<CFDataRef> certData = cfLoadFile(path))
865							hashOfCertificate(CFDataGetBytePtr(certData), CFDataGetLength(certData), digest);
866						  else
867							throw antlr::SemanticException(path + ": not found");
868
869			break;
870		}
871		default:
872		{
873			throw antlr::NoViableAltException(LT(1), getFilename());
874		}
875		}
876	}
877	catch (antlr::RecognitionException& ex) {
878		reportError(ex);
879		recover(ex,_tokenSet_7);
880	}
881}
882
883string  RequirementParser::bracketKey() {
884	string key;
885
886	try {      // for error handling
887		match(LBRACK);
888		key=stringvalue();
889		match(RBRACK);
890	}
891	catch (antlr::RecognitionException& ex) {
892		reportError(ex);
893		recover(ex,_tokenSet_13);
894	}
895	return key;
896}
897
898void RequirementParser::match_suffix(
899	Maker &maker
900) {
901
902	try {      // for error handling
903		switch ( LA(1)) {
904		case antlr::Token::EOF_TYPE:
905		case LITERAL_guest:
906		case LITERAL_host:
907		case LITERAL_designated:
908		case LITERAL_library:
909		case LITERAL_plugin:
910		case INTEGER:
911		case LITERAL_or:
912		case LITERAL_and:
913		case RPAREN:
914		case LITERAL_exists:
915		case SEMI:
916		{
917			empty();
918			{
919			switch ( LA(1)) {
920			case LITERAL_exists:
921			{
922				match(LITERAL_exists);
923				break;
924			}
925			case antlr::Token::EOF_TYPE:
926			case LITERAL_guest:
927			case LITERAL_host:
928			case LITERAL_designated:
929			case LITERAL_library:
930			case LITERAL_plugin:
931			case INTEGER:
932			case LITERAL_or:
933			case LITERAL_and:
934			case RPAREN:
935			case SEMI:
936			{
937				break;
938			}
939			default:
940			{
941				throw antlr::NoViableAltException(LT(1), getFilename());
942			}
943			}
944			}
945			maker.put(matchExists);
946			break;
947		}
948		case EQL:
949		case EQQL:
950		{
951			{
952			switch ( LA(1)) {
953			case EQL:
954			{
955				match(EQL);
956				break;
957			}
958			case EQQL:
959			{
960				match(EQQL);
961				break;
962			}
963			default:
964			{
965				throw antlr::NoViableAltException(LT(1), getFilename());
966			}
967			}
968			}
969			MatchOperation mop = matchEqual; string value;
970			{
971			switch ( LA(1)) {
972			case STAR:
973			{
974				match(STAR);
975				mop = matchEndsWith;
976				break;
977			}
978			case HEXCONSTANT:
979			case DOTKEY:
980			case STRING:
981			{
982				break;
983			}
984			default:
985			{
986				throw antlr::NoViableAltException(LT(1), getFilename());
987			}
988			}
989			}
990			value=datavalue();
991			{
992			switch ( LA(1)) {
993			case STAR:
994			{
995				match(STAR);
996				mop = (mop == matchEndsWith) ? matchContains : matchBeginsWith;
997				break;
998			}
999			case antlr::Token::EOF_TYPE:
1000			case LITERAL_guest:
1001			case LITERAL_host:
1002			case LITERAL_designated:
1003			case LITERAL_library:
1004			case LITERAL_plugin:
1005			case INTEGER:
1006			case LITERAL_or:
1007			case LITERAL_and:
1008			case RPAREN:
1009			case SEMI:
1010			{
1011				break;
1012			}
1013			default:
1014			{
1015				throw antlr::NoViableAltException(LT(1), getFilename());
1016			}
1017			}
1018			}
1019			maker.put(mop); maker.put(value);
1020			break;
1021		}
1022		case SUBS:
1023		{
1024			match(SUBS);
1025			string value;
1026			value=datavalue();
1027			maker.put(matchContains); maker.put(value);
1028			break;
1029		}
1030		case LESS:
1031		{
1032			match(LESS);
1033			string value;
1034			value=datavalue();
1035			maker.put(matchLessThan); maker.put(value);
1036			break;
1037		}
1038		case GT:
1039		{
1040			match(GT);
1041			string value;
1042			value=datavalue();
1043			maker.put(matchGreaterThan); maker.put(value);
1044			break;
1045		}
1046		case LE:
1047		{
1048			match(LE);
1049			string value;
1050			value=datavalue();
1051			maker.put(matchLessEqual); maker.put(value);
1052			break;
1053		}
1054		case GE:
1055		{
1056			match(GE);
1057			string value;
1058			value=datavalue();
1059			maker.put(matchGreaterEqual); maker.put(value);
1060			break;
1061		}
1062		default:
1063		{
1064			throw antlr::NoViableAltException(LT(1), getFilename());
1065		}
1066		}
1067	}
1068	catch (antlr::RecognitionException& ex) {
1069		reportError(ex);
1070		recover(ex,_tokenSet_7);
1071	}
1072}
1073
1074string  RequirementParser::datavalue() {
1075	string result;
1076	antlr::RefToken  hex = antlr::nullToken;
1077
1078	try {      // for error handling
1079		switch ( LA(1)) {
1080		case DOTKEY:
1081		case STRING:
1082		{
1083			result=stringvalue();
1084			break;
1085		}
1086		case HEXCONSTANT:
1087		{
1088			hex = LT(1);
1089			match(HEXCONSTANT);
1090			result = hexString(hex->getText());
1091			break;
1092		}
1093		default:
1094		{
1095			throw antlr::NoViableAltException(LT(1), getFilename());
1096		}
1097		}
1098	}
1099	catch (antlr::RecognitionException& ex) {
1100		reportError(ex);
1101		recover(ex,_tokenSet_14);
1102	}
1103	return result;
1104}
1105
1106string  RequirementParser::stringvalue() {
1107	string result;
1108	antlr::RefToken  dk = antlr::nullToken;
1109	antlr::RefToken  s = antlr::nullToken;
1110
1111	try {      // for error handling
1112		switch ( LA(1)) {
1113		case DOTKEY:
1114		{
1115			dk = LT(1);
1116			match(DOTKEY);
1117			result = dk->getText();
1118			break;
1119		}
1120		case STRING:
1121		{
1122			s = LT(1);
1123			match(STRING);
1124			result = s->getText();
1125			break;
1126		}
1127		default:
1128		{
1129			throw antlr::NoViableAltException(LT(1), getFilename());
1130		}
1131		}
1132	}
1133	catch (antlr::RecognitionException& ex) {
1134		reportError(ex);
1135		recover(ex,_tokenSet_15);
1136	}
1137	return result;
1138}
1139
1140string  RequirementParser::pathstring() {
1141	string result;
1142	antlr::RefToken  dk = antlr::nullToken;
1143	antlr::RefToken  s = antlr::nullToken;
1144	antlr::RefToken  pn = antlr::nullToken;
1145
1146	try {      // for error handling
1147		switch ( LA(1)) {
1148		case DOTKEY:
1149		{
1150			dk = LT(1);
1151			match(DOTKEY);
1152			result = dk->getText();
1153			break;
1154		}
1155		case STRING:
1156		{
1157			s = LT(1);
1158			match(STRING);
1159			result = s->getText();
1160			break;
1161		}
1162		case PATHNAME:
1163		{
1164			pn = LT(1);
1165			match(PATHNAME);
1166			result = pn->getText();
1167			break;
1168		}
1169		default:
1170		{
1171			throw antlr::NoViableAltException(LT(1), getFilename());
1172		}
1173		}
1174	}
1175	catch (antlr::RecognitionException& ex) {
1176		reportError(ex);
1177		recover(ex,_tokenSet_7);
1178	}
1179	return result;
1180}
1181
1182void RequirementParser::initializeASTFactory( antlr::ASTFactory& )
1183{
1184}
1185const char* RequirementParser::tokenNames[] = {
1186	"<0>",
1187	"EOF",
1188	"<2>",
1189	"NULL_TREE_LOOKAHEAD",
1190	"ARROW",
1191	"\"guest\"",
1192	"\"host\"",
1193	"\"designated\"",
1194	"\"library\"",
1195	"\"plugin\"",
1196	"INTEGER",
1197	"\"or\"",
1198	"\"and\"",
1199	"LPAREN",
1200	"RPAREN",
1201	"NOT",
1202	"\"always\"",
1203	"\"true\"",
1204	"\"never\"",
1205	"\"false\"",
1206	"\"identifier\"",
1207	"\"cdhash\"",
1208	"\"anchor\"",
1209	"\"apple\"",
1210	"\"generic\"",
1211	"\"certificate\"",
1212	"\"cert\"",
1213	"\"trusted\"",
1214	"\"info\"",
1215	"\"entitlement\"",
1216	"\"exists\"",
1217	"EQL",
1218	"EQQL",
1219	"STAR",
1220	"SUBS",
1221	"LESS",
1222	"GT",
1223	"LE",
1224	"GE",
1225	"LBRACK",
1226	"RBRACK",
1227	"NEG",
1228	"\"leaf\"",
1229	"\"root\"",
1230	"HASHCONSTANT",
1231	"HEXCONSTANT",
1232	"DOTKEY",
1233	"STRING",
1234	"PATHNAME",
1235	"SEMI",
1236	"IDENT",
1237	"HEX",
1238	"COMMA",
1239	"WS",
1240	"SHELLCOMMENT",
1241	"C_COMMENT",
1242	"CPP_COMMENT",
1243	0
1244};
1245
1246const unsigned long RequirementParser::_tokenSet_0_data_[] = { 2UL, 0UL, 0UL, 0UL };
1247// EOF
1248const antlr::BitSet RequirementParser::_tokenSet_0(_tokenSet_0_data_,4);
1249const unsigned long RequirementParser::_tokenSet_1_data_[] = { 16UL, 0UL, 0UL, 0UL };
1250// ARROW
1251const antlr::BitSet RequirementParser::_tokenSet_1(_tokenSet_1_data_,4);
1252const unsigned long RequirementParser::_tokenSet_2_data_[] = { 2018UL, 0UL, 0UL, 0UL };
1253// EOF "guest" "host" "designated" "library" "plugin" INTEGER
1254const antlr::BitSet RequirementParser::_tokenSet_2(_tokenSet_2_data_,4);
1255const unsigned long RequirementParser::_tokenSet_3_data_[] = { 18402UL, 131072UL, 0UL, 0UL };
1256// EOF "guest" "host" "designated" "library" "plugin" INTEGER RPAREN SEMI
1257const antlr::BitSet RequirementParser::_tokenSet_3(_tokenSet_3_data_,4);
1258const unsigned long RequirementParser::_tokenSet_4_data_[] = { 2018UL, 131072UL, 0UL, 0UL };
1259// EOF "guest" "host" "designated" "library" "plugin" INTEGER SEMI
1260const antlr::BitSet RequirementParser::_tokenSet_4(_tokenSet_4_data_,4);
1261const unsigned long RequirementParser::_tokenSet_5_data_[] = { 20450UL, 131072UL, 0UL, 0UL };
1262// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" RPAREN
1263// SEMI
1264const antlr::BitSet RequirementParser::_tokenSet_5(_tokenSet_5_data_,4);
1265const unsigned long RequirementParser::_tokenSet_6_data_[] = { 914333696UL, 0UL, 0UL, 0UL };
1266// LPAREN NOT "always" "true" "never" "false" "identifier" "cdhash" "anchor"
1267// "certificate" "cert" "info" "entitlement"
1268const antlr::BitSet RequirementParser::_tokenSet_6(_tokenSet_6_data_,4);
1269const unsigned long RequirementParser::_tokenSet_7_data_[] = { 24546UL, 131072UL, 0UL, 0UL };
1270// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" "and"
1271// RPAREN SEMI
1272const antlr::BitSet RequirementParser::_tokenSet_7(_tokenSet_7_data_,4);
1273const unsigned long RequirementParser::_tokenSet_8_data_[] = { 1024UL, 3584UL, 0UL, 0UL };
1274// INTEGER NEG "leaf" "root"
1275const antlr::BitSet RequirementParser::_tokenSet_8(_tokenSet_8_data_,4);
1276const unsigned long RequirementParser::_tokenSet_9_data_[] = { 2147483648UL, 118913UL, 0UL, 0UL };
1277// EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1278const antlr::BitSet RequirementParser::_tokenSet_9(_tokenSet_9_data_,4);
1279const unsigned long RequirementParser::_tokenSet_10_data_[] = { 0UL, 118784UL, 0UL, 0UL };
1280// HASHCONSTANT DOTKEY STRING PATHNAME
1281const antlr::BitSet RequirementParser::_tokenSet_10(_tokenSet_10_data_,4);
1282const unsigned long RequirementParser::_tokenSet_11_data_[] = { 2281701376UL, 118913UL, 0UL, 0UL };
1283// "trusted" EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1284const antlr::BitSet RequirementParser::_tokenSet_11(_tokenSet_11_data_,4);
1285const unsigned long RequirementParser::_tokenSet_12_data_[] = { 1073766370UL, 249856UL, 0UL, 0UL };
1286// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" "and"
1287// RPAREN "exists" HASHCONSTANT DOTKEY STRING PATHNAME SEMI
1288const antlr::BitSet RequirementParser::_tokenSet_12(_tokenSet_12_data_,4);
1289const unsigned long RequirementParser::_tokenSet_13_data_[] = { 3221250018UL, 131197UL, 0UL, 0UL };
1290// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" "and"
1291// RPAREN "exists" EQL EQQL SUBS LESS GT LE GE SEMI
1292const antlr::BitSet RequirementParser::_tokenSet_13(_tokenSet_13_data_,4);
1293const unsigned long RequirementParser::_tokenSet_14_data_[] = { 24546UL, 131074UL, 0UL, 0UL };
1294// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" "and"
1295// RPAREN STAR SEMI
1296const antlr::BitSet RequirementParser::_tokenSet_14(_tokenSet_14_data_,4);
1297const unsigned long RequirementParser::_tokenSet_15_data_[] = { 24546UL, 131330UL, 0UL, 0UL };
1298// EOF "guest" "host" "designated" "library" "plugin" INTEGER "or" "and"
1299// RPAREN STAR RBRACK SEMI
1300const antlr::BitSet RequirementParser::_tokenSet_15(_tokenSet_15_data_,4);
1301
1302
1303ANTLR_END_NAMESPACE
1304