Beispiel #1
0
/* records */
static void parseKeywords (tokenInfo * const token, boolean local)
{
	switch (token->keyword)
	{
	case KEYWORD_END:
		fileSkipToCharacter (';');
		break;
	case KEYWORD_CONSTANT:
		parseConstant (local);
		break;
	case KEYWORD_TYPE:
		parseTypes (token);
		break;
	case KEYWORD_SUBTYPE:
		parseTypes (token);
		break;
	case KEYWORD_ENTITY:
		parseModule (token);
		break;
	case KEYWORD_COMPONENT:
		parseModule (token);
		break;
	case KEYWORD_FUNCTION:
		parseSubProgram (token);
		break;
	case KEYWORD_PROCEDURE:
		parseSubProgram (token);
		break;
	case KEYWORD_PACKAGE:
		parsePackage (token);
		break;
	default:
		break;
	}
}
Beispiel #2
0
/*
 * populate an EC_CONFIG from xml document
 *
 * <code>cfg</code> - structure to be populated
 * 
 * <code>config</code> - xml document read in memory
 */
int read_config(char * config, int size, EC_CONFIG * cfg)
{
    LIBXML_TEST_VERSION;
    cfg->doc = xmlReadMemory(config, size, NULL, NULL, 0);
    assert(cfg->doc);
    CONTEXT ctx;
    ctx.config = cfg;
    xmlNode * node = xmlDocGetRootElement(cfg->doc);
    xmlNode * c;
    parsing_result_type_t parsing_okay = PARSING_OKAY;
    for(c = node->children; c && parsing_okay; c = c->next)
    {
        if(c->type != XML_ELEMENT_NODE)
        {
            continue;
        }
        if(strcmp((char *)c->name, "devices") == 0)
        {
            parsing_okay = parseTypes(c, &ctx);
        }
        else if(strcmp((char *)c->name, "chain") == 0)
        {
            parsing_okay = parseChain(c, &ctx);
        }
        else if(strcmp((char *)c->name, "sdorequests") == 0)
        {
            parsing_okay = parseSdoRequests(c, &ctx);
        }
    }
    return parsing_okay;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    
    pANTLR3_UINT8 filename;
    pANTLR3_INPUT_STREAM input=NULL;
    pProtoJSLexer lxr;
    pANTLR3_COMMON_TOKEN_STREAM tstream;
    pProtoJSParser psr;
    ProtoJSParser_protocol_return     pbjAST;
    if (argc < 2 || argv[1] == NULL)
        filename = (pANTLR3_UINT8)"./input";
    else
        filename = (pANTLR3_UINT8)argv[1];
    const char * outputFilename="output";
    if (argc>=3) {
        outputFilename=argv[2];
    }
    char * csOut=NULL;
    char * cppOut=NULL;
    char * cppInclude=NULL;
    int argindex;
    const char *outputInternalNamespace="_ProtoJS_Internal";
    const char *outputExternalNamespace="";
    for (argindex=3;argindex<argc;++argindex) {
        
        if (strncmp(argv[argindex],"--cpp=",6)==0) {
            cppOut=argv[argindex]+6;
        }
        if (strncmp(argv[argindex],"--cs=",5)==0) {
            csOut=argv[argindex]+5;
        }
        if (strncmp(argv[argindex],"--include=",10)==0) {
            cppInclude=argv[argindex]+10;
        }
        if (strncmp(argv[argindex],"--inamespace=",13)==0) {
            outputInternalNamespace=argv[argindex]+13;
        }
        if (strncmp(argv[argindex],"--namespace=",12)==0) {
            outputExternalNamespace=argv[argindex]+12;
        }
    }
    char*package=parsePackage((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace);
    pANTLR3_HASH_TABLE qualifiedTypes=antlr3HashTableNew(11);
    parseTypes((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes);
    if(generateASTProto((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes,&pbjAST,&lxr,&psr,&tstream,&input)) {
        pANTLR3_COMMON_TREE_NODE_STREAM    nodes;
        nodes   = antlr3CommonTreeNodeStreamNewTree(pbjAST.tree, ANTLR3_SIZE_HINT); // sIZE HINT WILL SOON BE DEPRECATED!!
        pANTLR3_STRING s = nodes->stringFactory->newRaw(nodes->stringFactory);
        grammarToString(nodes->tnstream,nodes->root,NULL,s);
        FILE*fp=fopen(outputFilename,"w");
        if (!fp) {
            perror("Unable to open output file!");
            exit(2);
        }
        if (s->size>1)
            fwrite(s->chars,s->size-1,1,fp);
        fclose(fp);
        stringFree(s);
        nodes   ->free  (nodes);        nodes   = NULL;
    }
    psr->free(psr);
    psr = NULL;
    
    tstream->free(tstream);
    tstream = NULL;
    
    
    lxr->free(lxr);
    lxr = NULL;
    input->close(input);
    input = NULL;
    return 0;
}
Beispiel #4
0
void BPatch_module::parseTypesIfNecessary() {
    if( moduleTypes != NULL ) { 
    	return;
    	}
    if (hasBeenRemoved_) return;
    
    moduleTypes = BPatch_typeCollection::getModTypeCollection( this );
	// /* DEBUG */ fprintf( stderr, "%s[%d]: parsing module '%s' @ %p (file %s) with type collection %p\n",	__FILE__, __LINE__, mod->fileName().c_str(), this, mod->obj()->fileName().c_str(), moduleTypes );

#if ! defined( USES_DWARF_DEBUG )
    if( BPatch::bpatch->parseDebugInfo() ) {
		parseTypes();
		}
#elif defined( arch_x86 ) || defined( arch_x86_64 ) || defined( arch_ia64 )
	/* I'm not actually sure about IA-64, but certainly on the other two,
	   it's legal and not uncommon to mix STABS and DWARF debug information
	   in the same file.  However, this causes problems because of the
	   differences in DWARF and STABS numeric type IDs.  In DWARF, the numeric
	   type IDs are unique accross the entire file, and are used to resolve
	   forward type references.  Thus, we parse all STABS debug information
	   before parsing any DWARF information.  Furthermore, DWARF requires
	   that all the BPatch_functions exist before parsing.  Thus... */
	   
	if( BPatch::bpatch->parseDebugInfo() ) {
        const pdvector< mapped_module  *> & map_mods = mod->obj()->getModules();
        
        /* Ensure all functions and type collections are defined. */
        for( unsigned i = 0; i < map_mods.size(); i++ ) {
            // use map_mods[i] instead of a name to get a precise match
            BPatch_module * bpmod = img->findOrCreateModule( map_mods[i] );
            assert( bpmod != NULL );

            bpmod->getProcedures();

			if( bpmod->moduleTypes == NULL ) {
				bpmod->moduleTypes = BPatch_typeCollection::getModTypeCollection( bpmod );
				}
            } /* end function instantiation */
		
		/* We'll need to have two loops anyway, so use three for clarity. */
        for( unsigned i = 0; i < map_mods.size(); i++ ) {
            // use map_mods[i] instead of a name to get a precise match
            BPatch_module * bpmod = img->findOrCreateModule( map_mods[i] );
            assert( bpmod != NULL );

            image * moduleImage = bpmod->mod->obj()->parse_img();
            assert( moduleImage != NULL );
            const Object & moduleObject = moduleImage->getObject();
            
            if( moduleObject.hasStabInfo() ) {
				/* This will blow away previous information, but not its own. */
				bpmod->parseStabTypes();

	            /* Therefore, blow away left-over STABS information to avoid type conflicts. */
    	        bpmod->moduleTypes->clearNumberedTypes();            
				}
            } /* end STABS parsing */

        for( unsigned i = 0; i < map_mods.size(); i++ ) {
            // use map_mods[i] instead of a name to get a precise match
            BPatch_module * bpmod = img->findOrCreateModule( map_mods[i] );
            assert( bpmod != NULL );
            
            image * moduleImage = bpmod->mod->obj()->parse_img();
            assert( moduleImage != NULL );
            const Object & moduleObject = moduleImage->getObject();
            
            if( moduleObject.hasDwarfInfo() ) { bpmod->parseDwarfTypes(); }            
			} /* end DWARF parsing */
		} /* end if we'rep parsing debug information at all */
#else 
	#error DWARF on platforms other than 86, x86-64, and IA-64 is unsupported.
#endif /* ! defined( USES_DWARF_DEBUG ) */
	return;
	} /* end parseTypesIfNecessary() */