Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////
// Class				:	CRenderer
// Method				:	declareDisplayChannel
// Description			:	Define a new displayChannel
// Return Value			:	The new display channel, NULL otherwise
// Comments				:
CDisplayChannel		*CRenderer::declareDisplayChannel(const char *type) {
	CDisplayChannel *oChannel;
	CVariable		cVariable,*oVariable;
	
	assert(declaredChannels	!=	NULL);
	
	if (parseVariable(&cVariable,NULL,type) == FALSE) {
		return NULL;
	}
	
	if (declaredChannels->find(cVariable.name,oChannel) == TRUE) {
		if ((oChannel->numSamples == cVariable.numFloats) &&
			((cVariable.storage != STORAGE_GLOBAL) || oChannel->outType == cVariable.entry)) {
			return oChannel;
		} else {
			error(CODE_SYSTEM,"Channel \"%s\" was previously defined differently\n",cVariable.name);
			return NULL;
		}
	} else {
		oVariable = declareVariable(NULL,type);
		
		if (oVariable == NULL) {
			error(CODE_SYSTEM,"Channel definition \"%s\" is ill formed\n",type);
		} else {
			const int samples = oVariable->numFloats;
			const int outType = (oVariable->storage == STORAGE_GLOBAL) ? oVariable->entry : -1;
			oChannel = new CDisplayChannel(oVariable->name,oVariable,samples,-1,outType);
			declaredChannels->insert(oChannel->name,oChannel);
			displayChannels->push(oChannel);
			
			return oChannel;
		}
	}
	return NULL;
}
	string GarbledClassConstructor:: toString(int n)
	{
		string output = "";
		output += declareVariable(n);
		output += declareConstruction(n);
		return output;
	}
Exemplo n.º 3
0
  void Compiler::declareClass(DefClassExpr& classExpr, Module* module)
  {
    declareVariable(classExpr.pos(), classExpr.name(), module);

    // Native classes have no fields or synthesized members.
    if (classExpr.isNative()) return;

    // Synthesize the constructor and field accessors.
    Array<gc<DefExpr> > synthesizedMethods;
    synthesizedMethods.add(synthesizeConstructor(classExpr));

    // Create getters and setters for fields.
    for (int i = 0; i < classExpr.fields().count(); i++)
    {
      synthesizedMethods.add(synthesizeGetter(classExpr, i));
      if (classExpr.fields()[i]->isMutable())
      {
        synthesizedMethods.add(synthesizeSetter(classExpr, i));
      }
    }

    // TODO(bob): Stuffing this back in the AST is a bit gross. An intermediate
    // representation would help here.
    classExpr.setSynthesizedMethods(synthesizedMethods);

    // Declare the automatically-generated methods.
    for (int i = 0; i < synthesizedMethods.count(); i++)
    {
      declareMultimethod(SignatureBuilder::build(*synthesizedMethods[i]));
    }
  }
Exemplo n.º 4
0
 bool findPassedParam(const string_type& name)
 {
   typename ScopeStack::reverse_iterator p = params_.rbegin()+1;    
   typename Scope::iterator i = p->find(name);
   if(i == p->end())
     return false;
   declareVariable(i->second);
   return true;
 } // findPassedParam
