1 /*
2  * main.h
3  *
4  * PWLib application header file for asnparser
5  *
6  * ASN.1 compiler to produce C++ classes.
7  *
8  * Copyright (c) 1997-1999 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is ASN Parser.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions of this code were written with the assisance of funding from
25  * Vovida Networks, Inc. http://www.vovida.com.
26  *
27  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
28  * All Rights Reserved.
29  *
30  * Contributor(s): ______________________________________.
31  *
32  * $Revision: 20385 $
33  * $Author: rjongbloed $
34  * $Date: 2008-06-04 05:40:38 -0500 (Wed, 04 Jun 2008) $
35  */
36 
37 #ifndef _MAIN_H
38 #define _MAIN_H
39 
40 extern unsigned lineNumber;
41 extern PString  fileName;
42 extern FILE * yyin;
43 extern int yyparse();
44 
45 void yyerror(char * str);
46 
47 
48 /////////////////////////////////////////
49 //
50 //  standard error output from parser
51 //
52 
53 enum StdErrorType { Warning, Fatal };
54 
55 class StdError {
56   public:
StdError(StdErrorType ne)57     StdError(StdErrorType ne) : e(ne) { }
58     //StdError(StdErrorType ne, unsigned ln) : e(ne), l(ln) { }
59     friend ostream & operator<<(ostream & out, const StdError & e);
60 
61   protected:
62     StdErrorType e;
63     //unsigned     l;
64 };
65 
66 
67 /////////////////////////////////////////
68 //
69 //  intermediate structures from parser
70 //
71 
72 
73 class NamedNumber : public PObject
74 {
75     PCLASSINFO(NamedNumber, PObject);
76   public:
77     NamedNumber(PString * nam);
78     NamedNumber(PString * nam, int num);
79     NamedNumber(PString * nam, const PString & ref);
80     void PrintOn(ostream &) const;
81 
82     void SetAutoNumber(const NamedNumber & prev);
GetName()83     const PString & GetName() const { return name; }
GetNumber()84     int GetNumber() const { return number; }
85 
86   protected:
87     PString name;
88     PString reference;
89     int number;
90     PBoolean autonumber;
91 };
92 
93 PLIST(NamedNumberList, NamedNumber);
94 
95 
96 // Types
97 
98 class TypeBase;
99 
100 PLIST(TypesList, TypeBase);
101 PSORTED_LIST(SortedTypesList, TypeBase);
102 
103 class Tag : public PObject
104 {
105     PCLASSINFO(Tag, PObject);
106   public:
107     enum Type {
108       Universal,
109       Application,
110       ContextSpecific,
111       Private
112     };
113     enum UniversalTags {
114       IllegalUniversalTag,
115       UniversalBoolean,
116       UniversalInteger,
117       UniversalBitString,
118       UniversalOctetString,
119       UniversalNull,
120       UniversalObjectId,
121       UniversalObjectDescriptor,
122       UniversalExternalType,
123       UniversalReal,
124       UniversalEnumeration,
125       UniversalEmbeddedPDV,
126       UniversalSequence = 16,
127       UniversalSet,
128       UniversalNumericString,
129       UniversalPrintableString,
130       UniversalTeletexString,
131       UniversalVideotexString,
132       UniversalIA5String,
133       UniversalUTCTime,
134       UniversalGeneralisedTime,
135       UniversalGraphicString,
136       UniversalVisibleString,
137       UniversalGeneralString,
138       UniversalUniversalString,
139       UniversalBMPString = 30
140     };
141     enum Mode {
142       Implicit,
143       Explicit,
144       Automatic
145     };
146     Tag(unsigned tagNum);
147 
148     void PrintOn(ostream &) const;
149 
150     Type type;
151     unsigned number;
152     Mode mode;
153 
154     static const char * classNames[];
155     static const char * modeNames[];
156 };
157 
158 
159 class ConstraintElementBase;
160 
161 PLIST(ConstraintElementList, ConstraintElementBase);
162 
163 
164 class Constraint : public PObject
165 {
166     PCLASSINFO(Constraint, PObject);
167   public:
168     Constraint(ConstraintElementBase * elmt);
169     Constraint(ConstraintElementList * std, PBoolean extend, ConstraintElementList * ext);
170 
171     void PrintOn(ostream &) const;
172 
IsExtendable()173     PBoolean IsExtendable() const { return extendable; }
174     void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
175     PBoolean ReferencesType(const TypeBase & type);
176 
177   protected:
178     ConstraintElementList standard;
179     PBoolean              extendable;
180     ConstraintElementList extensions;
181 };
182 
183 PLIST(ConstraintList, Constraint);
184 
185 
186 class ConstraintElementBase : public PObject
187 {
188     PCLASSINFO(ConstraintElementBase, PObject);
189   public:
190     ConstraintElementBase();
SetExclusions(ConstraintElementBase * excl)191     void SetExclusions(ConstraintElementBase * excl) { exclusions = excl; }
192 
193     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
194     virtual PBoolean ReferencesType(const TypeBase & type);
195 
196   protected:
197     ConstraintElementBase * exclusions;
198 };
199 
200 
201 class ConstrainAllConstraintElement : public ConstraintElementBase
202 {
203     PCLASSINFO(ConstrainAllConstraintElement, ConstraintElementBase);
204   public:
205     ConstrainAllConstraintElement(ConstraintElementBase * excl);
206 };
207 
208 
209 
210 class ElementListConstraintElement : public ConstraintElementBase
211 {
212     PCLASSINFO(ElementListConstraintElement, ConstraintElementBase);
213   public:
214     ElementListConstraintElement(ConstraintElementList * list);
215     void PrintOn(ostream &) const;
216 
217     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
218     virtual PBoolean ReferencesType(const TypeBase & type);
219 
220   protected:
221     ConstraintElementList elements;
222 };
223 
224 
225 class ValueBase;
226 
227 class SingleValueConstraintElement : public ConstraintElementBase
228 {
229     PCLASSINFO(SingleValueConstraintElement, ConstraintElementBase);
230   public:
231     SingleValueConstraintElement(ValueBase * val);
232     ~SingleValueConstraintElement();
233     void PrintOn(ostream &) const;
234 
235     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
236 
237   protected:
238     ValueBase * value;
239 };
240 
241 
242 class ValueRangeConstraintElement : public ConstraintElementBase
243 {
244     PCLASSINFO(ValueRangeConstraintElement, ConstraintElementBase);
245   public:
246     ValueRangeConstraintElement(ValueBase * lowerBound, ValueBase * upperBound);
247     ~ValueRangeConstraintElement();
248     void PrintOn(ostream &) const;
249 
250     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
251 
252   protected:
253     ValueBase * lower;
254     ValueBase * upper;
255 };
256 
257 
258 class TypeBase;
259 
260 class SubTypeConstraintElement : public ConstraintElementBase
261 {
262     PCLASSINFO(SubTypeConstraintElement, ConstraintElementBase);
263   public:
264     SubTypeConstraintElement(TypeBase * typ);
265     ~SubTypeConstraintElement();
266     void PrintOn(ostream &) const;
267     void GenerateCplusplus(const PString &, ostream &, ostream &);
268     virtual PBoolean ReferencesType(const TypeBase & type);
269   protected:
270     TypeBase * subtype;
271 };
272 
273 
274 class NestedConstraintConstraintElement : public ConstraintElementBase
275 {
276     PCLASSINFO(NestedConstraintConstraintElement, ConstraintElementBase);
277   public:
278     NestedConstraintConstraintElement(Constraint * con);
279     ~NestedConstraintConstraintElement();
280 
281     virtual PBoolean ReferencesType(const TypeBase & type);
282 
283   protected:
284     Constraint * constraint;
285 };
286 
287 
288 class SizeConstraintElement : public NestedConstraintConstraintElement
289 {
290     PCLASSINFO(SizeConstraintElement, NestedConstraintConstraintElement);
291   public:
292     SizeConstraintElement(Constraint * constraint);
293     void PrintOn(ostream &) const;
294     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
295 };
296 
297 
298 class FromConstraintElement : public NestedConstraintConstraintElement
299 {
300     PCLASSINFO(FromConstraintElement, NestedConstraintConstraintElement);
301   public:
302     FromConstraintElement(Constraint * constraint);
303     void PrintOn(ostream &) const;
304     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
305 };
306 
307 
308 class WithComponentConstraintElement : public NestedConstraintConstraintElement
309 {
310     PCLASSINFO(WithComponentConstraintElement, NestedConstraintConstraintElement);
311   public:
312     WithComponentConstraintElement(PString * name, Constraint * constraint, int presence);
313     void PrintOn(ostream &) const;
314     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
315 
316     enum {
317       Present,
318       Absent,
319       Optional,
320       Default
321     };
322 
323   protected:
324     PString name;
325     int     presence;
326 };
327 
328 
329 class InnerTypeConstraintElement : public ElementListConstraintElement
330 {
331     PCLASSINFO(InnerTypeConstraintElement, ElementListConstraintElement);
332   public:
333     InnerTypeConstraintElement(ConstraintElementList * list, PBoolean partial);
334 
335     void PrintOn(ostream &) const;
336     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
337 
338   protected:
339     PBoolean partial;
340 };
341 
342 
343 class UserDefinedConstraintElement : public ConstraintElementBase
344 {
345     PCLASSINFO(UserDefinedConstraintElement, ConstraintElementBase);
346   public:
347     UserDefinedConstraintElement(TypesList * types);
348     void PrintOn(ostream &) const;
349     virtual void GenerateCplusplus(const PString & fn, ostream & hdr, ostream & cxx);
350   protected:
351     TypesList types;
352 };
353 
354 
355 
356 class TypeBase : public PObject
357 {
358     PCLASSINFO(TypeBase, PObject);
359   public:
360     Comparison Compare(const PObject & obj) const;
361     void PrintOn(ostream &) const;
362 
363     virtual int GetIdentifierTokenContext() const;
364     virtual int GetBraceTokenContext() const;
365 
GetName()366     const PString & GetName() const { return name; }
367     void SetName(PString * name);
GetIdentifier()368     PString GetIdentifier() const { return identifier; }
369     void SetTag(Tag::Type cls, unsigned num, Tag::Mode mode);
GetTag()370     const Tag & GetTag() const { return tag; }
HasNonStandardTag()371     PBoolean HasNonStandardTag() const { return tag != defaultTag; }
372     void SetParameters(PStringList * list);
AddConstraint(Constraint * constraint)373     void AddConstraint(Constraint * constraint) { constraints.Append(constraint); }
HasConstraints()374     PBoolean HasConstraints() const { return constraints.GetSize() > 0; }
375     void MoveConstraints(TypeBase * from);
HasParameters()376     PBoolean HasParameters() const { return !parameters.IsEmpty(); }
IsOptional()377     PBoolean IsOptional() const { return isOptional; }
SetOptional()378     void SetOptional() { isOptional = TRUE; }
SetDefaultValue(ValueBase * value)379     void SetDefaultValue(ValueBase * value) { defaultValue = value; }
GetTemplatePrefix()380     const PString & GetTemplatePrefix() const { return templatePrefix; }
GetClassNameString()381     const PString & GetClassNameString() const { return classNameString; }
382 
383     virtual void AdjustIdentifier();
384     virtual void FlattenUsedTypes();
385     virtual TypeBase * FlattenThisType(const TypeBase & parent);
386     virtual PBoolean IsChoice() const;
387     virtual PBoolean IsParameterizedType() const;
388     virtual PBoolean IsPrimitiveType() const;
389     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
390     virtual void GenerateForwardDecls(ostream & hdr);
391     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
392     virtual const char * GetAncestorClass() const = 0;
393     virtual PString GetTypeName() const;
394     virtual PBoolean CanReferenceType() const;
395     virtual PBoolean ReferencesType(const TypeBase & type);
396     virtual void SetImportPrefix(const PString &);
397     virtual PBoolean IsParameterisedImport() const;
398 
IsGenerated()399     PBoolean IsGenerated() const { return isGenerated; }
400     void BeginGenerateCplusplus(ostream & hdr, ostream & cxx);
401     void EndGenerateCplusplus(ostream & hdr, ostream & cxx);
402     void GenerateCplusplusConstructor(ostream & hdr, ostream & cxx);
403     void GenerateCplusplusConstraints(const PString & prefix, ostream & hdr, ostream & cxx);
404 
405   protected:
406     TypeBase(unsigned tagNum);
407     TypeBase(TypeBase * copy);
408 
409     void PrintStart(ostream &) const;
410     void PrintFinish(ostream &) const;
411 
412     PString        name;
413     PString        identifier;
414     Tag            tag;
415     Tag            defaultTag;
416     ConstraintList constraints;
417     PBoolean           isOptional;
418     ValueBase    * defaultValue;
419     PBoolean           isGenerated;
420     PStringList    parameters;
421     PString        templatePrefix;
422     PString        classNameString;
423 };
424 
425 
426 class DefinedType : public TypeBase
427 {
428     PCLASSINFO(DefinedType, TypeBase);
429   public:
430     DefinedType(PString * name, PBoolean parameter);
431     DefinedType(TypeBase * refType, TypeBase * bType);
432     DefinedType(TypeBase * refType, const PString & name);
433     DefinedType(TypeBase * refType, const TypeBase & parent);
434 
435     void PrintOn(ostream &) const;
436 
437     virtual PBoolean IsChoice() const;
438     virtual PBoolean IsParameterizedType() const;
439     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
440     virtual const char * GetAncestorClass() const;
441     virtual PString GetTypeName() const;
442     virtual PBoolean CanReferenceType() const;
443     virtual PBoolean ReferencesType(const TypeBase & type);
444 
445   protected:
446     void ConstructFromType(TypeBase * refType, const PString & name);
447 
448     PString referenceName;
449     TypeBase * baseType;
450     PBoolean unresolved;
451 };
452 
453 
454 class ParameterizedType : public DefinedType
455 {
456     PCLASSINFO(ParameterizedType, DefinedType);
457   public:
458     ParameterizedType(PString * name, TypesList * args);
459 
460     void PrintOn(ostream &) const;
461 
462     virtual PBoolean IsParameterizedType() const;
463     virtual PString GetTypeName() const;
464     virtual PBoolean ReferencesType(const TypeBase & type);
465 
466   protected:
467     TypesList arguments;
468 };
469 
470 
471 class SelectionType : public TypeBase
472 {
473     PCLASSINFO(SelectionType, TypeBase);
474   public:
475     SelectionType(PString * name, TypeBase * base);
476     ~SelectionType();
477 
478     void PrintOn(ostream &) const;
479 
480     virtual void FlattenUsedTypes();
481     virtual TypeBase * FlattenThisType(const TypeBase & parent);
482     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
483     virtual const char * GetAncestorClass() const;
484     virtual PBoolean CanReferenceType() const;
485     virtual PBoolean ReferencesType(const TypeBase & type);
486 
487   protected:
488     PString selection;
489     TypeBase * baseType;
490 };
491 
492 
493 class BooleanType : public TypeBase
494 {
495     PCLASSINFO(BooleanType, TypeBase);
496   public:
497     BooleanType();
498     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
499     virtual const char * GetAncestorClass() const;
500 };
501 
502 
503 class IntegerType : public TypeBase
504 {
505     PCLASSINFO(IntegerType, TypeBase);
506   public:
507     IntegerType();
508     IntegerType(NamedNumberList *);
509     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
510     virtual const char * GetAncestorClass() const;
511   protected:
512     NamedNumberList allowedValues;
513 };
514 
515 
516 class EnumeratedType : public TypeBase
517 {
518     PCLASSINFO(EnumeratedType, TypeBase);
519   public:
520     EnumeratedType(NamedNumberList * enums, PBoolean extend, NamedNumberList * ext);
521     void PrintOn(ostream &) const;
522     virtual TypeBase * FlattenThisType(const TypeBase & parent);
523     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
524     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
525     virtual const char * GetAncestorClass() const;
526   protected:
527     NamedNumberList enumerations;
528     PINDEX numEnums;
529     PBoolean extendable;
530 };
531 
532 
533 class RealType : public TypeBase
534 {
535     PCLASSINFO(RealType, TypeBase);
536   public:
537     RealType();
538     virtual const char * GetAncestorClass() const;
539 };
540 
541 
542 class BitStringType : public TypeBase
543 {
544     PCLASSINFO(BitStringType, TypeBase);
545   public:
546     BitStringType();
547     BitStringType(NamedNumberList *);
548     virtual int GetIdentifierTokenContext() const;
549     virtual int GetBraceTokenContext() const;
550     virtual const char * GetAncestorClass() const;
551   protected:
552     NamedNumberList allowedBits;
553 };
554 
555 
556 class OctetStringType : public TypeBase
557 {
558     PCLASSINFO(OctetStringType, TypeBase);
559   public:
560     OctetStringType();
561     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
562     virtual const char * GetAncestorClass() const;
563 };
564 
565 
566 class NullType : public TypeBase
567 {
568     PCLASSINFO(NullType, TypeBase);
569   public:
570     NullType();
571     virtual const char * GetAncestorClass() const;
572 };
573 
574 
575 class SequenceType : public TypeBase
576 {
577     PCLASSINFO(SequenceType, TypeBase);
578     void PrintOn(ostream &) const;
579   public:
580     SequenceType(TypesList * std,
581                  PBoolean extendable,
582                  TypesList * extensions,
583                  unsigned tagNum = Tag::UniversalSequence);
584     virtual void FlattenUsedTypes();
585     virtual TypeBase * FlattenThisType(const TypeBase & parent);
586     virtual PBoolean IsPrimitiveType() const;
587     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
588     virtual const char * GetAncestorClass() const;
589     virtual PBoolean CanReferenceType() const;
590     virtual PBoolean ReferencesType(const TypeBase & type);
591   protected:
592     TypesList fields;
593     PINDEX numFields;
594     PBoolean extendable;
595 };
596 
597 
598 class SequenceOfType : public TypeBase
599 {
600     PCLASSINFO(SequenceOfType, TypeBase);
601   public:
602     SequenceOfType(TypeBase * base, Constraint * constraint, unsigned tag = Tag::UniversalSequence);
603     ~SequenceOfType();
604     void PrintOn(ostream &) const;
605     virtual void FlattenUsedTypes();
606     virtual TypeBase * FlattenThisType(const TypeBase & parent);
607     virtual PBoolean IsPrimitiveType() const;
608     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
609     virtual void GenerateForwardDecls(ostream & hdr);
610     virtual const char * GetAncestorClass() const;
611     virtual PBoolean CanReferenceType() const;
612     virtual PBoolean ReferencesType(const TypeBase & type);
613   protected:
614     TypeBase * baseType;
615 };
616 
617 
618 class SetType : public SequenceType
619 {
620     PCLASSINFO(SetType, SequenceType);
621   public:
622     SetType();
623     SetType(SequenceType * seq);
624     virtual const char * GetAncestorClass() const;
625 };
626 
627 
628 class SetOfType : public SequenceOfType
629 {
630     PCLASSINFO(SetOfType, SequenceOfType);
631   public:
632     SetOfType(TypeBase * base, Constraint * constraint);
633 };
634 
635 
636 class ChoiceType : public SequenceType
637 {
638     PCLASSINFO(ChoiceType, SequenceType);
639   public:
640     ChoiceType(TypesList * std = NULL,
641                PBoolean extendable = FALSE,
642                TypesList * extensions = NULL);
643     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
644     virtual void GenerateForwardDecls(ostream & hdr);
645     virtual PBoolean IsPrimitiveType() const;
646     virtual PBoolean IsChoice() const;
647     virtual const char * GetAncestorClass() const;
648     virtual PBoolean ReferencesType(const TypeBase & type);
649 };
650 
651 
652 class EmbeddedPDVType : public TypeBase
653 {
654     PCLASSINFO(EmbeddedPDVType, TypeBase);
655   public:
656     EmbeddedPDVType();
657     virtual const char * GetAncestorClass() const;
658 };
659 
660 
661 class ExternalType : public TypeBase
662 {
663     PCLASSINFO(ExternalType, TypeBase);
664   public:
665     ExternalType();
666     virtual const char * GetAncestorClass() const;
667 };
668 
669 
670 class AnyType : public TypeBase
671 {
672     PCLASSINFO(AnyType, TypeBase);
673   public:
674     AnyType(PString * ident);
675     void PrintOn(ostream & strm) const;
676     virtual const char * GetAncestorClass() const;
677   protected:
678     PString identifier;
679 };
680 
681 
682 class StringTypeBase : public TypeBase
683 {
684     PCLASSINFO(StringTypeBase, TypeBase);
685   public:
686     StringTypeBase(int tag);
687     virtual int GetBraceTokenContext() const;
688     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
689 };
690 
691 
692 class BMPStringType : public StringTypeBase
693 {
694     PCLASSINFO(BMPStringType, StringTypeBase);
695   public:
696     BMPStringType();
697     virtual const char * GetAncestorClass() const;
698     virtual void GenerateOperators(ostream & hdr, ostream & cxx, const TypeBase & actualType);
699 };
700 
701 
702 class GeneralStringType : public StringTypeBase
703 {
704     PCLASSINFO(GeneralStringType, StringTypeBase);
705   public:
706     GeneralStringType();
707     virtual const char * GetAncestorClass() const;
708 };
709 
710 
711 class GraphicStringType : public StringTypeBase
712 {
713     PCLASSINFO(GraphicStringType, StringTypeBase);
714   public:
715     GraphicStringType();
716     virtual const char * GetAncestorClass() const;
717 };
718 
719 
720 class IA5StringType : public StringTypeBase
721 {
722     PCLASSINFO(IA5StringType, StringTypeBase);
723   public:
724     IA5StringType();
725     virtual const char * GetAncestorClass() const;
726 };
727 
728 
729 class ISO646StringType : public StringTypeBase
730 {
731     PCLASSINFO(ISO646StringType, StringTypeBase);
732   public:
733     ISO646StringType();
734     virtual const char * GetAncestorClass() const;
735 };
736 
737 
738 class NumericStringType : public StringTypeBase
739 {
740     PCLASSINFO(NumericStringType, StringTypeBase);
741   public:
742     NumericStringType();
743     virtual const char * GetAncestorClass() const;
744 };
745 
746 
747 class PrintableStringType : public StringTypeBase
748 {
749     PCLASSINFO(PrintableStringType, StringTypeBase);
750   public:
751     PrintableStringType();
752     virtual const char * GetAncestorClass() const;
753 };
754 
755 
756 class TeletexStringType : public StringTypeBase
757 {
758     PCLASSINFO(TeletexStringType, StringTypeBase);
759   public:
760     TeletexStringType();
761     virtual const char * GetAncestorClass() const;
762 };
763 
764 
765 class T61StringType : public StringTypeBase
766 {
767     PCLASSINFO(T61StringType, StringTypeBase);
768   public:
769     T61StringType();
770     virtual const char * GetAncestorClass() const;
771 };
772 
773 
774 class UniversalStringType : public StringTypeBase
775 {
776     PCLASSINFO(UniversalStringType, StringTypeBase);
777   public:
778     UniversalStringType();
779     virtual const char * GetAncestorClass() const;
780 };
781 
782 
783 class VideotexStringType : public StringTypeBase
784 {
785     PCLASSINFO(VideotexStringType, StringTypeBase);
786   public:
787     VideotexStringType();
788     virtual const char * GetAncestorClass() const;
789 };
790 
791 
792 class VisibleStringType : public StringTypeBase
793 {
794     PCLASSINFO(VisibleStringType, StringTypeBase);
795   public:
796     VisibleStringType();
797     virtual const char * GetAncestorClass() const;
798 };
799 
800 
801 class UnrestrictedCharacterStringType : public StringTypeBase
802 {
803     PCLASSINFO(UnrestrictedCharacterStringType, StringTypeBase);
804   public:
805     UnrestrictedCharacterStringType();
806     virtual const char * GetAncestorClass() const;
807 };
808 
809 
810 class GeneralizedTimeType : public TypeBase
811 {
812     PCLASSINFO(GeneralizedTimeType, TypeBase);
813   public:
814     GeneralizedTimeType();
815     virtual const char * GetAncestorClass() const;
816 };
817 
818 
819 class UTCTimeType : public TypeBase
820 {
821     PCLASSINFO(UTCTimeType, TypeBase);
822   public:
823     UTCTimeType();
824     virtual const char * GetAncestorClass() const;
825 };
826 
827 
828 class ObjectDescriptorType : public TypeBase
829 {
830     PCLASSINFO(ObjectDescriptorType, TypeBase);
831   public:
832     ObjectDescriptorType();
833     virtual const char * GetAncestorClass() const;
834 };
835 
836 
837 class ObjectIdentifierType : public TypeBase
838 {
839     PCLASSINFO(ObjectIdentifierType, TypeBase);
840   public:
841     ObjectIdentifierType();
842     virtual int GetIdentifierTokenContext() const;
843     virtual int GetBraceTokenContext() const;
844     virtual const char * GetAncestorClass() const;
845 };
846 
847 
848 class ObjectClassFieldType : public TypeBase
849 {
850     PCLASSINFO(ObjectClassFieldType, TypeBase);
851   public:
852     ObjectClassFieldType(PString * objclass, PString * field);
853     virtual const char * GetAncestorClass() const;
854     void PrintOn(ostream &) const;
855     virtual TypeBase * FlattenThisType(const TypeBase & parent);
856     virtual PBoolean IsPrimitiveType() const;
857     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
858     virtual PBoolean CanReferenceType() const;
859     virtual PBoolean ReferencesType(const TypeBase & type);
860   protected:
861     PString asnObjectClassName;
862     PString asnObjectClassField;
863 };
864 
865 
866 class ImportedType : public TypeBase
867 {
868     PCLASSINFO(ImportedType, TypeBase);
869   public:
870     ImportedType(PString * name, PBoolean parameterised);
871     virtual const char * GetAncestorClass() const;
872     virtual void AdjustIdentifier();
873     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
874     virtual void SetImportPrefix(const PString &);
875     virtual PBoolean IsParameterisedImport() const;
876   protected:
877     PString modulePrefix;
878     PBoolean    parameterised;
879 };
880 
881 
882 class SearchType : public TypeBase
883 {
884     PCLASSINFO(SearchType, TypeBase);
885   public:
886     SearchType(const PString & name);
887     virtual const char * GetAncestorClass() const;
888 };
889 
890 
891 // Values
892 
893 class ValueBase : public PObject
894 {
895     PCLASSINFO(ValueBase, PObject);
896   public:
897     void SetValueName(PString * name);
GetName()898     const PString & GetName() const { return valueName; }
899 
900     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
901 
902   protected:
903     void PrintBase(ostream &) const;
904     PString valueName;
905 };
906 
907 PLIST(ValuesList, ValueBase);
908 
909 
910 class DefinedValue : public ValueBase
911 {
912     PCLASSINFO(DefinedValue, ValueBase);
913   public:
914     DefinedValue(PString * name);
915     void PrintOn(ostream &) const;
GetReference()916     const PString & GetReference() const { return referenceName; }
917     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
918   protected:
919     PString referenceName;
920     ValueBase * actualValue;
921     PBoolean unresolved;
922 };
923 
924 
925 class BooleanValue : public ValueBase
926 {
927     PCLASSINFO(BooleanValue, ValueBase);
928   public:
929     BooleanValue(PBoolean newVal);
930     void PrintOn(ostream &) const;
931     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
932   protected:
933     PBoolean value;
934 };
935 
936 
937 class IntegerValue : public ValueBase
938 {
939     PCLASSINFO(IntegerValue, ValueBase);
940   public:
941     IntegerValue(PInt64 newVal);
942     void PrintOn(ostream &) const;
943     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
944 
PInt64()945     operator PInt64() const { return value; }
946     operator long() const { return (long)value; }
947 
948   protected:
949     PInt64 value;
950 };
951 
952 
953 class RealValue : public ValueBase
954 {
955     PCLASSINFO(RealValue, ValueBase);
956   public:
957     RealValue(double newVal);
958   protected:
959     double value;
960 };
961 
962 
963 class OctetStringValue : public ValueBase
964 {
965     PCLASSINFO(OctetStringValue, ValueBase);
966   public:
OctetStringValue()967     OctetStringValue() { }
968     OctetStringValue(PString * newVal);
969   protected:
970     PBYTEArray value;
971 };
972 
973 
974 class BitStringValue : public ValueBase
975 {
976     PCLASSINFO(BitStringValue, ValueBase);
977   public:
BitStringValue()978     BitStringValue() { }
979     BitStringValue(PString * newVal);
980     BitStringValue(PStringList * newVal);
981   protected:
982     PBYTEArray value;
983 };
984 
985 
986 class NullValue : public ValueBase
987 {
988     PCLASSINFO(NullValue, ValueBase);
989 };
990 
991 
992 class CharacterValue : public ValueBase
993 {
994     PCLASSINFO(CharacterValue, ValueBase);
995   public:
996     CharacterValue(BYTE c);
997     CharacterValue(BYTE t1, BYTE t2);
998     CharacterValue(BYTE q1, BYTE q2, BYTE q3, BYTE q4);
999     void PrintOn(ostream &) const;
1000     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
1001   protected:
1002     unsigned value;
1003 };
1004 
1005 
1006 class CharacterStringValue : public ValueBase
1007 {
1008     PCLASSINFO(CharacterStringValue, ValueBase);
1009   public:
CharacterStringValue()1010     CharacterStringValue() { }
1011     CharacterStringValue(PString * newVal);
1012     CharacterStringValue(PStringList * newVal);
1013     void PrintOn(ostream &) const;
1014     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
1015   protected:
1016     PString value;
1017 };
1018 
1019 
1020 class ObjectIdentifierValue : public ValueBase
1021 {
1022     PCLASSINFO(ObjectIdentifierValue, ValueBase);
1023   public:
1024     ObjectIdentifierValue(PString * newVal);
1025     ObjectIdentifierValue(PStringList * newVal);
1026     void PrintOn(ostream &) const;
1027   protected:
1028     PStringList value;
1029 };
1030 
1031 
1032 class MinValue : public ValueBase
1033 {
1034     PCLASSINFO(MinValue, ValueBase);
1035   public:
1036     void PrintOn(ostream &) const;
1037     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
1038 };
1039 
1040 
1041 class MaxValue : public ValueBase
1042 {
1043     PCLASSINFO(MaxValue, ValueBase);
1044   public:
1045     void PrintOn(ostream &) const;
1046     virtual void GenerateCplusplus(ostream & hdr, ostream & cxx);
1047 };
1048 
1049 
1050 class SequenceValue : public ValueBase
1051 {
1052     PCLASSINFO(SequenceValue, ValueBase);
1053   public:
1054     SequenceValue(ValuesList * list = NULL);
1055     void PrintOn(ostream &) const;
1056   protected:
1057     ValuesList values;
1058 };
1059 
1060 
1061 class MibBase : public PObject
1062 {
1063     PCLASSINFO(MibBase, PObject);
1064   public:
1065     MibBase(PString * name, PString * descr, PString * refer, ValueBase * val);
1066     virtual ~MibBase();
1067   protected:
1068     PString name;
1069     PString description;
1070     PString reference;
1071     ValueBase * value;
1072 };
1073 
1074 PLIST(MibList, MibBase);
1075 
1076 
1077 class MibObject : public MibBase
1078 {
1079     PCLASSINFO(MibObject, MibBase);
1080   public:
1081     enum Access {
1082       read_only,
1083       read_write,
1084       write_only,
1085       not_accessible,
1086     };
1087     enum Status {
1088       mandatory,
1089       optional,
1090       obsolete,
1091       deprecated
1092     };
1093     MibObject(PString * name, TypeBase * type, Access acc, Status stat,
1094               PString * descr, PString * refer, PStringList * idx,
1095               ValueBase * defVal,
1096               ValueBase * setVal);
1097     ~MibObject();
1098     void PrintOn(ostream &) const;
1099   protected:
1100     TypeBase * type;
1101     Access access;
1102     Status status;
1103     PStringList index;
1104     ValueBase * defaultValue;
1105 };
1106 
1107 
1108 class MibTrap : public MibBase
1109 {
1110     PCLASSINFO(MibTrap, MibBase);
1111   public:
1112     MibTrap(PString * nam, ValueBase * ent, ValuesList * var,
1113             PString * descr, PString * refer, ValueBase * val);
1114     ~MibTrap();
1115     void PrintOn(ostream &) const;
1116   protected:
1117     ValueBase * enterprise;
1118     ValuesList variables;
1119 };
1120 
1121 
1122 class ImportModule : public PObject
1123 {
1124     PCLASSINFO(ImportModule, PObject);
1125   public:
1126     ImportModule(PString * name, TypesList * syms);
1127 
1128     void PrintOn(ostream &) const;
1129 
1130     void GenerateCplusplus(ostream & hdr, ostream & cxx);
1131 
1132     PString   fullModuleName;
1133   protected:
1134     PString   shortModuleName;
1135     PString   filename;
1136     PString   directoryPrefix;
1137     TypesList symbols;
1138 };
1139 
1140 PLIST(ImportsList, ImportModule);
1141 
1142 
1143 class ModuleDefinition : public PObject
1144 {
1145     PCLASSINFO(ModuleDefinition, PObject);
1146   public:
1147     ModuleDefinition(PString * name, PStringList * id, Tag::Mode defTagMode);
1148 
1149     void PrintOn(ostream &) const;
1150 
GetDefaultTagMode()1151     Tag::Mode GetDefaultTagMode() const { return defaultTagMode; }
1152 
1153     void SetExportAll();
1154     void SetExports(TypesList * syms);
1155 
IsImportModule(const PString & name)1156     bool IsImportModule( const PString & name ) const
1157     {
1158        for( PINDEX i = 0; i < imports.GetSize(); ++i )
1159        {
1160           if( imports[i].fullModuleName == name )
1161              return true;
1162        }
1163        return false;
1164     }
1165 
AddImport(ImportModule * mod)1166     void AddImport(ImportModule * mod)  { imports.Append(mod); }
AddType(TypeBase * type)1167     void AddType(TypeBase * type)       { types.Append(type); }
AddValue(ValueBase * val)1168     void AddValue(ValueBase * val)      { values.Append(val); }
AddMIB(MibBase * mib)1169     void AddMIB(MibBase * mib)          { mibs.Append(mib); }
1170 
1171     void AppendType(TypeBase * type);
1172     TypeBase * FindType(const PString & name);
GetValues()1173     const ValuesList & GetValues() const { return values; }
1174 
GetModuleName()1175     const PString & GetModuleName() const { return moduleName; }
GetPrefix()1176     const PString & GetPrefix()     const { return classNamePrefix; }
1177 
1178     PString GetImportModuleName(const PString & moduleName);
1179 
GetIndentLevel()1180     int GetIndentLevel() const { return indentLevel; }
SetIndentLevel(int delta)1181     void SetIndentLevel(int delta) { indentLevel += delta; }
1182 
UsingInlines()1183     PBoolean UsingInlines() const { return usingInlines; }
UsingOperators()1184     PBoolean UsingOperators() const { return usingOperators; }
1185 
1186     void GenerateCplusplus(const PFilePath & path,
1187                            const PString & modName,
1188                            const PString & headerDir,
1189                            unsigned numFiles,
1190                            PBoolean useNamespaces,
1191                            PBoolean useInlines,
1192                            PBoolean useOperators,
1193                            PBoolean verbose);
1194 
1195 
1196   protected:
1197     PString         moduleName;
1198     PString         classNamePrefix;
1199     PBoolean            separateClassFiles;
1200     PStringList     definitiveId;
1201     Tag::Mode       defaultTagMode;
1202     TypesList       exports;
1203     PBoolean            exportAll;
1204     ImportsList     imports;
1205     PStringToString importNames;
1206     TypesList       types;
1207     SortedTypesList sortedTypes;
1208     ValuesList      values;
1209     MibList         mibs;
1210     int             indentLevel;
1211     PBoolean            usingInlines;
1212     PBoolean            usingOperators;
1213 };
1214 
1215 
1216 extern ModuleDefinition * Module;
1217 
1218 
1219 #endif
1220