Exemple #1
0
/**
 * interfaces in Obj-C look like:
 * 
 * @interface Class1 [ : SuperClass | (CategoryName) ] [ <Protocols> ]
 *         [ {
 *           ...
 *            }
 *         ]
 *         methods
 *         @end
 */
static void interfaceHandler(const char *keyword) {
  char *ident;
  char *proto = NULL;
  char *superclass = NULL;
  char *inheritance;
  int z;

  z = skipToNonWhite();

  ident = readToNonIdentifier(0);
  if (ident && *ident) {
    ident = eStrdup(ident);
   } else {
     return;
  }

  recordPosition();
  z = skipToNonWhite();
  if (z == '(') {
    char *category;
    char *newIdent;
    category = readCategoryTag();
    if (category) {
      newIdent = eMalloc(strlen(category) + strlen(ident) + 1);
      strcpy(newIdent, ident);
      strcat(newIdent, category);
      eFree(ident);
      ident = newIdent;
     }
  } else if (z == ':') {
     cppGetc();
     skipToNonWhite();
     superclass = readToNonIdentifier(0);
  }

  if (superclass && *superclass) {
    superclass = eStrdup(superclass);
  } else{
    superclass = eStrdup("");
  }

  proto = readProtocolTag();
  if (proto && *proto) {
    proto = eStrdup(proto);
  } else {
    proto = eStrdup("<>");
  }

  inheritance = eMalloc(strlen(proto) + strlen(superclass) + 1);
  strcpy(inheritance, superclass);
  strcat(inheritance, proto);

  emitObjCTag(ident, K_INTERFACE, 0, inheritance, TRUE);
  readObjCMethods(K_INTMETHOD, ident, inheritance);

  eFree(ident);
  eFree(proto);
  eFree(superclass);
  eFree(inheritance);
}
Exemple #2
0
/* createDynamicArray: create a dynamic array */
Array *createDynamicArray( Symbol *s )
{

    int     i, arraySize, stackPos;
    Array   *array;

    /* paranoia */
    eMemTest( "createDynamicArray: symbol", s );

    /* allocate space for structure */
    array = (Array *)eMalloc(sizeof(Array));
    array->isDynamic = 1;

    /* get the ranges */
    arraySize = 32;
    array->lower[0]        = 0;         /* count of used cells */
    array->upper[0]        = 32;        /* count of free cells */

    array->data.cell = (ArrayCell *)eMalloc(arraySize * sizeof(ArrayCell)) ;

    /* initialize array */
    for (i=0; i < arraySize; i++){
        array->data.cell[i].key = NULL;
        array->data.cell[i].data.datatype = DATA_UNDEFINED;
    }

    /* store pointer in variable */
    stackPos = varStackPos( s );
    stack[stackPos].datatype = DATA_ARRAY;
    stack[stackPos].value.array = array;

    return array;
}
Exemple #3
0
Fichier : main.c Projet : att/uwin
static boolean createTagsForAmigaWildcard (const char *const pattern)
{
    boolean resize = FALSE;
    struct AnchorPath *const anchor =
	    (struct AnchorPath *) eMalloc ((size_t) ANCHOR_SIZE);
    LONG result;

    memset (anchor, 0, (size_t) ANCHOR_SIZE);
    anchor->ap_Strlen = ANCHOR_BUF_SIZE;
    /* Allow '.' for current directory */
#ifdef APF_DODOT
    anchor->ap_Flags = APF_DODOT | APF_DOWILD;
#else
    anchor->ap_Flags = APF_DoDot | APF_DoWild;
#endif
    result = MatchFirst ((UBYTE *) pattern, anchor);
    while (result == 0)
    {
	resize |= createTagsForEntry ((char *) anchor->ap_Buf);
	result = MatchNext (anchor);
    }
    MatchEnd (anchor);
    eFree (anchor);
    return resize;
}
Exemple #4
0
static bool isPodWord (const char *word)
{
	bool result = false;
	if (isalpha (*word))
	{
		const char *const pods [] = {
			"head1", "head2", "head3", "head4", "over", "item", "back",
			"pod", "begin", "end", "for"
		};
		const size_t count = ARRAY_SIZE (pods);
		const char *white = strpbrk (word, " \t");
		const size_t len = (white!=NULL) ? (size_t)(white-word) : strlen (word);
		char *const id = (char*) eMalloc (len + 1);
		size_t i;
		strncpy (id, word, len);
		id [len] = '\0';
		for (i = 0  ;  i < count  &&  ! result  ;  ++i)
		{
			if (strcmp (id, pods [i]) == 0)
				result = true;
		}
		eFree (id);
	}
	return result;
}
Exemple #5
0
/* eCopyString: copy a string, report if error */
char *eCopyString(char *s)
{
    char    *t;

    t = (char *)eMalloc(strlen(s)+1);
    strcpy(t, s);
    return t;
}
Exemple #6
0
/* buildKey: build key from stack data */
char *buildKey( Array *array, Symbol *s )
{
    int     args, i, keylen;
    char    *index, *buffer;

/* FIX: should eventually just realloc when size is exceeded */

    /* create a buffer */
    buffer = (char *)eMalloc( 256 );
    buffer[0] = '\0';

    /* check arg count */
    args = (int)popNumber();

    /* there must be at least one index */
    if (args == 0) {
        ePrintf( Runtime, "Array %s[]x expects at least 1 index, not 0" );
    }

    /* build the key backwards, for speed */
    keylen = 0;
    for ( i = 1; i <= args; i++ ) {

        /* get index */
        index = popString();

        /* make sure it fits in the buffer */
        keylen += strlen( index );
        if (keylen >= 256) {
            ePrintf( Runtime, "Array key exceeds 256 characters" );
        }

        /* append to key */
        strcat( buffer, index );

	/*
	ivanixcu: debug
	need free allocated memory of index!
	printf("ivanixdebug: freeing (index) (%d)\n", *index );
	*/
	if (*index != '\0' ){
	    eFree( index );
	}

        if (i < args) {
            /* add delimiter */
            keylen += 1;
            if (keylen >= 256) {
                ePrintf( Runtime, "Array key exceeds 256 characters" );
            }
            /* replace with ASCII 34 eventually */
            strcat( buffer, "," );
        }
    }

    /* resize the buffer */
    return (char *)eRealloc( buffer, keylen+1 );
}
Exemple #7
0
static boolean isPodWord (const char *word)
{
/* <<<<<<< HEAD */
#if 1
	boolean result = FALSE;
	if (isalpha (*word))
	{
		const char *const pods [] = {
			"head1", "head2", "head3", "head4", "over", "item", "back",
			"pod", "begin", "end", "for"
		};
		const size_t count = sizeof (pods) / sizeof (pods [0]);
		const char *white = strpbrk (word, " \t");
		const size_t len = (white!=NULL) ? (size_t)(white-word) : strlen (word);
		char *const id = (char*) eMalloc (len + 1);
		size_t i;
		strncpy (id, word, len);
		id [len] = '\0';
		for (i = 0  ;  i < count  &&  ! result  ;  ++i)
		{
			if (strcmp (id, pods [i]) == 0)
				result = TRUE;
		}
		eFree (id);
	}
	return result;
/* ======= */
#else
	/* Perl POD words are three to five characters in size.  We use this
	 * fact to find (or not find) the right side of the word and then
	 * perform comparisons, if necessary, of POD words of that size.
	 */
	size_t len;
	for (len = 0; len < 6; ++len)
		if ('\0' == word[len] || ' ' == word[len] || '\t' == word[len])
			break;
	switch (len) {
		case 3:
			return 0 == strncmp(word, "end", 3)
				|| 0 == strncmp(word, "for", 3)
				|| 0 == strncmp(word, "pod", 3);
		case 4:
			return 0 == strncmp(word, "back", 4)
				|| 0 == strncmp(word, "item", 4)
				|| 0 == strncmp(word, "over", 4);
		case 5:
			return 0 == strncmp(word, "begin", 5)
				|| 0 == strncmp(word, "head1", 5)
				|| 0 == strncmp(word, "head2", 5)
				|| 0 == strncmp(word, "head3", 5)
				|| 0 == strncmp(word, "head4", 5);
		default:
			return FALSE;
	}
/* >>>>>>> f039977edb44f3d46aacd26cc486ce153b879b0e */
#endif
}
Exemple #8
0
static void cxxParserParseNextTokenApplyReplacement(
		const cppMacroInfo * pInfo,
		CXXToken * pParameterChainToken
	)
{
	CXX_DEBUG_ENTER();

	CXX_DEBUG_ASSERT(pInfo,"Info must be not null");
	CXX_DEBUG_ASSERT(pInfo->replacements,"There should be a replacement");

	if(!pInfo->hasParameterList)
	{
		CXX_DEBUG_ASSERT(!pParameterChainToken,"This shouldn't have been extracted");
	}

	CXXTokenChain * pParameters = NULL;
	const char ** aParameters = NULL;
	int iParameterCount = 0;

	if(pInfo->hasParameterList && pParameterChainToken && (pParameterChainToken->pChain->iCount >= 3))
	{
		// kill parenthesis
		cxxTokenChainDestroyFirst(pParameterChainToken->pChain);
		cxxTokenChainDestroyLast(pParameterChainToken->pChain);

		pParameters = cxxTokenChainSplitOnComma(
				pParameterChainToken->pChain
			);

		aParameters = (const char **)eMalloc(sizeof(const char *) * pParameters->iCount);
		CXXToken * pParam = cxxTokenChainFirst(pParameters);
		while(pParam)
		{
			aParameters[iParameterCount] = vStringValue(pParam->pszWord);
			iParameterCount++;
			pParam = pParam->pNext;
		}

		CXX_DEBUG_ASSERT(iParameterCount == pParameters->iCount,"Bad number of parameters found");
	}

	vString * pReplacement = cppBuildMacroReplacement(pInfo,aParameters,iParameterCount);

	if(pParameters)
	{
		cxxTokenChainDestroy(pParameters);
		eFree(aParameters);
	}

	CXX_DEBUG_PRINT("Applying complex replacement '%s'",vStringValue(pReplacement));

	cppUngetString(vStringValue(pReplacement),vStringLength(pReplacement));

	vStringDelete(pReplacement);

	CXX_DEBUG_LEAVE();
}
Exemple #9
0
static void* createToken (void *createArg)
{
	struct tokenInfoClass *klass = createArg;
	tokenInfo *token;

	token = eMalloc (sizeof (*token) + klass->extraSpace);
	token->klass = klass;
	token->string  = vStringNew ();

	return token;
}
Exemple #10
0
Node *opNode( int op, Node *left, Node *right )
{
    Node    *node;

    node = (Node *) eMalloc( sizeof( Node ) );
    node->op = op;
    node->left = left;
    node->right = right;
    node->next = NULL;
    node->trace = -1;    
    return node;
}
Exemple #11
0
/* create a new stack */
Stack *newStack( int size )
{
    Stack *stack;

    /* allocate stack */
    stack = (Stack *)eMalloc( sizeof( Stack ) +
                (sizeof(intptr_t) * (size)) );

    stack->tos = -1;
    stack->size = size;
    return stack; 
}
Exemple #12
0
extern void *eRealloc (void *const ptr, const size_t size)
{
	void *buffer;
	if (ptr == NULL)
		buffer = eMalloc (size);
	else
	{
		buffer = realloc (ptr, size);
		if (buffer == NULL)
			error (FATAL, "out of memory");
	}
	return buffer;
}
Exemple #13
0
extern void *eRealloc (void *const ptr, const size_t size)
{
	void *buffer;
	if (ptr == NULL)
		buffer = eMalloc (size);
	else
	{
		buffer = realloc (ptr, size);
		if (buffer == NULL)
		{
			fprintf(stderr, "out of memory");
			abort ();
		}
	}
	return buffer;
}
Exemple #14
0
static void parseKinds (
		const char* const kinds, char* const kind, char** const kindName,
		char **description)
{
	*kind = '\0';
	*kindName = NULL;
	*description = NULL;
	if (kinds == NULL  ||  kinds [0] == '\0')
	{
		*kind = 'r';
		*kindName = eStrdup ("regex");
	}
	else if (kinds [0] != '\0')
	{
		const char* k = kinds;
		if (k [0] != ','  &&  (k [1] == ','  ||  k [1] == '\0'))
			*kind = *k++;
		else
			*kind = 'r';
		if (*k == ',')
			++k;
		if (k [0] == '\0')
			*kindName = eStrdup ("regex");
		else
		{
			const char *const comma = strchr (k, ',');
			if (comma == NULL)
				*kindName = eStrdup (k);
			else
			{
				*kindName = (char*) eMalloc (comma - k + 1);
				strncpy (*kindName, k, comma - k);
				(*kindName) [comma - k] = '\0';
				k = comma + 1;
				if (k [0] != '\0')
					*description = eStrdup (k);
			}
		}
	}
}
Exemple #15
0
/**
 * implementations in Obj-C look like:
 *
 * @implementation Class1 [ (CategoryName) ]
 *  [ {
 *     ...
 *    }
 *  ]
 *  methods
 *  @end
 */
static void implementationHandler(const char *keyword) {
  char *ident;
  int z;


  z = skipToNonWhite();
  ident = readToNonIdentifier(0);

  if (ident && *ident) {
    ident = eStrdup(ident);
  } else {
    return;
  }

  recordPosition();

  z = skipToNonWhite();

  if (z == '(') {
    char *category;
    char *newIdent;
    category = readCategoryTag();
    if (category) {
      newIdent = eMalloc(strlen(category) + strlen(ident) + 1);
      strcpy(newIdent, ident);
      strcat(newIdent, category);
      eFree(ident);
      ident = newIdent;
    }
  } 

  emitObjCTag(ident, K_IMPLEMENTATION, 0, 0, TRUE);
  readObjCMethods(K_IMPMETHOD, ident, 0);

  eFree(ident);
}
Exemple #16
0
extern void initFieldDescs (void)
{
	int i;
	fieldDesc *fdesc;

	Assert (fieldDescs == NULL);

	fieldDescAllocated
	  = ARRAY_SIZE (fieldSpecsFixed)
	  + ARRAY_SIZE (fieldSpecsExuberant)
	  + ARRAY_SIZE (fieldSpecsUniversal);
	fieldDescs = xMalloc (fieldDescAllocated, fieldDesc);

	fieldDescUsed = 0;

	for (i = 0; i < ARRAY_SIZE (fieldSpecsFixed); i++)
	{
		fdesc = fieldDescs + i + fieldDescUsed;
		fdesc->spec   = fieldSpecsFixed + i;
		fdesc->fixed  = 1;
		fdesc->buffer = NULL;
		fdesc->nameWithPrefix = fdesc->spec->name;
		fdesc->language = LANG_IGNORE;
		fdesc->sibling  = FIELD_UNKNOWN;
	}
	fieldDescUsed += ARRAY_SIZE (fieldSpecsFixed);

	for (i = 0; i < ARRAY_SIZE (fieldSpecsExuberant); i++)
	{
		fdesc = fieldDescs + i + fieldDescUsed;
		fdesc->spec = fieldSpecsExuberant +i;
		fdesc->fixed = 0;
		fdesc->buffer = NULL;
		fdesc->nameWithPrefix = fdesc->spec->name;
		fdesc->language = LANG_IGNORE;
		fdesc->sibling  = FIELD_UNKNOWN;
	}
	fieldDescUsed += ARRAY_SIZE (fieldSpecsExuberant);

	for (i = 0; i < ARRAY_SIZE (fieldSpecsUniversal); i++)
	{
		char *nameWithPrefix;

		fdesc = fieldDescs + i + fieldDescUsed;
		fdesc->spec = fieldSpecsUniversal + i;
		fdesc->fixed = 0;
		fdesc->buffer = NULL;

		if (fdesc->spec->name)
		{
			nameWithPrefix = eMalloc (sizeof CTAGS_FIELD_PREFIX + strlen (fdesc->spec->name) + 1);
			nameWithPrefix [0] = '\0';
			strcat (nameWithPrefix, CTAGS_FIELD_PREFIX);
			strcat (nameWithPrefix, fdesc->spec->name);
			fdesc->nameWithPrefix = nameWithPrefix;
		}
		else
			fdesc->nameWithPrefix = NULL;
		fdesc->language = LANG_IGNORE;
		fdesc->sibling  = FIELD_UNKNOWN;
	}
	fieldDescUsed += ARRAY_SIZE (fieldSpecsUniversal);

	Assert ( fieldDescAllocated == fieldDescUsed );
}
Exemple #17
0
/* createStaticArray: create an array; indexes are on stack */
Array *createStaticArray( Symbol *s )
{

    int     indexes, i, arraySize, stackPos;
    int     indexSize[NINDEX], lower[NINDEX], upper[NINDEX];
    Array   *array;

    /* stack holds:
            index count (on top)
            lower range of index 1
            upper range of index 1
            lower range of index 2
            upper range of index 2
            ...
            lower range of index n
            upper range of index n
    */


    /* paranoia */
    eMemTest( "createStaticArray: symbol", s );

    /* get the index */
    indexes = (int)popNumber();
    if (indexes > NINDEX) {
        ePrintf( Runtime, "array %s has %d dimensions, maximum is %d",
                    s->name, indexes, NINDEX );
    }

    /* get the ranges */
    arraySize = 1;
    for (i=0; i < indexes; i++) {
        lower[i] = (int)popNumber();
        upper[i] = (int)popNumber();

        if (lower[i] > upper[i]) {
            ePrintf( Runtime, "index %d of array %s: lower index (%d) greater than upper(%d) index",
                i+1, lower[i], upper[i] );
        }

        indexSize[i] = (upper[i]-lower[i])+1;
        arraySize *= indexSize[i];
    }

    /* allocate space for structure */
    array = (Array *)eMalloc(sizeof(Array));
    array->isDynamic = 0;
    array->data.item = (Variant *)eMalloc(arraySize * sizeof(Variant)) ;

    /* initialize array */
    for (i=0; i < arraySize; i++){
        array->data.item[i].datatype = DATA_NUMBER;
        array->data.item[i].value.number = 0;
    }

    /* store values in structure */
    array->indexes = indexes;
    array->elements = arraySize;
    for (i=0; i<indexes; i++) {
        array->lower[i] = lower[i];
        array->upper[i] = upper[i];
        arraySize = arraySize/indexSize[i];
        array->offset[i] = arraySize;
    }

    /* store pointer in variable */
    stackPos = varStackPos( s );
    stack[stackPos].datatype = DATA_ARRAY;
    stack[stackPos].value.array = array;

    return array;
}