Exemple #1
0
/**
 * Parses the class member (field or method) contained within the given token stack
 */
int CodeParser::parseClassMember( Scope* scope, TokenStack* stack ) {
	int errorCode = 0;
	TypeReference* type;
	const char* name;

	// the following types are parsed:
	// 	method layout: "[static] [final] type|[]| methodName(...) { ... }"
	//	field layout:  "[static] [final] type|[]| fieldName| = ....|"

	int step = 0;
	bool done = false;
	while( !done && stack->hasNext() ) {
		switch( ++step ) {
			// step 1: get the type of the class member (e.g. "string" or "string[]")
			case 1:
				// extract the name of the identifier
				if( !( type = parseType( scope, stack ) ) ) {
					return -1;
				}
				break;

			// step 2: get the class member name
			case 2:
				// get the type name
				if( !( name = state->getIdentifierName( stack, "class member" ) ) ) {
					return -2;
				}
				break;

			// step 3: get the class member instance (field or method)
			// 			method layout: "[static] [final] type methodName(...) { ... }"
			//			field layout:  "[static] [final] type fieldName[ = ....]"
			case 3:
				// each child should be a method (e.g. "type methodName(...)") or field (e.g. "type fieldName")
				// if there is a parenthesis block, it's likely to be a method
				errorCode = ( stack->peek()->getType() == tok::PARENTHESIS_BLOCK )
						? parseMethod( scope, name, type, stack )
						: parseField( scope, name, type, stack );

				// was there an error?
				if( errorCode ) {
					return errorCode;
				}
				done = true;
				break;
		}
	}

	// did it complete?
	if( !done ) {
		SYNTAX_ERROR( "unexpected end of statement", stack->last() );
		return -4;
	}

	// return the error code
	return 0;
}
Exemple #2
0
int HttpRequest::parseFirstLine( const CircularBuffer &buf ) {
   TRACE_BEGIN( LOG_LVL_INFO );

   std::string method;
   method.reserve( MAX_METHOD_SIZE );
   std::string uri;
   uri.reserve( MAX_URI_SIZE );
   std::string protocol;
   protocol.reserve( MAX_PROTO_SIZE );
   int i = 0;
   int c;

   while (1) {
      c = buf.byteAt( i++ );

      // If we requested a byte beyond the line size . . .
      if ( c == -1 or i > buf.getLength() ) {
         return -1;
      }

      if ( c == ' ' ) {
         break;
      }

      method += c;
      if ( method.size() >= MAX_METHOD_SIZE )
         return -1;
   }

   while (( c = buf.byteAt( i ) == ' ' )) {
      i++;

      // If we requested a byte beyond the line size . . .
      if ( c == -1 or i > buf.getLength() ) {
         return -1;
      }
   }

   while (1) {
      c = buf.byteAt( i++ );

      // If we requested a byte beyond the line size . . .
      if ( c == -1 or i > buf.getLength() ) {
         return -1;
      }

      if ( c == ' ' )
         break;

      uri += c;
      if ( uri.size() >= MAX_URI_SIZE )
         return -1;
   }

   while (1) {
      c = buf.byteAt( i++ );

      // If we requested a byte beyond the line size . . .
      if ( c == -1 or i > buf.getLength() ) {
         return -1;
      }

      if ( c == '\r' )
         break;

      protocol += c;
      if ( protocol.size() >= MAX_PROTO_SIZE )
         return -1;
   }

   // if CRLF move past LF
   if ( buf.byteAt( i ) == '\n' )
      i++;

   LOG( "Method %s, URI %s, Proto %s",
         method.c_str(), uri.c_str(), protocol.c_str() );

   parseProtocol( protocol.c_str() );
   parseMethod( method.c_str() );
   mUri = uri.c_str();

   return i;
}
Exemple #3
0
        void handleRESTRequest( const char *rq, // the full request
                                string url,
                                string& responseMsg,
                                int& responseCode,
                                vector<string>& headers // if completely empty, content-type: text/html will be added
                              ) {

            string::size_type first = url.find( "/" , 1 );
            if ( first == string::npos ) {
                responseCode = 400;
                return;
            }

            string method = parseMethod( rq );
            string dbname = url.substr( 1 , first - 1 );
            string coll = url.substr( first + 1 );
            string action = "";

            map<string,string> params;
            if ( coll.find( "?" ) != string::npos ) {
                parseParams( params , coll.substr( coll.find( "?" ) + 1 ) );
                coll = coll.substr( 0 , coll.find( "?" ) );
            }

            string::size_type last = coll.find_last_of( "/" );
            if ( last == string::npos ) {
                action = coll;
                coll = "_defaultCollection";
            }
            else {
                action = coll.substr( last + 1 );
                coll = coll.substr( 0 , last );
            }

            for ( string::size_type i=0; i<coll.size(); i++ )
                if ( coll[i] == '/' )
                    coll[i] = '.';

            string fullns = dbname + "." + coll;

            headers.push_back( (string)"x-action: " + action );
            headers.push_back( (string)"x-ns: " + fullns );
            headers.push_back( "Content-Type: text/plain;charset=utf-8" );

            stringstream ss;

            if ( method == "GET" ) {
                responseCode = 200;
                handleRESTQuery( fullns , action , params , responseCode , ss  );
            }
            else if ( method == "POST" ) {
                responseCode = 201;
                handlePost( fullns , body( rq ) , params , responseCode , ss  );
            }
            else {
                responseCode = 400;
                headers.push_back( "X_err: bad request" );
                ss << "don't know how to handle a [" << method << "]";
                out() << "don't know how to handle a [" << method << "]" << endl;
            }

            responseMsg = ss.str();
        }
