コード例 #1
0
ファイル: default.py プロジェクト: raxvan/precompiler
 def AddUserDefineValue(self, define_name, string_value):
     tokens = _pc_utils.precompiler_tokens
     tok_def = _pc_utils.CreateUserDefineSourceToken(
         define_name, string_value)
     self.input_state.AddGlobalDefine(
         _impl_pc_define.VarDefine(define_name, None, string_value, tok_def,
                                   self))
コード例 #2
0
 def AddUserDefineValue(self, define_name, string_value):
     tokens = _pc_utils.precompiler_tokens
     tok_def = (_pc_utils.precompiler_tokens.k_define, 0,
                (define_name, None, string_value), ["user", -1])
     self.input_state.AddGlobalDefine(
         _impl_pc_define.VarDefine(define_name, string_value, None, tok_def,
                                   self))
コード例 #3
0
	def open_and_load_config_file(self,strval,tok):

		abs_file_path = self.evaluate_file_path(strval,tok,False)

		file_handle_obj,raw_defines_list = self.load_config_defines(abs_file_path)
		if file_handle_obj == None:
			self.RaiseErrorOnToken(tok,"Unknown file format!.","Config file path `" + abs_file_path + "`.")

		self.mark_dependency(abs_file_path,file_handle_obj)

		for define_name,string_value in raw_defines_list:
			self.input_state.AddGlobalDefine(_impl_pc_define.VarDefine(define_name,None,string_value,tok,self))
コード例 #4
0
ファイル: default.py プロジェクト: raxvan/precompiler
    def LoadConfigFile(self, abs_config_file_path):
        file_handle_obj, raw_defines_list = self.load_config_defines(
            abs_config_file_path)
        if file_handle_obj == None:
            return False

        self.mark_dependency(abs_config_file_path, file_handle_obj)

        for define_name, string_value in raw_defines_list:
            tok_def = _pc_utils.CreateUserDefineSourceToken(
                define_name, string_value)
            self.input_state.AddGlobalDefine(
                _impl_pc_define.VarDefine(define_name, None, string_value,
                                          tok_def, self))
コード例 #5
0
	def Advance(self,tok):

		_prep = self.precompiler

		_is_executed = _prep.is_evaluating() #true/false if the

		tokflags = tok[0]

		#strings, characters, comments, whitespaces, etc
		if (tokflags & _token_flags.k_trivial_flag) != 0:
			if _is_executed:

				self.assembler.Write(tok)
			return self

		toktype = tok[1]
		_tok_value = tok[2]

		#check for defines with same name
		if toktype == _primitive_toks.kIdentifier:
			if _is_executed:
				df = _prep.input_state.FindVarDefineWithName(_tok_value[0])
				if df != None:
					return self._expand_define(df,tok)
				else:
					self.assembler.Write(tok)
			return self

		#conditional tokens, no output
		if (tokflags & _token_flags.k_conditional_flag) != 0:
			if toktype == _cmd_tokens.k_if_defined:
				if _is_executed:
					_prep.push_execution_state(_prep.is_defined(_tok_value[1]))
				else:
					_prep.push_execution_state(None)
			elif toktype == _cmd_tokens.k_if_not_defined:
				if _is_executed:
					cond = _prep.is_defined(_tok_value[1])
					_prep.push_execution_state(True if (cond == False) else False)
				else:
					_prep.push_execution_state(None)
			elif toktype == _cmd_tokens.k_if:
				if _prep.is_evaluating():
					_prep.push_execution_state(_prep.evaluate_if_condition(tok))
				else:
					_prep.push_execution_state(None)
			elif toktype == _cmd_tokens.k_else_if:
				_prep.negate_execution_state(tok)
				if _prep.is_evaluating():
					_prep.pop_execution_state(tok)
					_prep.push_execution_state(_prep.evaluate_if_condition(tok))
				else:
					_prep.pop_execution_state(tok)
					_prep.push_execution_state(None)
			elif toktype == _cmd_tokens.k_else:
				_prep.negate_execution_state(tok)
			elif toktype == _cmd_tokens.k_endif:
				_prep.pop_execution_state(tok)

			#end of conditional
			return self

		#non conditionals statements, no output
		if _is_executed:
			#all this commands should have k_command_flag
			if (tokflags & _token_flags.k_id_str_argument_flag) != 0:
				(_,name_or_str,type_of_argument) = _tok_value
				no_error_flag = (tokflags & _token_flags.k_no_error) != 0

				if type_of_argument == _token_flags.k_identifier_flag:
					string_value = _prep.get_required_define(tok,name_or_str).GetValueAsString(tok)
					return self._evaluate_functions_with_string_arg(tok,toktype,string_value,no_error_flag)

				elif type_of_argument == _token_flags.k_string_flag:
					return self._evaluate_functions_with_string_arg(tok,toktype,_pc_utils.UnboxString(name_or_str),no_error_flag)

			elif toktype == _cmd_tokens.k_define:
				(_,name,content) = _tok_value
				(arguments,value) = _prep.parse_define_content(tok,content);
				if (tokflags & _token_flags.k_no_error) != 0:
					_prep.add_new_define(tok,_impl_pc_define.VarDefine(name,arguments,value,tok,_prep),False)
				else:
					_prep.add_new_define(tok,_impl_pc_define.VarDefine(name,arguments,value,tok,_prep),True)

			elif toktype == _cmd_tokens.k_collapse:
				self._collapse_macro(tok)
			elif toktype == _cmd_tokens.k_run:
				self._run_command(tok,False)
			elif toktype == _cmd_tokens.k_inline_eval:
				self._run_command(tok,True)

			elif toktype == _cmd_tokens.k_cwstrip:
				_prep.get_required_define(tok,_tok_value[1]).CwStrip()

			elif toktype == _cmd_tokens.k_undefine:
				if _prep.input_state.RemoveDefineRecursive(_tok_value[1]) == False:
					_prep.RaiseErrorOnToken(tok,"Failed to execute #undef statement!","Searching for `" + tok[2] + "`")
			elif toktype == _cmd_tokens.k_source:
				self._evaluate_source_id(tok,_tok_value[1])

			return self

		elif (tokflags & _token_flags.k_command_flag) != 0:
			#cmd tokens that are on a not evaluated, are skipped
			return self

		#should never reach this place
		assert False, "Internal execution error!"