void FunctionStatement::init(void *parser, bool ref,
                             const vector<ParameterPtr> &params,
                             StatementListStatementPtr body,
                             bool has_call_to_get_args) {
  m_ref = ref;
  m_params = params;
  m_body = body;
  m_hasCallToGetArgs = has_call_to_get_args;
  const CallInfo* cit1;
  void* vt1;
  if (get_call_info_no_eval(cit1, vt1, m_name)) {
    m_invalid =
      get_call_info_builtin(cit1, vt1, m_name->data(), m_name->hash()) ? -1 : 1;
  }

  bool seenOptional = false;
  set<string> names;
  m_callInfo.m_argCount = m_closureCallInfo.m_argCount = m_params.size();
  for (unsigned int i = 0; i < m_params.size(); i++) {
    ParameterPtr param = m_params[i];

    std::string name = param->name();
    if (names.find(name) != names.end()) {
      raise_notice("%s:%d %s() has 2 parameters with the same name: $%s",
                   m_loc.file, m_loc.line0, m_name.c_str(), name.c_str());
    } else {
      names.insert(name);
    }

    if (!seenOptional) {
      if (param->isOptional()) {
        seenOptional = true;
      }
    } else if (!param->isOptional()) {
/*
      raise_notice("%s:%d %s() has required parameter after optional one: $%s",
                   m_loc.file, m_loc.line0, m_name.c_str(), name.c_str());
*/
      param->addNullDefault(parser);
    }
    if (param->isRef()) {
      m_callInfo.m_refFlags        |= 1 << i;
      m_closureCallInfo.m_refFlags |= 1 << i;
    }

    if (param->getIdx() == -1) {
      param->setIdx(declareVariable(name));
    }
  }
}
Exemplo n.º 6
0
  void Compiler::declareVariables(gc<Pattern> pattern, Module* module)
  {
    RecordPattern* record = pattern->asRecordPattern();
    if (record != NULL)
    {
      for (int i = 0; i < record->fields().count(); i++)
      {
        declareVariables(record->fields()[i].value, module);
      }

      return;
    }

    VariablePattern* variable = pattern->asVariablePattern();
    if (variable != NULL)
    {
      declareVariable(variable->pos(), variable->name(), module);

      if (!variable->pattern().isNull())
      {
        declareVariables(variable->pattern(), module);
      }
    }
  }
