Refactor some stuff in LSL preprocessor

Tue, 06 Jan 2015 20:11:15 +0100

author
Ansariel
date
Tue, 06 Jan 2015 20:11:15 +0100
changeset 43105
bf8b86ab1f11
parent 43104
ff8e62707177
child 43106
f3934808b579

Refactor some stuff in LSL preprocessor

indra/newview/fslslpreproc.cpp file | annotate | diff | revisions
     1.1 --- a/indra/newview/fslslpreproc.cpp	Thu Mar 06 05:51:49 2014 +0200
     1.2 +++ b/indra/newview/fslslpreproc.cpp	Tue Jan 06 20:11:15 2015 +0100
     1.3 @@ -137,7 +137,6 @@
     1.4  
     1.5  std::string FSLSLPreprocessor::encode(std::string script)
     1.6  {
     1.7 -	
     1.8  	std::string otext = FSLSLPreprocessor::decode(script);
     1.9  	
    1.10  	BOOL mono = mono_directive(script);
    1.11 @@ -157,19 +156,17 @@
    1.12  	
    1.13  	if(mono)otext += "//mono\n";
    1.14  	else otext += "//lsl2\n";
    1.15 -	
    1.16  
    1.17  	return otext;
    1.18  }
    1.19  
    1.20  std::string FSLSLPreprocessor::decode(std::string script)
    1.21  {
    1.22 -	
    1.23  	static S32 startpoint = encode_start.length();
    1.24  	
    1.25  	std::string tip = script.substr(0,startpoint);
    1.26  	
    1.27 -	if(tip != encode_start)
    1.28 +	if (tip != encode_start)
    1.29  	{
    1.30  		LL_DEBUGS() << "No start" << LL_ENDL;
    1.31  		//if(sp != -1)trigger warningg/error?
    1.32 @@ -178,24 +175,19 @@
    1.33  	
    1.34  	S32 end = script.find(encode_end);
    1.35  	
    1.36 -	if(end == -1)
    1.37 +	if (end == -1)
    1.38  	{
    1.39  		LL_DEBUGS() << "No end" << LL_ENDL;
    1.40  		return script;
    1.41  	}
    1.42 -	
    1.43  
    1.44  	std::string data = script.substr(startpoint,end-startpoint);
    1.45  	LL_DEBUGS() << "data = " << data << LL_ENDL;
    1.46 -	
    1.47  
    1.48  	std::string otext = data;
    1.49  
    1.50 -	
    1.51 -
    1.52  	otext = boost::regex_replace(otext, boost::regex("([/*])\\|",boost::regex::perl), "$1");
    1.53  
    1.54 -	
    1.55  	//otext = curl_unescape(otext.c_str(),otext.length());
    1.56  
    1.57  	return otext;
    1.58 @@ -204,30 +196,36 @@
    1.59  
    1.60  std::string scopeript2(std::string& top, S32 fstart, char left = '{', char right = '}')
    1.61  {
    1.62 -	
    1.63 -	if(fstart >= int(top.length()))
    1.64 +	if (fstart >= S32(top.length()))
    1.65  	{
    1.66  		return "begin out of bounds";
    1.67  	}
    1.68  	
    1.69 -	int cursor = fstart;
    1.70 +	S32 cursor = fstart;
    1.71  	bool noscoped = true;
    1.72  	bool in_literal = false;
    1.73 -	int count = 0;
    1.74 +	S32 count = 0;
    1.75  	char ltoken = ' ';
    1.76  	
    1.77  	do
    1.78  	{
    1.79  		char token = top.at(cursor);
    1.80 -		if(token == '"' && ltoken != '\\')in_literal = !in_literal;
    1.81 -		else if(token == '\\' && ltoken == '\\')token = ' ';
    1.82 -		else if(!in_literal)
    1.83 +		if (token == '"' && ltoken != '\\')
    1.84  		{
    1.85 -			if(token == left)
    1.86 +			in_literal = !in_literal;
    1.87 +		}
    1.88 +		else if (token == '\\' && ltoken == '\\')
    1.89 +		{
    1.90 +			token = ' ';
    1.91 +		}
    1.92 +		else if (!in_literal)
    1.93 +		{
    1.94 +			if (token == left)
    1.95  			{
    1.96  				count += 1;
    1.97  				noscoped = false;
    1.98 -			}else if(token == right)
    1.99 +			}
   1.100 +			else if (token == right)
   1.101  			{
   1.102  				count -= 1;
   1.103  				noscoped = false;
   1.104 @@ -235,9 +233,11 @@
   1.105  		}
   1.106  		ltoken = token;
   1.107  		cursor += 1;
   1.108 -	}while((count > 0 || noscoped) && cursor < int(top.length()));
   1.109 -	int end = (cursor-fstart);
   1.110 -	if(end > int(top.length()))
   1.111 +	}
   1.112 +	while ((count > 0 || noscoped) && cursor < S32(top.length()));
   1.113 +
   1.114 +	S32 end = (cursor-fstart);
   1.115 +	if (end > S32(top.length()))
   1.116  	{
   1.117  		return "end out of bounds";
   1.118  	}
   1.119 @@ -245,19 +245,20 @@
   1.120  	return top.substr(fstart,(cursor-fstart));
   1.121  }
   1.122  
   1.123 -inline int const_iterator_to_pos(std::string::const_iterator begin, std::string::const_iterator cursor)
   1.124 +inline S32 const_iterator_to_pos(std::string::const_iterator begin, std::string::const_iterator cursor)
   1.125  {
   1.126  	return std::distance(begin, cursor);
   1.127  }
   1.128  
   1.129  void shredder(std::string& text)
   1.130  {
   1.131 -	int cursor = 0;
   1.132 -	if(int(text.length()) == 0)
   1.133 +	S32 cursor = 0;
   1.134 +	if (text.length() == 0)
   1.135  	{
   1.136 -		text = "y u do dis?";
   1.137 +		text = "No text to shredder.";
   1.138  		return;
   1.139  	}
   1.140 +
   1.141  	char ltoken = ' ';
   1.142  	do
   1.143  	{
   1.144 @@ -266,7 +267,7 @@
   1.145  		{
   1.146  			ltoken = token;
   1.147  			token = text[++cursor];
   1.148 -			while(cursor < int(text.length()))
   1.149 +			while(cursor < S32(text.length()))
   1.150  			{
   1.151  				if(token == '\\' && ltoken == '\\') token = ' ';
   1.152  				if(token == '"' && ltoken != '\\')
   1.153 @@ -294,13 +295,14 @@
   1.154  		}
   1.155  		ltoken = token;
   1.156  		++cursor;
   1.157 -	}while(cursor < int(text.length()));
   1.158 +	}
   1.159 +	while (cursor < S32(text.length()));
   1.160  }
   1.161  
   1.162  std::string FSLSLPreprocessor::lslopt(std::string script)
   1.163  {
   1.164  	
   1.165 -	script = " \n"+script;//HACK//this should prevent regex fail for functions starting on line 0, column 0
   1.166 +	script = " \n" + script;//HACK//this should prevent regex fail for functions starting on line 0, column 0
   1.167  	//added more to prevent split fail on scripts with no global data
   1.168  	//this should be fun
   1.169  
   1.170 @@ -327,13 +329,13 @@
   1.171  			std::set<std::string> kept_functions;
   1.172  			std::map<std::string, std::string> functions;
   1.173  			
   1.174 -			while(boost::regex_search(std::string::const_iterator(top.begin()), std::string::const_iterator(top.end()), TOPfmatch, findfuncts, boost::match_default))
   1.175 +			while (boost::regex_search(std::string::const_iterator(top.begin()), std::string::const_iterator(top.end()), TOPfmatch, findfuncts, boost::match_default))
   1.176  			{
   1.177  				
   1.178  				//std::string type = TOPfmatch[1];
   1.179  				std::string funcname = TOPfmatch[2];
   1.180  
   1.181 -				int pos = TOPfmatch.position(boost::match_results<std::string::const_iterator>::size_type(0));
   1.182 +				S32 pos = TOPfmatch.position(boost::match_results<std::string::const_iterator>::size_type(0));
   1.183  				std::string funcb = scopeript2(top, pos);
   1.184  				functions[funcname] = funcb;
   1.185  				LL_DEBUGS() << "func " << funcname << " added to list[" << funcb << "]" << LL_ENDL;
   1.186 @@ -346,12 +348,12 @@
   1.187  				
   1.188  				repass = false;
   1.189  				std::map<std::string, std::string>::iterator func_it;
   1.190 -				for(func_it = functions.begin(); func_it != functions.end(); func_it++)
   1.191 +				for (func_it = functions.begin(); func_it != functions.end(); func_it++)
   1.192  				{
   1.193  					
   1.194  					std::string funcname = func_it->first;
   1.195  					
   1.196 -					if(kept_functions.find(funcname) == kept_functions.end())
   1.197 +					if (kept_functions.find(funcname) == kept_functions.end())
   1.198  					{
   1.199  						
   1.200  						boost::smatch calls;
   1.201 @@ -361,7 +363,7 @@
   1.202  						std::string::const_iterator bstart = bottom.begin();
   1.203  						std::string::const_iterator bend = bottom.end();
   1.204  
   1.205 -						if(boost::regex_search(bstart, bend, calls, findcalls, boost::match_default))
   1.206 +						if (boost::regex_search(bstart, bend, calls, findcalls, boost::match_default))
   1.207  						{
   1.208  							
   1.209  							std::string function = func_it->second;
   1.210 @@ -371,7 +373,8 @@
   1.211  						}
   1.212  					}
   1.213  				}
   1.214 -			}while(repass);
   1.215 +			}
   1.216 +			while (repass);
   1.217  
   1.218  			std::map<std::string, std::string> gvars;
   1.219  			boost::regex findvars("(integer|float|string|key|vector|rotation|list)\\s+([a-zA-Z0-9_]+)([^\\(\\);]*;)");
   1.220 @@ -384,12 +387,12 @@
   1.221  				std::string fullref = TOPvmatch[1] + " " + varname+TOPvmatch[3];
   1.222  
   1.223  				gvars[varname] = fullref;
   1.224 -				int start = const_iterator_to_pos(std::string::const_iterator(top.begin()), TOPvmatch[1].first);
   1.225 +				S32 start = const_iterator_to_pos(std::string::const_iterator(top.begin()), TOPvmatch[1].first);
   1.226  				top.erase(start,fullref.length());
   1.227  			}
   1.228  			
   1.229  			std::map<std::string, std::string>::iterator var_it;
   1.230 -			for(var_it = gvars.begin(); var_it != gvars.end(); var_it++)
   1.231 +			for (var_it = gvars.begin(); var_it != gvars.end(); var_it++)
   1.232  			{
   1.233  				
   1.234  				std::string varname = var_it->first;
   1.235 @@ -398,7 +401,7 @@
   1.236  				std::string::const_iterator bstart = bottom.begin();
   1.237  				std::string::const_iterator bend = bottom.end();
   1.238  				
   1.239 -				if(boost::regex_search(bstart, bend, vcalls, findvcalls, boost::match_default))
   1.240 +				if (boost::regex_search(bstart, bend, vcalls, findvcalls, boost::match_default))
   1.241  				{
   1.242  					bottom = var_it->second + "\n" + bottom;
   1.243  				}
   1.244 @@ -457,17 +460,16 @@
   1.245  class trace_include_files : public boost::wave::context_policies::default_preprocessing_hooks
   1.246  {
   1.247  public:
   1.248 -	trace_include_files(FSLSLPreprocessor* proc) 
   1.249 -    :   mProc(proc) 
   1.250 -    {
   1.251 +	trace_include_files(FSLSLPreprocessor* proc)
   1.252 +	:   mProc(proc) 
   1.253 +	{
   1.254  		mAssetStack.push(LLUUID::null.asString());
   1.255  		mFileStack.push(proc->mMainScriptName);
   1.256  	}
   1.257  
   1.258  
   1.259  	template <typename ContextT>
   1.260 -    bool found_include_directive(ContextT const& ctx, 
   1.261 -        std::string const &filename, bool include_next)
   1.262 +	bool found_include_directive(ContextT const& ctx, std::string const &filename, bool include_next)
   1.263  	{
   1.264  		std::string cfilename = filename.substr(1,filename.length()-2);
   1.265  		LL_DEBUGS() << cfilename << ":found_include_directive" << LL_ENDL;
   1.266 @@ -512,13 +514,14 @@
   1.267  					}
   1.268  				}
   1.269  			}
   1.270 -        }else
   1.271 +		}
   1.272 +		else
   1.273  		{
   1.274  			//todo check on HDD in user defined dir for file in question
   1.275  		}
   1.276 -        //++include_depth;
   1.277 +		//++include_depth;
   1.278  		return false;
   1.279 -    }
   1.280 +	}
   1.281  
   1.282  	template <typename ContextT>
   1.283  	void opened_include_file(ContextT const& ctx, 
   1.284 @@ -530,10 +533,14 @@
   1.285  		std::string id;
   1.286  		std::string filename = shortfile(relname);//boost::filesystem::path(std::string(relname)).filename();
   1.287  		std::map<std::string,LLUUID>::iterator it = mProc->cached_assetids.find(filename);
   1.288 -		if(it != mProc->cached_assetids.end())
   1.289 +		if (it != mProc->cached_assetids.end())
   1.290  		{
   1.291  			id = mProc->cached_assetids[filename].asString();
   1.292 -		}else id = "NOT_IN_WORLD";//I guess, still need to add external includes atm
   1.293 +		}
   1.294 +		else
   1.295 +		{
   1.296 +			id = "NOT_IN_WORLD";//I guess, still need to add external includes atm
   1.297 +		}
   1.298  		mAssetStack.push(id);
   1.299  		std::string macro = "__ASSETID__";
   1.300  		usefulctx.remove_macro_definition(macro, true);
   1.301 @@ -575,12 +582,14 @@
   1.302  	{
   1.303  		std::string err;
   1.304  		err = "warning: last line of file ends without a newline";
   1.305 -		if( !err.compare( e.description())){
   1.306 +		if( !err.compare( e.description()))
   1.307 +		{
   1.308  			err = "Ignoring warning: ";
   1.309  			err += e.description();
   1.310  			LL_WARNS() << err << LL_ENDL;
   1.311  		}
   1.312 -		else{
   1.313 +		else
   1.314 +		{
   1.315  			boost::throw_exception(e);
   1.316  		}
   1.317  	}
   1.318 @@ -594,7 +603,7 @@
   1.319  
   1.320  std::string cachepath(std::string name)
   1.321  {
   1.322 -	return gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"lslpreproc",name);
   1.323 +	return gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "lslpreproc", name);
   1.324  }
   1.325  
   1.326  void cache_script(std::string name, std::string content)
   1.327 @@ -612,16 +621,15 @@
   1.328  
   1.329  void FSLSLPreprocessor::FSProcCacheCallback(LLVFS *vfs, const LLUUID& iuuid, LLAssetType::EType type, void *userdata, S32 result, LLExtStat extstat)
   1.330  {
   1.331 -	
   1.332  	LLUUID uuid = iuuid;
   1.333  	LL_DEBUGS() << "cachecallback called" << LL_ENDL;
   1.334 -	ProcCacheInfo* info =(ProcCacheInfo*)userdata;
   1.335 +	ProcCacheInfo* info = (ProcCacheInfo*)userdata;
   1.336  	LLViewerInventoryItem* item = info->item;
   1.337  	FSLSLPreprocessor* self = info->self;
   1.338 -	if(item && self)
   1.339 +	if (item && self)
   1.340  	{
   1.341  		std::string name = item->getName();
   1.342 -		if(result == LL_ERR_NOERR)
   1.343 +		if (result == LL_ERR_NOERR)
   1.344  		{
   1.345  			LLVFile file(vfs, uuid, type);
   1.346  			S32 file_length = file.getSize();
   1.347 @@ -637,13 +645,13 @@
   1.348  			content += "\n#define __ITEMID__ __UP_ITEMID__\n";*/
   1.349  			//prolly wont work and ill have to be not lazy, but worth a try
   1.350  			delete buffer;
   1.351 -			if(boost::filesystem::native(name))
   1.352 +			if (boost::filesystem::native(name))
   1.353  			{
   1.354  				LL_DEBUGS() << "native name of " << name << LL_ENDL;
   1.355 -				self->mCore->mErrorList->setCommentText(std::string("Cached ")+name);
   1.356 +				self->mCore->mErrorList->setCommentText("Cached " + name);
   1.357  				cache_script(name, content);
   1.358  				std::set<std::string>::iterator loc = self->caching_files.find(name);
   1.359 -				if(loc != self->caching_files.end())
   1.360 +				if (loc != self->caching_files.end())
   1.361  				{
   1.362  					LL_DEBUGS() << "finalizing cache" << LL_ENDL;
   1.363  					self->caching_files.erase(loc);
   1.364 @@ -666,7 +674,7 @@
   1.365  		}
   1.366  	}
   1.367  
   1.368 -	if(info)
   1.369 +	if (info)
   1.370  	{
   1.371  		delete info;
   1.372  	}
   1.373 @@ -678,22 +686,24 @@
   1.374  	mSync = sync;
   1.375  	mDefinitionCaching = defcache;
   1.376  	caching_files.clear();
   1.377 -	mCore->mErrorList->setCommentText(std::string("PreProc Starting..."));
   1.378 +	mCore->mErrorList->setCommentText("PreProc Starting...");
   1.379  	
   1.380 -	LLFile::mkdir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"")+gDirUtilp->getDirDelimiter()+"lslpreproc");
   1.381 +	LLFile::mkdir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"") + gDirUtilp->getDirDelimiter() + "lslpreproc");
   1.382  	std::string script = mCore->mEditor->getText();
   1.383 -	if(mMainScriptName == "")//more sanity
   1.384 +	if (mMainScriptName.empty())//more sanity
   1.385  	{
   1.386  		const LLInventoryItem* item = NULL;
   1.387  		LLPreview* preview = (LLPreview*)mCore->mUserdata;
   1.388 -		if(preview)
   1.389 +		if (preview)
   1.390  		{
   1.391  			item = preview->getItem();
   1.392  		}
   1.393 -		if(item)
   1.394 +
   1.395 +		if (item)
   1.396  		{
   1.397  			mMainScriptName = item->getName();
   1.398 -		}else
   1.399 +		}
   1.400 +		else
   1.401  		{
   1.402  			mMainScriptName = "(Unknown)";
   1.403  		}
   1.404 @@ -703,7 +713,6 @@
   1.405  	cache_script(name, script);
   1.406  	//start the party
   1.407  	start_process();
   1.408 -	
   1.409  }
   1.410  
   1.411  const std::string lazy_list_set_func("\
   1.412 @@ -731,15 +740,15 @@
   1.413  
   1.414  std::string reformat_lazy_lists(std::string script)
   1.415  {
   1.416 -	BOOL add_set = FALSE;
   1.417 +	bool add_set = false;
   1.418  	std::string nscript = script;
   1.419  	nscript = boost::regex_replace(nscript, boost::regex("([a-zA-Z0-9_]+)\\[([a-zA-Z0-9_()\"]+)]\\s*=\\s*([a-zA-Z0-9_()\"\\+\\-\\*/]+)([;)])",boost::regex::perl), "$1=lazy_list_set($1,$2,[$3])$4");
   1.420 -	if(nscript != script)
   1.421 +	if (nscript != script)
   1.422  	{
   1.423 -		add_set = TRUE;
   1.424 +		add_set = true;
   1.425  	}
   1.426  
   1.427 -	if(add_set == TRUE)
   1.428 +	if (add_set)
   1.429  	{
   1.430  		//add lazy_list_set function to top of script, as it is used
   1.431  		nscript = utf8str_removeCRLF(lazy_list_set_func) + "\n" + nscript;
   1.432 @@ -748,14 +757,14 @@
   1.433  }
   1.434  
   1.435  
   1.436 -inline std::string randstr(int len, std::string chars)
   1.437 +inline std::string randstr(S32 len, std::string chars)
   1.438  {
   1.439 -	int clen = int(chars.length());
   1.440 -	int built = 0;
   1.441 +	S32 clen = S32(chars.length());
   1.442 +	S32 built = 0;
   1.443  	std::string ret;
   1.444 -	while(built < len)
   1.445 +	while (built < len)
   1.446  	{
   1.447 -		int r = std::rand() / ( RAND_MAX / clen );
   1.448 +		S32 r = std::rand() / ( RAND_MAX / clen );
   1.449  		r = r % clen;//sanity
   1.450  		ret += chars.at(r);
   1.451  		built += 1;
   1.452 @@ -765,12 +774,12 @@
   1.453  
   1.454  inline std::string quicklabel()
   1.455  {
   1.456 -	return std::string("c")+randstr(5,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
   1.457 +	return std::string("c") + randstr(5, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
   1.458  }
   1.459  
   1.460  std::string minimalize_whitespace(std::string in)
   1.461  {
   1.462 -	return boost::regex_replace(in, boost::regex("\\s*",boost::regex::perl), "\n");		
   1.463 +	return boost::regex_replace(in, boost::regex("\\s*",boost::regex::perl), "\n");
   1.464  }
   1.465  
   1.466  std::string reformat_switch_statements(std::string script)
   1.467 @@ -785,13 +794,13 @@
   1.468  
   1.469  			static std::string switchstr = "switch(";
   1.470  
   1.471 -			int escape = 100;
   1.472 +			S32 escape = 100;
   1.473  
   1.474  			while(boost::regex_search(std::string::const_iterator(buffer.begin()), std::string::const_iterator(buffer.end()), matches, findswitches, boost::match_default) && escape > 1)
   1.475  			{
   1.476 -				int res = matches.position(boost::match_results<std::string::const_iterator>::size_type(0))+1;
   1.477 +				S32 res = matches.position(boost::match_results<std::string::const_iterator>::size_type(0))+1;
   1.478  				
   1.479 -				static int slen = switchstr.length();
   1.480 +				static S32 slen = switchstr.length();
   1.481  
   1.482  				std::string arg = scopeript2(buffer, res+slen-1,'(',')');
   1.483  
   1.484 @@ -804,7 +813,7 @@
   1.485  				LL_DEBUGS() << "arg=[" << arg << "]" << LL_ENDL;;
   1.486  				std::string rstate = scopeript2(buffer, res+slen+arg.length()-1);
   1.487  
   1.488 -				int cutlen = slen;
   1.489 +				S32 cutlen = slen;
   1.490  				cutlen -= 1;
   1.491  				cutlen += arg.length();
   1.492  				cutlen += rstate.length();
   1.493 @@ -812,7 +821,7 @@
   1.494  				//then add arg len and state len to get section to excise
   1.495  
   1.496  				//rip off the scope edges
   1.497 -				int slicestart = rstate.find("{")+1;
   1.498 +				S32 slicestart = rstate.find("{")+1;
   1.499  				rstate = rstate.substr(slicestart,(rstate.rfind("}")-slicestart)-1);
   1.500  				LL_DEBUGS() << "rstate=[" << rstate << "]" << LL_ENDL;
   1.501  
   1.502 @@ -826,11 +835,11 @@
   1.503  				{
   1.504  					//if(statematches[0].matched)
   1.505  					{
   1.506 -						int case_start = statematches.position(boost::match_results<std::string::const_iterator>::size_type(0))+1;//const_iterator2pos(statematches[0].first+1, std::string::const_iterator(rstate.begin()))-1;
   1.507 -						int next_curl = rstate.find("{",case_start+1);
   1.508 -						int next_semi = rstate.find(":",case_start+1);
   1.509 -						int case_end = (next_curl < next_semi && next_curl != -1) ? next_curl : next_semi;
   1.510 -						static int caselen = std::string("case").length();
   1.511 +						S32 case_start = statematches.position(boost::match_results<std::string::const_iterator>::size_type(0))+1;//const_iterator2pos(statematches[0].first+1, std::string::const_iterator(rstate.begin()))-1;
   1.512 +						S32 next_curl = rstate.find("{",case_start+1);
   1.513 +						S32 next_semi = rstate.find(":",case_start+1);
   1.514 +						S32 case_end = (next_curl < next_semi && next_curl != -1) ? next_curl : next_semi;
   1.515 +						static S32 caselen = std::string("case").length();
   1.516  						if(case_end != -1)
   1.517  						{
   1.518  							std::string casearg = rstate.substr(case_start+caselen,case_end-(case_start+caselen));
   1.519 @@ -929,11 +938,12 @@
   1.520  
   1.521  void FSLSLPreprocessor::start_process()
   1.522  {
   1.523 -	if(mWaving)
   1.524 +	if (mWaving)
   1.525  	{
   1.526  		LL_WARNS() << "already waving?" << LL_ENDL;
   1.527  		return;
   1.528  	}
   1.529 +
   1.530  	mWaving = TRUE;
   1.531  	boost::wave::util::file_position_type current_position;
   1.532  	std::string input = mCore->mEditor->getText();
   1.533 @@ -945,31 +955,34 @@
   1.534  	std::string name = mMainScriptName;
   1.535  	bool lazy_lists = gSavedSettings.getBOOL("_NACL_PreProcLSLLazyLists");
   1.536  	bool use_switch = gSavedSettings.getBOOL("_NACL_PreProcLSLSwitch");
   1.537 +	bool use_optimizer = gSavedSettings.getBOOL("_NACL_PreProcLSLOptimizer");
   1.538 +	bool enable_hdd_include = gSavedSettings.getBOOL("_NACL_PreProcEnableHDDInclude");
   1.539 +	bool use_compression = gSavedSettings.getBOOL("_NACL_PreProcLSLTextCompress");
   1.540  	std::string settings;
   1.541  	settings = "Settings: preproc ";
   1.542  	if (lazy_lists)
   1.543  	{
   1.544 -	  settings = settings + " Lazy Lists";
   1.545 -	} 
   1.546 +		settings = settings + " Lazy Lists";
   1.547 +	}
   1.548  	if (use_switch)
   1.549  	{
   1.550 -	  settings = settings + " Switches";
   1.551 +		settings = settings + " Switches";
   1.552  	}
   1.553 -	if(gSavedSettings.getBOOL("_NACL_PreProcLSLOptimizer"))
   1.554 +	if (use_optimizer)
   1.555  	{
   1.556 -		  settings = settings + " Optimize";
   1.557 +		settings = settings + " Optimize";
   1.558  	}
   1.559 -	if(gSavedSettings.getBOOL("_NACL_PreProcEnableHDDInclude"))
   1.560 +	if (enable_hdd_include)
   1.561  	{
   1.562 -		   settings = settings + " HDDInclude";
   1.563 +		settings = settings + " HDDInclude";
   1.564  	}
   1.565 -	if(gSavedSettings.getBOOL("_NACL_PreProcLSLTextCompress"))
   1.566 +	if (use_compression)
   1.567  	{
   1.568 -			settings = settings + " Compress";
   1.569 +		settings = settings + " Compress";
   1.570  	}
   1.571  	//display the settings
   1.572 -	 mCore->mErrorList->setCommentText(std::string(settings));
   1.573 -	 
   1.574 +	mCore->mErrorList->setCommentText(settings);
   1.575 +
   1.576  	LL_DEBUGS() << settings << LL_ENDL;
   1.577  	bool errored = false;
   1.578  	std::string err;
   1.579 @@ -986,29 +999,29 @@
   1.580  		ctx.set_language(boost::wave::enable_prefer_pp_numbers(ctx.get_language()));
   1.581  		ctx.set_language(boost::wave::enable_variadics(ctx.get_language()));
   1.582  		
   1.583 -		std::string path = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"")+gDirUtilp->getDirDelimiter()+"lslpreproc"+gDirUtilp->getDirDelimiter();
   1.584 +		std::string path = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"") + gDirUtilp->getDirDelimiter() + "lslpreproc" + gDirUtilp->getDirDelimiter();
   1.585  		ctx.add_include_path(path.c_str());
   1.586 -		if(gSavedSettings.getBOOL("_NACL_PreProcEnableHDDInclude"))
   1.587 +		if (enable_hdd_include)
   1.588  		{
   1.589  			std::string hddpath = gSavedSettings.getString("_NACL_PreProcHDDIncludeLocation");
   1.590 -			if(hddpath != "")
   1.591 +			if (!hddpath.empty())
   1.592  			{
   1.593  				ctx.add_include_path(hddpath.c_str());
   1.594  				ctx.add_sysinclude_path(hddpath.c_str());
   1.595  			}
   1.596  		}
   1.597 -		std::string def = llformat("__AGENTKEY__=\"%s\"",gAgent.getID().asString().c_str());//legacy because I used it earlier
   1.598 +		std::string def = llformat("__AGENTKEY__=\"%s\"", gAgentID.asString().c_str());//legacy because I used it earlier
   1.599  		ctx.add_macro_definition(def,false);
   1.600 -		def = llformat("__AGENTID__=\"%s\"",gAgent.getID().asString().c_str());
   1.601 +		def = llformat("__AGENTID__=\"%s\"", gAgentID.asString().c_str());
   1.602  		ctx.add_macro_definition(def,false);
   1.603 -		def = llformat("__AGENTIDRAW__=%s",gAgent.getID().asString().c_str());
   1.604 +		def = llformat("__AGENTIDRAW__=%s", gAgentID.asString().c_str());
   1.605  		ctx.add_macro_definition(def,false);
   1.606  		std::string aname = gAgentAvatarp->getFullname();
   1.607 -		def = llformat("__AGENTNAME__=\"%s\"",aname.c_str());
   1.608 +		def = llformat("__AGENTNAME__=\"%s\"", aname.c_str());
   1.609  		ctx.add_macro_definition(def,false);
   1.610 -		def = llformat("__ASSETID__=%s",LLUUID::null.asString().c_str());
   1.611 +		def = llformat("__ASSETID__=%s", LLUUID::null.asString().c_str());
   1.612  		ctx.add_macro_definition(def,false);
   1.613 -		def = llformat("__SHORTFILE__=\"%s\"",name.c_str());
   1.614 +		def = llformat("__SHORTFILE__=\"%s\"", name.c_str());
   1.615  		ctx.add_macro_definition(def,false);
   1.616  
   1.617  		ctx.add_macro_definition("list(input)=((list)(input))",false);
   1.618 @@ -1023,15 +1036,15 @@
   1.619  
   1.620  		context_type::iterator_type first = ctx.begin();
   1.621  		context_type::iterator_type last = ctx.end();
   1.622 -	        
   1.623 -        while (first != last)
   1.624 +
   1.625 +		while (first != last)
   1.626  		{
   1.627 -			if(caching_files.size() != 0)
   1.628 +			if (caching_files.size() != 0)
   1.629  			{
   1.630  				mWaving = FALSE;
   1.631  				return;
   1.632  			}
   1.633 -            current_position = (*first).get_position();
   1.634 +			current_position = (*first).get_position();
   1.635  			
   1.636  			std::string token = std::string((*first).get_value().c_str());//stupid boost bitching even though we know its a std::string
   1.637  			
   1.638 @@ -1042,17 +1055,17 @@
   1.639  
   1.640  			output += token;
   1.641  			
   1.642 -			if(lazy_lists == FALSE)
   1.643 +			if (!lazy_lists)
   1.644  			{
   1.645  				lazy_lists = ctx.is_defined_macro(std::string("USE_LAZY_LISTS"));
   1.646  			}
   1.647  			
   1.648 -			if(use_switch == FALSE)
   1.649 +			if (!use_switch)
   1.650  			{
   1.651  				use_switch = ctx.is_defined_macro(std::string("USE_SWITCHES"));
   1.652  			}
   1.653 -            ++first;
   1.654 -        }
   1.655 +			++first;
   1.656 +		}
   1.657  	}
   1.658  	catch(boost::wave::cpp_exception const& e)
   1.659  	{
   1.660 @@ -1081,31 +1094,33 @@
   1.661  		mCore->mErrorList->setCommentText(err);
   1.662  	}
   1.663  
   1.664 -	if(!errored)
   1.665 +	if (!errored)
   1.666  	{
   1.667  		FAILDEBUG
   1.668 -		if(lazy_lists == TRUE)
   1.669 +		if (lazy_lists)
   1.670  		{
   1.671  			try
   1.672  			{
   1.673  				mCore->mErrorList->setCommentText("Applying lazy list set transform");
   1.674  				output = reformat_lazy_lists(output);
   1.675 -			}catch(...)
   1.676 -			{	
   1.677 +			}
   1.678 +			catch(...)
   1.679 +			{
   1.680  				errored = TRUE;
   1.681  				err = "unexpected exception in lazy list converter.";
   1.682  				mCore->mErrorList->setCommentText(err);
   1.683  			}
   1.684  
   1.685  		}
   1.686 -		if(use_switch == TRUE)
   1.687 +		if (use_switch)
   1.688  		{
   1.689  			try
   1.690  			{
   1.691  				mCore->mErrorList->setCommentText("Applying switch statement transform");
   1.692  				output = reformat_switch_statements(output);
   1.693 -			}catch(...)
   1.694 -			{	
   1.695 +			}
   1.696 +			catch(...)
   1.697 +			{
   1.698  				errored = TRUE;
   1.699  				err = "unexpected exception in switch statement converter.";
   1.700  				mCore->mErrorList->setCommentText(err);
   1.701 @@ -1113,11 +1128,11 @@
   1.702  		}
   1.703  	}
   1.704  
   1.705 -	if(!mDefinitionCaching)
   1.706 +	if (!mDefinitionCaching)
   1.707  	{
   1.708 -		if(!errored)
   1.709 +		if (!errored)
   1.710  		{
   1.711 -			if(gSavedSettings.getBOOL("_NACL_PreProcLSLOptimizer"))
   1.712 +			if (use_optimizer)
   1.713  			{
   1.714  				mCore->mErrorList->setCommentText("Optimizing out unreferenced user-defined functions and global variables");
   1.715  				try
   1.716 @@ -1132,32 +1147,33 @@
   1.717  				}
   1.718  			}
   1.719  		}
   1.720 -		if(!errored)
   1.721 +		if (!errored)
   1.722  		{
   1.723 -			if(gSavedSettings.getBOOL("_NACL_PreProcLSLTextCompress"))
   1.724 +			if (use_compression)
   1.725  			{
   1.726  				mCore->mErrorList->setCommentText("Compressing lsltext by removing unnecessary space");
   1.727  				try
   1.728  				{
   1.729  					output = lslcomp(output);
   1.730 -				}catch(...)
   1.731 -				{	
   1.732 +				}
   1.733 +				catch(...)
   1.734 +				{
   1.735  					errored = TRUE;
   1.736  					err = "unexpected exception in lsl compressor";
   1.737  					mCore->mErrorList->setCommentText(err);
   1.738  				}
   1.739  			}
   1.740  		}
   1.741 -		output = encode(rinput)+"\n\n"+output;
   1.742 +		output = encode(rinput) + "\n\n" + output;
   1.743  
   1.744  
   1.745  		LLTextEditor* outfield = mCore->mPostEditor;//getChild<LLViewerTextEditor>("post_process");
   1.746 -		if(outfield)
   1.747 +		if (outfield)
   1.748  		{
   1.749  			outfield->setText(LLStringExplicit(output));
   1.750  		}
   1.751  		mCore->mPostScript = output;
   1.752 -		mCore->doSaveComplete((void*)mCore,mClose,mSync);
   1.753 +		mCore->doSaveComplete((void*)mCore, mClose, mSync);
   1.754  	}
   1.755  	mWaving = FALSE;
   1.756  }
   1.757 @@ -1208,13 +1224,13 @@
   1.758  {
   1.759  	bool domono = agent_inv;
   1.760  	
   1.761 -	if(text.find("//mono\n") != -1)
   1.762 +	if (text.find("//mono\n") != -1)
   1.763  	{
   1.764 -		domono = TRUE;
   1.765 +		domono = true;
   1.766  	}
   1.767 -	else if(text.find("//lsl2\n") != -1)
   1.768 +	else if (text.find("//lsl2\n") != -1)
   1.769  	{
   1.770 -		domono = FALSE;
   1.771 +		domono = false;
   1.772  	}
   1.773  	return domono;
   1.774  }

mercurial