int main(int argc, char *argv[])
{
    // Get options from the command line
    QApplication a(argc, argv);
    QTextStream qout(stdout);
    if (argc < 2) {
        qout << "Usage: " << argv[0] << " <qmlfile> [outputfolder]";
        return(1);
    }
    // source qml file
    QFileInfo qmlfile(argv[1]);
    if (!qmlfile.exists()) {
        qout << "File not found: " << qmlfile.filePath();
        return (1);
    }
    // output folder
    QFileInfo outputfolder("");
    if (argc == 3) {
        outputfolder.setFile(argv[2]);
        if (!outputfolder.isDir()) {
            qout << "Output folder doesn't exist: " << outputfolder.filePath();
            return (1);
        }
    }

    // Parse the qml file
    QDeclarativeEngine* qmlEngine = new QDeclarativeEngine();
    qmlEngine->addPluginPath("../../imports/com/nokia/symbian"); // component's own imports specified fully so point directly to import folder where dll built to
    //qmlEngine->addImportPath("../../imports");
    QDeclarativeComponent* qmlComponent = new QDeclarativeComponent(qmlEngine, QUrl::fromLocalFile(qmlfile.filePath()));
    if (qmlComponent->isError()) {
        qDebug() << qmlComponent->errors();
        return (1);
        }
    QObject* qmlObject = qmlComponent->create();
    if ( !qmlObject ) {
        qout << "Failed to load: " << qmlfile.path();
        qDebug() << qmlComponent->errors();
        return (1);
    }

    //explicit mapping of Qt types to QML types
    //it's too complicated to scan through the basic types using private headers so hard-coding this
    QMap<QString,QString> qmlBasicType;
    qmlBasicType.insert("QAction",                      "action");
    qmlBasicType.insert("bool",                         "bool");
    qmlBasicType.insert("QColor",                       "color");
    qmlBasicType.insert("QDateTime",                    "date");
    qmlBasicType.insert("double",                       "double");
    qmlBasicType.insert("enumeration",                  "enumeration");
    qmlBasicType.insert("QFont",                        "font");
    qmlBasicType.insert("int",                          "int");
    qmlBasicType.insert("ListProperty",                 "list");
    qmlBasicType.insert("QPointF",                      "point");
    qmlBasicType.insert("qreal",                        "real");
    qmlBasicType.insert("QRectF",                       "rect");
    qmlBasicType.insert("QSize",                        "size");
    qmlBasicType.insert("QString",                      "string");
    qmlBasicType.insert("QDateTime",                    "time"); //Duplicate...
    qmlBasicType.insert("QUrl",                         "url");
    qmlBasicType.insert("QVariant",                     "variant");
    qmlBasicType.insert("TransformOrigin",              "enumeration");
    qmlBasicType.insert("QVector3d",                    "vector3d");
    qmlBasicType.insert("QGraphicsObject",              "Item");
    qmlBasicType.insert("SStyleWrapper",                "style");
    qmlBasicType.insert("QObject",                      "QtObject");
    qmlBasicType.insert("QValidator",                   "validator");
    qmlBasicType.insert("SDeclarativeImplicitSizeItem", "Item");
    qmlBasicType.insert("ListProperty<QObject>",        "list<QtObject>");
    qmlBasicType.insert("ListProperty<QGraphicsObject>","list<Item>");


    // Get the component name and remove the _QMLTYPE part
    QString componentname(qmlObject->metaObject()->className());
    componentname =  componentname.left(componentname.indexOf("_QML"));

    QStringList memberlist;

    // Collect all the properties (excluding inherited)
    for(int i = qmlObject->metaObject()->propertyOffset() ; i < qmlObject->metaObject()->propertyCount(); ++i) {
        memberlist.append(parseProperty(&qmlObject->metaObject()->property(i),qmlBasicType,componentname));
    }

    // Collect all the methods (excluding inherited)
    for(int i = qmlObject->metaObject()->methodOffset() ; i < qmlObject->metaObject()->methodCount(); ++i) {
        memberlist.append(parseMethod(&qmlObject->metaObject()->method(i),qmlBasicType,componentname));
    }

    // Output the results
    memberlist.sort();
    if (outputfolder.exists()) { // output to file
        QFile outputfile(outputfolder.filePath() + "/" + componentname.toLower() + ".txt");
        if (outputfile.open(QFile::WriteOnly)) {
            QTextStream fout(&outputfile);
            for (int i=0; i<memberlist.size();i++) {
                if (memberlist.at(i) != QString::null)
                    fout << memberlist.at(i) << "\n";
            }
        }
        else {
            qout << "Failed to open: " << outputfile.fileName();
            return(1);
        }
        outputfile.close();
    }
    else { // output to console
        for (int i=0; i<memberlist.size();i++) {
            if (memberlist.at(i) != QString::null)
                qout << memberlist.at(i) << "\n";
        }
    }

}