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

quote-class.cc

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 /*
00016   Copyright (c) 1995, 1996 Xerox Corporation.
00017   All Rights Reserved.
00018 
00019   Use and copying of this software and preparation of derivative works
00020   based upon this software are permitted. Any copy of this software or
00021   of any derivative work must include the above copyright notice of
00022   Xerox Corporation, this paragraph and the one after it.  Any
00023   distribution of this software or derivative works must comply with all
00024   applicable United States export control laws.
00025 
00026   This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
00027   ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
00028   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
00030   LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
00031   EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
00032   NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
00033   OF THE POSSIBILITY OF SUCH DAMAGES.
00034 */
00035 
00036 // Part of the implementation of QuoteClass is in metaclass.cc.
00037 
00038 #include <string.h>
00039 #include "ptree.h"
00040 #include "quote-class.h"
00041 #include "buffer.h"
00042 
00043 Ptree* QuoteClass::TranslateMemberCall(Environment* env,
00044                                        Ptree* member, Ptree* args)
00045 {
00046     Ptree* name = StripClassQualifier(member);
00047     char* str;
00048 
00049     if(Ptree::Eq(name, "qMake")){
00050         Ptree* arg1 = Ptree::First(Ptree::Second(args));
00051         if(arg1->Reify(str) && str != nil)
00052             return ProcessBackQuote(env, str, arg1, name);
00053         else
00054             ErrorMessage(env, "bad argument for qMake()", arg1, name);
00055     }
00056     else if(Ptree::Eq(name, "qMakeStatement")){
00057         WarnObsoleteness("Ptree::qMakeStatement()", "Ptree::qMake()");
00058         Ptree* arg1 = Ptree::First(Ptree::Second(args));
00059         if(arg1->Reify(str) && str != nil)
00060             return ProcessBackQuote(env, str, arg1, name);
00061         else
00062             ErrorMessage(env, "bad argument for qMakeStatement()", arg1, name);
00063     }
00064 
00065     return Class::TranslateMemberCall(env, member, args);
00066 }
00067 
00068 Ptree* QuoteClass::ProcessBackQuote(Environment* env,
00069                                     char* str, Ptree* arg, Ptree* exp)
00070 {
00071     ProgramString result;
00072 
00073     result << "(Ptree*)(PtreeHead()";
00074     while(*str != '\0')
00075         if(*str == '`'){
00076             result << '+';
00077             while(*++str != '`')
00078                 if(*str != '\0')
00079                     result << *str;
00080                 else{
00081                     ErrorMessage(env,
00082                                  "unmatched backquote for Ptree::qMake(): ",
00083                                  arg, exp);
00084                     break;
00085                 }
00086 
00087             ++str;
00088         }
00089         else{
00090             result << "+\"";
00091             while(*str != '`' && *str != '\0')
00092                 result << *str++;
00093 
00094             result << '"';
00095         }
00096 
00097     result << ')';
00098     char* rstr = (char*)result.Read(0);
00099     return new DupLeaf(rstr, strlen(rstr));
00100 }

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