Exemplo n.º 7
0
///////////////////////////////////////////////////////////////////////
// Class				:	CRenderer
// Method				:	initDeclarations
// Description			:	Init the declarations
// Return Value			:
// Comments				:
void			CRenderer::initDeclarations() {


	////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//			A L L O C A T E    M E M O R Y
	//
	//
	////////////////////////////////////////////////////////////////////////////////////////////
	// Init the coordinate systems
	definedCoordinateSystems			=	new CTrie<CNamedCoordinateSystem *>;

	// Init the declared variables
	declaredVariables					=	new CTrie<CVariable *>;
	// Allocate the global variables array
	globalVariables						=	new CArray<CVariable *>;
	// This is the list of all variables
	variables							=	NULL;

	// Allocate the space for default display channels
	declaredChannels					=	new CTrie<CDisplayChannel*>;
	displayChannels						=	new	CArray<CDisplayChannel*>;

	// Zero is reserved as an invalid value
	numKnownGlobalIds					=	1;
	// Global Ids
	globalIdHash						=	new CTrie<CGlobalIdentifier *>;


	////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//			R E G I S T E R    O P T I O N S / A T T R I B U T E S
	//
	//
	////////////////////////////////////////////////////////////////////////////////////////////
	// Define the options
	declareVariable(RI_ARCHIVE,				"string");
	declareVariable(RI_PROCEDURAL,			"string");
	declareVariable(RI_TEXTURE,				"string");
	declareVariable(RI_SHADER,				"string");
	declareVariable(RI_DISPLAY,				"string");
	declareVariable(RI_RESOURCE,			"string");

	declareVariable(RI_BUCKETSIZE,			"int[2]");
	declareVariable(RI_METABUCKETS,			"int[2]");
	declareVariable(RI_INHERITATTRIBUTES,	"int");
	declareVariable(RI_GRIDSIZE,			"int");
	declareVariable(RI_EYESPLITS,			"int");
	declareVariable(RI_TEXTUREMEMORY,		"int");
	declareVariable(RI_BRICKMEMORY,			"int");
	declareVariable(RI_NUMTHREADS,			"int");
	declareVariable(RI_THREADSTRIDE,		"int");
	declareVariable(RI_GEOCACHEMEMORY,		"int");
	declareVariable(RI_OTHRESHOLD,			"color");
	declareVariable(RI_ZTHRESHOLD,			"color");

	declareVariable(RI_RADIANCECACHE,		"int");
	declareVariable(RI_JITTER,				"float");
	declareVariable(RI_FALSECOLOR,			"int");
	declareVariable(RI_EMIT,				"int");
	declareVariable(RI_SAMPLESPECTRUM,		"int");
	declareVariable(RI_DEPTHFILTER,			"string");

	declareVariable(RI_MAXDEPTH,			"int");

	declareVariable(RI_ENDOFFRAME,			"int");
	declareVariable(RI_FILELOG,				"string");
	declareVariable(RI_PROGRESS,			"int");

	// File display variables
	
	declareVariable("quantize",				"float[4]");
	declareVariable("dither",				"float");
	declareVariable("gamma",				"float");
	declareVariable("gain",					"float");
	declareVariable("near",					"float");
	declareVariable("far",					"float");
	declareVariable("Software",				"string");
	declareVariable("compression",			"string");
	declareVariable("NP",					"float[16]");
	declareVariable("Nl",					"float[16]");

	// Define the attributes
	declareVariable(RI_NUMPROBES,			"int[2]");
	declareVariable(RI_MINSUBDIVISION,		"int");
	declareVariable(RI_MAXSUBDIVISION,		"int");
	declareVariable(RI_MINSPLITS,			"int");
	declareVariable(RI_BOUNDEXPAND,			"float");
	declareVariable(RI_BINARY,				"int");
	declareVariable(RI_RASTERORIENT,		"int");

	declareVariable(RI_SPHERE,				"float");
	declareVariable(RI_COORDINATESYSYTEM,	"string");

	declareVariable(RI_DISPLACEMENTS,		"int");
	declareVariable(RI_BIAS,				"float");
	declareVariable(RI_MAXDIFFUSEDEPTH,		"int");
	declareVariable(RI_MAXSPECULARDEPTH,	"int");
	declareVariable(RI_SAMPLEMOTION,		"int");

	declareVariable(RI_HANDLE,				"string");
	declareVariable(RI_FILEMODE,			"string");
	declareVariable(RI_MAXERROR,			"float");
	declareVariable(RI_MAXPIXELDIST,		"float");

	declareVariable(RI_GLOBALMAP,			"string");
	declareVariable(RI_CAUSTICMAP,			"string");
	declareVariable(RI_SHADINGMODEL,		"string");
	declareVariable(RI_ESTIMATOR,			"int");
	declareVariable(RI_ILLUMINATEFRONT,		"int");

	declareVariable(RI_TRANSMISSION,		"int");
	declareVariable(RI_CAMERA,				"int");
	declareVariable(RI_SPECULAR,			"int");
	declareVariable(RI_DIFFUSE,				"int");
	declareVariable(RI_PHOTON,				"int");

	declareVariable(RI_DIFFUSEHITMODE,		"string");
	declareVariable(RI_SPECULARHITMODE,		"string");
	declareVariable(RI_TRANSMISSIONHITMODE,	"string");
	declareVariable(RI_CAMERAHITMODE,		"string");

	declareVariable(RI_NAME,				"string");

	declareVariable(RI_HIDDEN,				"int");
	declareVariable(RI_BACKFACING,			"int");

	////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//			R E G I S T E R    D E F A U L T    V A R I A B L E S
	//
	//
	////////////////////////////////////////////////////////////////////////////////////////////
	CVariable		*tmp;
	tmp	=	declareVariable("P",	"global vertex point",PARAMETER_P);			assert(tmp->entry	==	VARIABLE_P);
	tmp	=	declareVariable("Ps",	"global vertex point",PARAMETER_PS);		assert(tmp->entry	==	VARIABLE_PS);
	tmp	=	declareVariable("N",	"global varying normal",PARAMETER_N);		assert(tmp->entry	==	VARIABLE_N);
	tmp	=	declareVariable("Ng",	"global varying normal",PARAMETER_NG);		assert(tmp->entry	==	VARIABLE_NG);
	tmp	=	declareVariable("dPdu",	"global vertex vector",PARAMETER_DPDU);		assert(tmp->entry	==	VARIABLE_DPDU);
	tmp	=	declareVariable("dPdv",	"global vertex vector",PARAMETER_DPDV);		assert(tmp->entry	==	VARIABLE_DPDV);
	tmp	=	declareVariable("L",	"global varying vector",PARAMETER_L);		assert(tmp->entry	==	VARIABLE_L);
	tmp	=	declareVariable("Cs",	"global varying color",PARAMETER_CS);		assert(tmp->entry	==	VARIABLE_CS);
	tmp	=	declareVariable("Os",	"global varying color",PARAMETER_OS);		assert(tmp->entry	==	VARIABLE_OS);
	tmp	=	declareVariable("Cl",	"global varying color",PARAMETER_CL);		assert(tmp->entry	==	VARIABLE_CL);
	tmp	=	declareVariable("Ol",	"global varying color",PARAMETER_OL);		assert(tmp->entry	==	VARIABLE_OL);
	tmp	=	declareVariable("Ci",	"global varying color",PARAMETER_CI);		assert(tmp->entry	==	VARIABLE_CI);
	tmp	=	declareVariable("Oi",	"global varying color",PARAMETER_OI);		assert(tmp->entry	==	VARIABLE_OI);
	tmp	=	declareVariable("s",	"global varying float",PARAMETER_S);		assert(tmp->entry	==	VARIABLE_S);
	tmp	=	declareVariable("t",	"global varying float",PARAMETER_T);		assert(tmp->entry	==	VARIABLE_T);
	tmp	=	declareVariable("st",	"varying float[2]",PARAMETER_S | PARAMETER_T);
	tmp	=	declareVariable("du",	"global varying float",PARAMETER_DU | PARAMETER_DERIVATIVE);	assert(tmp->entry	==	VARIABLE_DU);
	tmp	=	declareVariable("dv",	"global varying float",PARAMETER_DV | PARAMETER_DERIVATIVE);	assert(tmp->entry	==	VARIABLE_DV);
	tmp	=	declareVariable("u",	"global varying float",PARAMETER_U);		assert(tmp->entry	==	VARIABLE_U);
	tmp	=	declareVariable("v",	"global varying float",PARAMETER_V);		assert(tmp->entry	==	VARIABLE_V);
	tmp	=	declareVariable("I",	"global varying vector",PARAMETER_I);		assert(tmp->entry	==	VARIABLE_I);
	tmp	=	declareVariable("E",	"global varying point",PARAMETER_E);		assert(tmp->entry	==	VARIABLE_E);
	tmp	=	declareVariable("alpha","global varying float",PARAMETER_ALPHA);	assert(tmp->entry	==	VARIABLE_ALPHA);
	tmp	=	declareVariable("time",	"global varying float",PARAMETER_TIME);		assert(tmp->entry	==	VARIABLE_TIME);
	tmp	=	declareVariable("Pw",	"global vertex htpoint",PARAMETER_P);		tmp->entry			=	VARIABLE_PW;
	tmp	=	declareVariable("Pz",	"vertex float",PARAMETER_P);				tmp->entry			=	VARIABLE_P;
	tmp	=	declareVariable("ncomps","global uniform float",PARAMETER_NCOMPS);	assert(tmp->entry	==	VARIABLE_NCOMPS);
	tmp	=	declareVariable("dtime","global uniform float",PARAMETER_DTIME);	assert(tmp->entry	==	VARIABLE_DTIME);
	tmp	=	declareVariable("dPdtime","global varying vector",PARAMETER_DPDTIME);assert(tmp->entry	==	VARIABLE_DPDTIME);

	tmp	=	declareVariable("width","global varying float",0);					assert(tmp->entry	==	VARIABLE_WIDTH);
	tmp	=	declareVariable("constantwidth","global constant float",0);			assert(tmp->entry	==	VARIABLE_CONSTANTWIDTH);
	tmp	=	declareVariable("Np","uniform normal",PARAMETER_NG);


	////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//			R E G I S T E R    D E F A U L T   D I S P L A Y    C H A N N E L S
	//
	//
	////////////////////////////////////////////////////////////////////////////////////////////
	CDisplayChannel	*tmp2;

	tmp2 = new CDisplayChannel("rgb",NULL,3,0);
	displayChannels->push(tmp2);
	declaredChannels->insert(tmp2->name,tmp2);
	
	tmp2 = new CDisplayChannel("rgba",NULL,4,0);
	displayChannels->push(tmp2);
	declaredChannels->insert(tmp2->name,tmp2);
	
	tmp2 = new CDisplayChannel("a",NULL,1,3);
	displayChannels->push(tmp2);
	declaredChannels->insert(tmp2->name,tmp2);
	
	tmp2 = new CDisplayChannel("z",NULL,1,4);
	displayChannels->push(tmp2);
	declaredChannels->insert(tmp2->name,tmp2);
	
	tmp2 = new CDisplayChannel("rgbaz",NULL,5,0);
	displayChannels->push(tmp2);
	declaredChannels->insert(tmp2->name,tmp2);
	

	////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//			R E G I S T E R    D E F A U L T   C O O R D I N A T E    S Y S T E M S
	//
	//
	////////////////////////////////////////////////////////////////////////////////////////////


	defineCoordinateSystem(coordinateCameraSystem,identityMatrix,identityMatrix,COORDINATE_CAMERA);
	defineCoordinateSystem(coordinateWorldSystem,identityMatrix,identityMatrix,COORDINATE_WORLD);
	defineCoordinateSystem(coordinateObjectSystem,identityMatrix,identityMatrix,COORDINATE_OBJECT);
	defineCoordinateSystem(coordinateShaderSystem,identityMatrix,identityMatrix,COORDINATE_SHADER);
	defineCoordinateSystem(coordinateLightSystem,identityMatrix,identityMatrix,COORDINATE_LIGHT);
	defineCoordinateSystem(coordinateNDCSystem,identityMatrix,identityMatrix,COORDINATE_NDC);
	defineCoordinateSystem(coordinateRasterSystem,identityMatrix,identityMatrix,COORDINATE_RASTER);
	defineCoordinateSystem(coordinateScreenSystem,identityMatrix,identityMatrix,COORDINATE_SCREEN);
	defineCoordinateSystem(coordinateCurrentSystem,identityMatrix,identityMatrix,COORDINATE_CURRENT);

	// Define the default color systems
	defineCoordinateSystem(colorRgbSystem,identityMatrix,identityMatrix,COLOR_RGB);
	defineCoordinateSystem(colorHslSystem,identityMatrix,identityMatrix,COLOR_HSL);
	defineCoordinateSystem(colorHsvSystem,identityMatrix,identityMatrix,COLOR_HSV);
	defineCoordinateSystem(colorXyzSystem,identityMatrix,identityMatrix,COLOR_XYZ);
	defineCoordinateSystem(colorCieSystem,identityMatrix,identityMatrix,COLOR_CIE);
	defineCoordinateSystem(colorYiqSystem,identityMatrix,identityMatrix,COLOR_YIQ);
	defineCoordinateSystem(colorXyySystem,identityMatrix,identityMatrix,COLOR_XYY);
}
Exemplo n.º 8
0
 void declareParam(Variable_instance_ptr param)
 {
   declareVariable(param);
 } // declareParam
