Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Global Variable Redeclaration


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Jason Goepel   Members   -  Reputation: 429

Like
0Likes
Like

Posted 12 May 2014 - 01:28 PM

The compiler doesn't seem to prevent declaring two global properties with the same name.  Is this by design or a bug?



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3417

Like
0Likes
Like

Posted 12 May 2014 - 02:25 PM

Sounds like a bug. It shouldn't be allowed to exist multiple properties/variables of the same name in the same namespace. The variable name must also not conflict with a type name or the name of any function.

 

With global properties you mean application registered global properties? Or global variables declared from the script?

 

Can you give more detail on the exact scenario (to reduce my time in reproducing the problem)?


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Jason Goepel   Members   -  Reputation: 429

Like
1Likes
Like

Posted 12 May 2014 - 02:50 PM

I'm sorry, I mean global variables declared from the script.  I find that in any script two global variable declarations compile with no errors.

double x;
double x;
void test() {

}

It doesn't look like there is any test for duplicate names in asCCompiler::CompileGlobalVariable.

 

as_compiler.cpp(1196):

asSExprContext compiledCtx(engine);
bool preCompiled = false;
if( gvar->datatype.IsAuto() )
	preCompiled = CompileAutoType(gvar->datatype, compiledCtx, node, gvar->declaredAtNode);
if( gvar->property == 0 )
{
	gvar->property = builder->module->AllocateGlobalProperty(gvar->name.AddressOf(), gvar->datatype, gvar->ns);
	gvar->index = gvar->property->id;
}

as_module.cpp(1175):

asCGlobalProperty *asCModule::AllocateGlobalProperty(const char *name, const asCDataType &dt, asSNameSpace *ns)
{
	asCGlobalProperty *prop = engine->AllocateGlobalProperty();
	prop->name = name;
	prop->nameSpace = ns;

	// Allocate the memory for this property based on its type
	prop->type = dt;
	prop->AllocateMemory();

	// Make an entry in the address to variable map
	engine->varAddressMap.Insert(prop->GetAddressOfValue(), prop);

	// Store the variable in the module scope (the reference count is already set to 1)
	scriptGlobals.Put(prop);

	return prop;
}

Edited by Jason Goepel, 12 May 2014 - 02:54 PM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3417

Like
0Likes
Like

Posted 13 May 2014 - 03:07 PM

Thanks for the details.

 

The builder should definitely guarantee that no two global variables in the same namespace can have the same name. It should be done by CheckNameConflict, called by asCBuilder::RegisterGlobalVar, but I guess something has been broken recently.

 

I'll investigate further and have this fixed a.s.a.p.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Andreas Jonsson   Moderators   -  Reputation: 3417

Like
0Likes
Like

Posted 14 May 2014 - 06:55 PM

I've fixed this in revision 1921.

 

The check for name conflict had been broken by the implementation of 'auto' types in the WIP version. For some odd reason my regression test suite didn't have a test case for this basic scenario so it wasn't detected before. But now it has so it shouldn't be broken by mistake again in the future. :)

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS