Type* compileBasicType(void) {
  Type* type;

  switch (lookAhead->tokenType) {
  case KW_INTEGER: 
    eat(KW_INTEGER); 
    type = makeIntType();
    break;
  case KW_CHAR: 
    eat(KW_CHAR); 
    type = makeCharType();
    break;
  case KW_FLOAT: 
    eat(KW_FLOAT); 
    type = makeFloatType();
    break;
  case KW_STRING: 
    eat(KW_STRING); 
    type = makeStringType();
    break;
  default:
    error(ERR_INVALID_BASICTYPE, lookAhead->lineNo, lookAhead->colNo);
    break;
  }
  return type;
}
ITypeInfo * getConcatResultType(IHqlExpression * expr)
{
    assertex(!"not sure if this is unicode safe, but appears not to be used");
    //first work out the maximum size of the target
    unsigned max = expr->numChildren();
    unsigned idx;
    unsigned totalSize = 0;
    bool unknown = false;
    type_t resultType = type_string;

    for (idx = 0; idx < max; idx++)
    {
        ITypeInfo * type = expr->queryChild(idx)->queryType();
        unsigned size = type->getStringLen();
        if (size == UNKNOWN_LENGTH)
            unknown = true;
        else
            totalSize += size;
        if (type->getTypeCode() == type_varstring)
            resultType = type_varstring;
    }

    if (unknown)
        totalSize = 1023;
    if (resultType == type_string)
        return makeStringType(totalSize, NULL, NULL);
    return makeVarStringType(totalSize);
}
Exemple #3
0
DataSourceMetaData::DataSourceMetaData(type_t typeCode)
{
    init();
    OwnedITypeInfo type;
    if (typeCode == type_unicode)
        type.setown(makeUnicodeType(UNKNOWN_LENGTH, 0));
    else
        type.setown(makeStringType(UNKNOWN_LENGTH, NULL, NULL));
    fields.append(*new DataSourceMetaItem(FVFFnone, "line", NULL, type));
}
Type* compileType(void) {
  Type* type;
  Type* elementType;
  int arraySize;
  Object* obj;

  switch (lookAhead->tokenType) {
  case KW_INTEGER: 
    eat(KW_INTEGER);
    type =  makeIntType();
    break;
  case KW_CHAR: 
    eat(KW_CHAR); 
    type = makeCharType();
    break;
  case KW_STRING:
    eat(KW_STRING);
    type=makeStringType();
    break;
  case KW_FLOAT:
    eat(KW_FLOAT);
    type=makeFloatType();
    break;
  case KW_ARRAY:
    eat(KW_ARRAY);
    eat(SB_LSEL);
    eat(TK_NUMBER);

    arraySize = currentToken->value;

    eat(SB_RSEL);
    eat(KW_OF);
    elementType = compileType();
    type = makeArrayType(arraySize, elementType);
    break;
  case TK_IDENT:
    eat(TK_IDENT);
    obj = checkDeclaredType(currentToken->string);
    type = duplicateType(obj->typeAttrs->actualType);
    break;
  default:
    error(ERR_INVALID_TYPE, lookAhead->lineNo, lookAhead->colNo);
    break;
  }
  return type;
}
TypePtr factor (void) {

	TypePtr thisType = NULL;
	switch (curToken) {
		case TKN_IDENTIFIER: {
			SymTableNodePtr IdPtr = NULL;
			searchAndFindAllSymTables(IdPtr);
			switch (IdPtr->defn.key) {
				case DFN_FUNCTION:
					crunchSymTableNodePtr(IdPtr);
					getToken();
					thisType = routineCall(IdPtr, 1);
					break;
				case DFN_CONST:
					crunchSymTableNodePtr(IdPtr);
					getToken();
					thisType = (TypePtr)(IdPtr->typePtr);
					break;
				default:
					thisType = (TypePtr)variable(IdPtr);
					break;
			}
			}
			break;
		case TKN_NUMBER: {
			SymTableNodePtr thisNode = searchSymTable(tokenString, SymTableDisplay[1]);
			if (!thisNode)
				thisNode = enterSymTable(tokenString, &SymTableDisplay[1]);
			if (curLiteral.type == LIT_INTEGER) {
				thisNode->typePtr = IntegerTypePtr;
				thisType = (TypePtr)(thisNode->typePtr);
				thisNode->defn.info.constant.value.integer = curLiteral.value.integer;
				}
			else {
				thisNode->typePtr = RealTypePtr;
				thisType = (TypePtr)(thisNode->typePtr);
				thisNode->defn.info.constant.value.real = curLiteral.value.real;
			}
			crunchSymTableNodePtr(thisNode);
			getToken();
			}
			break;
		case TKN_STRING: {
			long length = strlen(curLiteral.value.string);
			if (EnterStateSymbol) {
				SymTableNodePtr stateSymbol = searchSymTableForState(curLiteral.value.string, SymTableDisplay[1]);
				if (!stateSymbol)
					forwardState(curLiteral.value.string);
			}
			SymTableNodePtr thisNode = searchSymTableForString(tokenString, SymTableDisplay[1]);
			if (!thisNode)// {
				thisNode = enterSymTable(tokenString, &SymTableDisplay[1]);
				if (length == 1) {
					thisNode->defn.info.constant.value.character = curLiteral.value.string[0];
					thisType = CharTypePtr;
					}
				else {
					thisNode->typePtr = thisType = makeStringType(length);
					thisNode->info = (char*)ABLSymbolMallocCallback(length + 1);
					if (!thisNode->info)
						ABL_Fatal(0, " ABL: Unable to AblSymTableHeap->malloc string literal ");
					strcpy(thisNode->info, curLiteral.value.string);
				}
			//}
			crunchSymTableNodePtr(thisNode);

			getToken();
			}
			break;
		case TKN_NOT:
			getToken();
			thisType = factor();
			break;
		case TKN_LPAREN:
			getToken();
			thisType = expression();
			ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
			break;
		default:
			syntaxError(ABL_ERR_SYNTAX_INVALID_EXPRESSION);
			thisType = &DummyType;
			break;
	}
	return(thisType);
}
Exemple #6
0
void doConst (SymTableNodePtr constantIdPtr) {

	TokenCodeType sign = TKN_PLUS;
	bool sawSign = false;

	if ((curToken == TKN_PLUS) || (curToken == TKN_MINUS)) {
		sign = curToken;
		sawSign = true;
		getToken();
	}

	//----------------------------------
	// Numeric constant: real or integer
	if (curToken == TKN_NUMBER) {
		if (curLiteral.type == LIT_INTEGER) {
			if (sign == TKN_PLUS)
				constantIdPtr->defn.info.constant.value.integer = curLiteral.value.integer;
			else
				constantIdPtr->defn.info.constant.value.integer = -(curLiteral.value.integer);
			constantIdPtr->typePtr = setType(IntegerTypePtr);
			}
		else {
			if (sign == TKN_PLUS)
				constantIdPtr->defn.info.constant.value.real = curLiteral.value.real;
			else
				constantIdPtr->defn.info.constant.value.real = -(curLiteral.value.real);
			constantIdPtr->typePtr = setType(RealTypePtr);
		}
		}
	else if (curToken == TKN_IDENTIFIER) {
		SymTableNodePtr idPtr = NULL;
		searchAllSymTables(idPtr);

		if (!idPtr)
			syntaxError(ABL_ERR_SYNTAX_UNDEFINED_IDENTIFIER);
		else if (idPtr->defn.key != DFN_CONST)
			syntaxError(ABL_ERR_SYNTAX_NOT_A_CONSTANT_IDENTIFIER);
		else if (idPtr->typePtr == IntegerTypePtr) {
			if (sign == TKN_PLUS)
				constantIdPtr->defn.info.constant.value.integer = idPtr->defn.info.constant.value.integer;
			else
				constantIdPtr->defn.info.constant.value.integer = -(idPtr->defn.info.constant.value.integer);
			constantIdPtr->typePtr = setType(IntegerTypePtr);
			}
		else if (idPtr->typePtr == CharTypePtr) {
			if (sawSign)
				syntaxError(ABL_ERR_SYNTAX_INVALID_CONSTANT);
			constantIdPtr->defn.info.constant.value.character = idPtr->defn.info.constant.value.character;
			constantIdPtr->typePtr = setType(CharTypePtr);
			}
		else if (idPtr->typePtr == RealTypePtr) {
			if (sign == TKN_PLUS)
				constantIdPtr->defn.info.constant.value.real = idPtr->defn.info.constant.value.real;
			else
				constantIdPtr->defn.info.constant.value.real = -(idPtr->defn.info.constant.value.real);
			constantIdPtr->typePtr = setType(RealTypePtr);
			}
		else if (((Type*)(idPtr->typePtr))->form == FRM_ENUM) {
			if (sawSign)
				syntaxError(ABL_ERR_SYNTAX_INVALID_CONSTANT);
			constantIdPtr->defn.info.constant.value.integer = idPtr->defn.info.constant.value.integer;
			constantIdPtr->typePtr = setType(idPtr->typePtr);
			}
		else if (((TypePtr)(idPtr->typePtr))->form == FRM_ARRAY) {
			if (sawSign)
				syntaxError(ABL_ERR_SYNTAX_INVALID_CONSTANT);
			constantIdPtr->defn.info.constant.value.stringPtr = idPtr->defn.info.constant.value.stringPtr;
			constantIdPtr->typePtr = setType(idPtr->typePtr);
		}
		}
	else if (curToken == TKN_STRING) {
		if (sawSign)
			syntaxError(ABL_ERR_SYNTAX_INVALID_CONSTANT);
		if (strlen(curLiteral.value.string) == 1) {
			constantIdPtr->defn.info.constant.value.character = curLiteral.value.string[0];
			constantIdPtr->typePtr = setType(CharTypePtr);
			}
		else {
			long length = strlen(curLiteral.value.string);
			constantIdPtr->defn.info.constant.value.stringPtr = (char*)ABLSymbolMallocCallback(length + 1);
			if (!constantIdPtr->defn.info.constant.value.stringPtr)
				ABL_Fatal(0, " ABL: Unable to AblSymbolHeap->malloc array string constant ");
			strcpy(constantIdPtr->defn.info.constant.value.stringPtr, curLiteral.value.string);
			constantIdPtr->typePtr = makeStringType(length);
		}
		}
	else {
		constantIdPtr->typePtr = NULL;
		syntaxError(ABL_ERR_SYNTAX_INVALID_CONSTANT);
	}

	getToken();
}
Exemple #7
0
void initSymTab(void) {
  Object* param;

  symtab = (SymTab*) malloc(sizeof(SymTab));
  symtab->globalObjectList = NULL;
  symtab->program = NULL;
  symtab->currentScope = NULL;
  
  readcFunction = createFunctionObject("READC");
  declareObject(readcFunction);
  readcFunction->funcAttrs->returnType = makeCharType();

  readiFunction = createFunctionObject("READI");
  declareObject(readiFunction);
  readiFunction->funcAttrs->returnType = makeIntType();

  readfFunction = createFunctionObject("READF");
  declareObject(readfFunction);
  readfFunction->funcAttrs->returnType = makeFloatType();

  readsFunction = createFunctionObject("READS");
  declareObject(readsFunction);
  readsFunction->funcAttrs->returnType = makeStringType();

  writeiProcedure = createProcedureObject("WRITEI");
  declareObject(writeiProcedure);
  enterBlock(writeiProcedure->procAttrs->scope);
    param = createParameterObject("i", PARAM_VALUE);
    param->paramAttrs->type = makeIntType();
    declareObject(param);
  exitBlock();

  writecProcedure = createProcedureObject("WRITEC");
  declareObject(writecProcedure);
  enterBlock(writecProcedure->procAttrs->scope);
    param = createParameterObject("ch", PARAM_VALUE);
    param->paramAttrs->type = makeCharType();
    declareObject(param);
  exitBlock();

  writesProcedure = createProcedureObject("WRITES");
  declareObject(writesProcedure);
  enterBlock(writesProcedure->procAttrs->scope);
    param = createParameterObject("str", PARAM_VALUE);
    param->paramAttrs->type = makeStringType();
    declareObject(param);
  exitBlock();

  writefProcedure = createProcedureObject("WRITEF");
  declareObject(writefProcedure);
  enterBlock(writefProcedure->procAttrs->scope);
    param = createParameterObject("f", PARAM_VALUE);
    param->paramAttrs->type = makeFloatType();
    declareObject(param);
  exitBlock();

  writelnProcedure = createProcedureObject("WRITELN");
  declareObject(writelnProcedure);

  intType = makeIntType();
  charType = makeCharType();
  floatType = makeFloatType();
  stringType = makeStringType();
}