Exemplo n.º 9
0
int main(){

	freopen("lexer_output.txt", "r", stdin);
	trieRoot = createNewTrieNode();
	if(trieRoot == NULL){
		perror("Could not create root node!!\n");
		return 0;
	}

	envTop = NULL;
	currentScope = totalVariables = 0;
	addScope();


	token t;
	while(scanf("%d%d", &t.iden, &t.line) != EOF){

		fgets(t.value, 1000, stdin);

		int len = strlen(t.value);
		t.value[len-1] = '\0';
		if(t.value[0] == '-')	t.value[0] = '\0';
		t.line++;

		lexemeStream[stream_size++] = t;
	}

	// int zz;
	// for(zz=0;zz<stream_size;zz++)
	// 	printf("%d ", lexemeStream[zz].iden);	printf("\n");


	int i, n = stream_size, lastLineOfDeclaration = -1, lastDataTypeOfDeclaration = -1;
	int lastDataTypeOfAssignment = -1, lastLineOfAssignment = -1;
	funcName[0] = '!';	funcName[1] = '\0';
	int insideMain = 0, diff = 0;
	funcParameterCount = 0;

	for(i=0;i<n;i++){

		if(lexemeStream[i].iden == MAIN)	insideMain = 1;
		if(i == 2){

			if(lexemeStream[i].iden != MAIN){

				assert(lexemeStream[i].iden == FUNC);
				strcpy(funcName, lexemeStream[i+1].value);
			}
			i++;
			continue;
		}

		//check for recursive function calls
		if(lexemeStream[i].iden == FUNC && !insideMain){

			printf("Semantic error: Recursive function calls not allowed.\n");
			continue;
		}

		if(lexemeStream[i].iden == LSQ){
			diff++;
			continue;
		}

		if(lexemeStream[i].iden == RSQ){
			diff--;
			continue;
		}


		//store function parameter list
		if(isDataType(lexemeStream[i].iden) && diff > 0 && !insideMain){

			funcParameterType[funcParameterCount++] = lexemeStream[i].iden;
		}

		//for function calls inside main, check whether correct function name is used
		//then check for correct number and types of parameters
		if(insideMain && i > 0 && lexemeStream[i].iden == IDEN && lexemeStream[i-1].iden == FUNC){

			if(strcmp(funcName, lexemeStream[i].value) > 0)
				printf("Function named %s in line %d not declared.\n", lexemeStream[i].value, lexemeStream[i].line);

			int j, argumentCount = 0, wrongType = 0;
			for(j=i+1;j < stream_size && lexemeStream[j].iden != RSQ;j++){

				if(lexemeStream[j].iden != IDEN)	continue;

				if(argumentCount < funcParameterCount && getDataType(lexemeStream[j]) != funcParameterType[argumentCount])
					wrongType = lexemeStream[j].line;
				argumentCount++;
			}

			if(argumentCount != funcParameterCount)	printf("Incorrect number of function arguments in line %d.\n", lexemeStream[j].line);
			if(wrongType > 0)	printf("Type mismatch in function parameters in line %d.\n", wrongType);

			i = j;
			continue;
		}

		if(lexemeStream[i].iden == LAD){
			addScope();
			continue;
		}

		if(lexemeStream[i].iden == RAD){
			deleteScope();
			continue;
		}

		if(isDataType(lexemeStream[i].iden)){

			lastLineOfDeclaration = lexemeStream[i].line;
			lastDataTypeOfDeclaration = lexemeStream[i].iden;

// printf("setting lastlineOfDeclaration = %d because of %d.\n", lastLineOfDeclaration, lexemeStream[i].iden);
			continue;
		}


		if(lexemeStream[i].iden == ASSIGN){

			//line number of assignment operator
			lastLineOfAssignment = lexemeStream[i].line;
			continue;
		}


		if(lexemeStream[i].iden == IDEN){

			insert(lexemeStream[i].value);

			//check if variable is being declared or referenced
			if(lastLineOfDeclaration == lexemeStream[i].line){

				//declared
				declareVariable(lexemeStream[i], lastDataTypeOfDeclaration);
				continue;
			}

			//referenced
			referenceVariable(lexemeStream[i]);

			if(lexemeStream[i].line != lastLineOfAssignment){

				lastDataTypeOfAssignment = getDataType(lexemeStream[i]);
				continue;
			}


			if(lexemeStream[i].line == lastLineOfAssignment){

				int dataType = getDataType(lexemeStream[i]);
				if(dataType != lastDataTypeOfAssignment){

					printf("Semantic error in line %d: Type mismatch between LHS and RHS in line %d.\n", lexemeStream[i].line, lastLineOfAssignment);
				}
				continue;
			}
		}
	}

// int c = 0, cc = 0;
// EnvStackNode temp = envTop;
// while(temp != NULL){
	
// 	c++;
// 	EnvListNode ev = temp->ev;
// 	while(ev != NULL){
// 		cc++;
// 		ev = ev->next;
// 	}

// 	temp = temp->next;
// }
// printf("Total active scopes : %d and active variables = %d.\n", c, cc);
// printf("\ncheck variable stack of size = %d :\n", z);
// for(int i=0;i<z;i++){

// 	int idx = vvv[i];
// 	if(variableStack[idx] == NULL){
// 		printf("empty stack at idx = %d\n", idx);
// 		continue;
// 	}
// 	printf("idx = %d has the value = %s\n", idx, variableStack[idx]->node.name);
// }

	return 0;
}