Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

mop.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
00003 
00004   Permission to use, copy, distribute and modify this software and   
00005   its documentation for any purpose is hereby granted without fee,        
00006   provided that the above copyright notice appear in all copies and that 
00007   both that copyright notice and this permission notice appear in 
00008   supporting documentation.
00009 
00010   Shigeru Chiba makes no representations about the suitability of this 
00011   software for any purpose.  It is provided "as is" without express or
00012   implied warranty.
00013 */
00014 
00015 #ifndef _mop_h
00016 #define _mop_h
00017 
00018 #include "types.h"
00019 #include "ptree-core.h"
00020 #include "env.h"
00021 #include "typeinfo.h"
00022 #include "member.h"
00023 
00024 #include <iostream>
00025 
00026 class ClassArray;
00027 class Member;
00028 class MemberList;
00029 class ChangedMemberList;
00030 struct ChangedMemberList::Cmem;
00031 
00032 class OCXXMOP Class : public Object {
00033 public:
00034     Class() {}
00035     Class(Environment* e, char* name) { Construct(e, Ptree::Make(name)); }
00036     Class(Environment* e, Ptree* name) { Construct(e, name); }
00037 
00038     virtual void InitializeInstance(Ptree* def, Ptree* margs);
00039     virtual ~Class();
00040 
00041 // introspection
00042 
00043     Ptree* Comments();
00044     Ptree* Name();
00045     Ptree* BaseClasses();
00046     Ptree* Members();
00047     Ptree* Definition() { return definition; }
00048     virtual char* MetaclassName();      // automaticallly implemented
00049                                         // by Metaclass
00050     Class* NthBaseClass(int nth);
00051     Ptree* NthBaseClassName(int nth);
00052     bool IsSubclassOf(Ptree* name);
00053     bool IsImmediateSubclassOf(Ptree* name);
00054 
00055     bool NthMember(int nth, Member& member);
00056     bool LookupMember(Ptree* name);
00057     bool LookupMember(Ptree* name, Member& member, int index = 0);
00058     bool LookupMember(char* name);
00059     bool LookupMember(char* name, Member& member, int index = 0);
00060     MemberList* GetMemberList();
00061 
00062     // These are available only within Finalize()
00063     static ClassArray& AllClasses();
00064     int Subclasses(ClassArray& subclasses);
00065     static int Subclasses(Ptree* name, ClassArray& subclasses);
00066     int ImmediateSubclasses(ClassArray& subclasses);
00067     static int ImmediateSubclasses(Ptree* name, ClassArray& subclasses);
00068     static int InstancesOf(char* metaclass_name, ClassArray& classes);
00069 
00070     // obsolete
00071     Ptree* NthMemberName(int);
00072     int IsMember(Ptree*);
00073     bool LookupMemberType(Ptree*, TypeInfo&);
00074 
00075 // translation
00076 
00077     // these must be consistent with PUBLIC, PRIVATE, PROTECTED in token.h
00078     enum { Public = 298, Protected = 297, Private = 296, Undefined = 0 };
00079 
00080     virtual void TranslateClass(Environment*);
00081     void RemoveClass() { removed = TRUE; }
00082     void AddClassSpecifier(Ptree* spec);        // only for MSVC++
00083     void ChangeName(Ptree* name);
00084     void ChangeBaseClasses(Ptree*);
00085     void RemoveBaseClasses();
00086     void AppendBaseClass(Class* c, int specifier = Public,
00087                          bool is_virtual = false);
00088     void AppendBaseClass(char* class_name, int specifier = Public,
00089                          bool is_virtual = false);
00090     void AppendBaseClass(Ptree* class_name, int specifier = Public,
00091                          bool is_virtual = false);
00092 
00093     void ChangeMember(Member& changed_member);
00094     void AppendMember(Member& added_member, int specifier = Public);
00095     void AppendMember(Ptree* added_member);
00096     void RemoveMember(Member&);
00097 
00098     virtual void TranslateMemberFunction(Environment*, Member&);
00099 
00100     virtual Ptree* TranslateInitializer(Environment*, Ptree* var_name,
00101                                         Ptree* initializer);
00102 
00103     virtual Ptree* TranslateNew(Environment*,
00104                                 Ptree* header, Ptree* new_operator,
00105                                 Ptree* placement, Ptree* type_name,
00106                                 Ptree* arglist);
00107     virtual Ptree* TranslateDelete(Environment*, Ptree* op, Ptree* obj);
00108     virtual Ptree* TranslateAssign(Environment*, Ptree* left,
00109                                    Ptree* assign_op, Ptree* right);
00110     virtual Ptree* TranslateBinary(Environment*, Ptree* left,
00111                                    Ptree* binary_op, Ptree* right);
00112     virtual Ptree* TranslateUnary(Environment*,
00113                                   Ptree* unary_op, Ptree* object);
00114     virtual Ptree* TranslateSubscript(Environment*,
00115                                       Ptree* object, Ptree* index);
00116     virtual Ptree* TranslatePostfix(Environment*,
00117                                     Ptree* object, Ptree* postfix_op);
00118     virtual Ptree* TranslateFunctionCall(Environment*,
00119                                          Ptree* object, Ptree* arglist);
00120     virtual Ptree* TranslateMemberCall(Environment*,
00121                                        Ptree* object, Ptree* access_op,
00122                                        Ptree* member_name,
00123                                        Ptree* arglist);
00124     virtual Ptree* TranslateMemberCall(Environment*,
00125                                        Ptree* member_name, Ptree* arglist);
00126     virtual Ptree* TranslateMemberRead(Environment*,
00127                                        Ptree* object, Ptree* access_op,
00128                                        Ptree* member_name);
00129     virtual Ptree* TranslateMemberRead(Environment*, Ptree* member_name);
00130     virtual Ptree* TranslateMemberWrite(Environment*,
00131                                         Ptree* object, Ptree* access_op,
00132                                         Ptree* member_name,
00133                                         Ptree* assign_op, Ptree* expr);
00134     virtual Ptree* TranslateMemberWrite(Environment*,
00135                                         Ptree* member_name,
00136                                         Ptree* assign_op, Ptree* expr);
00137     virtual Ptree* TranslateUnaryOnMember(Environment*, Ptree* unary_op,
00138                                           Ptree* object, Ptree* access_op,
00139                                           Ptree* member_name);
00140     virtual Ptree* TranslateUnaryOnMember(Environment*, Ptree* unary_op,
00141                                           Ptree* member_name);
00142     virtual Ptree* TranslatePostfixOnMember(Environment*,
00143                                             Ptree* object, Ptree* access_op,
00144                                             Ptree* member_name,
00145                                             Ptree* postfix_op);
00146     virtual Ptree* TranslatePostfixOnMember(Environment*,
00147                                             Ptree* member_name,
00148                                             Ptree* postfix_op);
00149     virtual Ptree* TranslatePointer(Environment*, Ptree* var_name);
00150 
00151     virtual Ptree* TranslateUserStatement(Environment*,
00152                                           Ptree* object, Ptree* access_op,
00153                                           Ptree* keyword, Ptree* rest);
00154     virtual Ptree* TranslateStaticUserStatement(Environment*,
00155                                                 Ptree* keyword, Ptree* rest);
00156 
00157     static Ptree* StripClassQualifier(Ptree* qualified_name);
00158 
00159     Ptree* TranslateExpression(Environment*, Ptree* expr);
00160     Ptree* TranslateExpression(Environment*, Ptree* expr, TypeInfo& type);
00161     Ptree* TranslateStatement(Environment* env, Ptree* expr);   // obsolete
00162     Ptree* TranslateNewType(Environment* env, Ptree* type);
00163     Ptree* TranslateArguments(Environment*, Ptree* arglist);
00164     Ptree* TranslateFunctionBody(Environment*, Member& m, Ptree* body);
00165 
00166 // others
00167 
00168     Environment* GetEnvironment() { return class_environment; }
00169     virtual bool AcceptTemplate();
00170     static bool Initialize();
00171     static void FinalizeAll(ostream& out);
00172     virtual Ptree* FinalizeInstance();
00173     virtual Ptree* Finalize();          // obsolete
00174     static Ptree* FinalizeClass();
00175 
00176     static void RegisterNewModifier(char* keyword);
00177     static void RegisterNewAccessSpecifier(char* keyword);
00178     static void RegisterNewMemberModifier(char* keyword);
00179     static void RegisterNewWhileStatement(char* keyword);
00180     static void RegisterNewForStatement(char* keyword);
00181     static void RegisterNewClosureStatement(char* keyword);
00182     static void RegisterMetaclass(char* keyword, char* class_name);
00183 
00184     static void ChangeDefaultMetaclass(char* name);
00185     static void SetMetaclassForFunctions(char* name);
00186 
00187     static void InsertBeforeStatement(Environment*, Ptree*);
00188     static void AppendAfterStatement(Environment*, Ptree*);
00189     static void InsertBeforeToplevel(Environment*, Class*);
00190     static void InsertBeforeToplevel(Environment*, Member&);
00191     static void InsertBeforeToplevel(Environment*, Ptree*);
00192     static void AppendAfterToplevel(Environment*, Class*);
00193     static void AppendAfterToplevel(Environment*, Member&);
00194     static void AppendAfterToplevel(Environment*, Ptree*);
00195     bool InsertDeclaration(Environment*, Ptree* declaration);
00196     bool InsertDeclaration(Environment*, Ptree* declaration,
00197                            Ptree* key, void* client_data);
00198     void* LookupClientData(Environment*, Ptree* key);
00199 
00200     void ErrorMessage(Environment*, char* message, Ptree* name,
00201                       Ptree* where);
00202     void WarningMessage(Environment*, char* message, Ptree* name,
00203                         Ptree* where);
00204     void ErrorMessage(char* message, Ptree* name, Ptree* where);
00205     void WarningMessage(char* message, Ptree* name, Ptree* where);
00206 
00207     static bool RecordCmdLineOption(char* key, char* value);
00208     static bool LookupCmdLineOption(char* key);
00209     static bool LookupCmdLineOption(char* key, char*& value);
00210     static void WarnObsoleteness(char*, char* = nil);
00211 
00212 private:
00213     void Construct(Environment*, Ptree*);
00214 
00215     void SetEnvironment(Environment*);
00216     Ptree* GetClassSpecifier() { return new_class_specifier; }
00217     Ptree* GetNewName() { return new_class_name; }
00218     Ptree* GetBaseClasses() { return new_base_classes; }
00219     ChangedMemberList::Cmem* GetChangedMember(Ptree*);
00220     ChangedMemberList* GetAppendedMembers() { return appended_member_list; }
00221     Ptree* GetAppendedCode() { return appended_code; }
00222     void TranslateClassHasFinished() { done_decl_translation = TRUE; }
00223     void CheckValidity(char*);
00224 
00225 private:
00226     Ptree* definition;
00227     Ptree* full_definition;     // including a user keyword
00228     Environment* class_environment;
00229     MemberList* member_list;
00230 
00231     bool done_decl_translation;
00232     bool removed;
00233     ChangedMemberList* changed_member_list;
00234     ChangedMemberList* appended_member_list;
00235     Ptree* appended_code;
00236     Ptree* new_base_classes;
00237     Ptree* new_class_specifier;
00238     Ptree* new_class_name;
00239 
00240     static ClassArray* class_list;
00241 
00242     enum { MaxOptions = 8 };
00243     static int num_of_cmd_options;
00244     static char* cmd_options[MaxOptions * 2];
00245 
00246     static char* metaclass_for_c_functions;
00247     static Class* for_c_functions;
00248 
00249     static Ptree* class_t;
00250     static Ptree* empty_block_t;
00251     static Ptree* public_t;
00252     static Ptree* protected_t;
00253     static Ptree* private_t;
00254     static Ptree* virtual_t;
00255     static Ptree* colon_t;
00256     static Ptree* comma_t;
00257     static Ptree* semicolon_t;
00258 
00259 friend class Walker;
00260 friend class ClassWalker;
00261 friend class ClassBodyWalker;
00262 friend class Member;
00263 };
00264 
00265 class OCXXMOP TemplateClass : public Class {
00266 public:
00267     void InitializeInstance(Ptree* def, Ptree* margs);
00268     static bool Initialize();
00269     char* MetaclassName();
00270 
00271     Ptree* TemplateDefinition() { return template_definition; }
00272     Ptree* TemplateArguments();
00273     bool AcceptTemplate();
00274     virtual Ptree* TranslateInstantiation(Environment*, Ptree*);
00275 
00276 private:
00277     static Ptree* GetClassInTemplate(Ptree* def);
00278 
00279     Ptree* template_definition;
00280 };
00281 
00282 class OCXXMOP ClassArray : public LightObject {
00283 public:
00284     ClassArray(int = 16);
00285     uint Number() { return num; }
00286     Class*& operator [] (uint index) { return Ref(index); }
00287     Class*& Ref(uint index);
00288     void Append(Class*);
00289     void Clear() { num = 0; }
00290 
00291 private:
00292     uint num, size;
00293     Class** array;
00294 };
00295 
00296 
00297 // not documented class --- internal use only
00298 
00299 typedef Class* (*opcxx_MetaclassCreator)(Ptree*, Ptree*);
00300 
00301 class OCXXMOP opcxx_ListOfMetaclass {
00302 public:
00303     opcxx_ListOfMetaclass(char*, opcxx_MetaclassCreator,
00304                           bool (*)(), Ptree* (*)());
00305     static Class* New(Ptree*, Ptree*, Ptree*);
00306     static Class* New(char*, Ptree*, Ptree*);
00307     static void FinalizeAll(ostream&);
00308     static bool AlreadyRecorded(char*);
00309     static bool AlreadyRecorded(Ptree*);
00310     static void PrintAllMetaclasses();
00311 
00312 private:
00313     opcxx_ListOfMetaclass* next;
00314     char* name;
00315     opcxx_MetaclassCreator proc;
00316     Ptree* (*finalizer)();      // pointer to FinalizeClass()
00317     static opcxx_ListOfMetaclass* head;
00318 };
00319 
00320 #endif /* _mop_h */

Generated on Mon Feb 10 17:32:51 2003 for VFiasco Semantics Compiler by doxygen1.2.15