<commit_before>/***************************************************************************
 *   Copyright (C) by <NAME>                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package jolie.process;

import jolie.ExecutionThread;
import jolie.runtime.ExitingException;
import jolie.runtime.FaultException;
import jolie.runtime.Value;
import jolie.runtime.VariablePathBuilder;

public class ScopeProcess implements Process
{
	private class Execution
	{
		final private ScopeProcess parent;
		final private ExecutionThread ethread;
		private boolean shouldMerge = true;
		private FaultException fault = null;
		
		public Execution( ScopeProcess parent )
		{
			this.parent = parent;
			this.ethread = ExecutionThread.currentThread();
		}
		
		public void run()
			throws FaultException, ExitingException
		{
			ethread.pushScope( parent.id );
			runScope( parent.process );
			if ( autoPop ) {
				ethread.popScope( shouldMerge );
			}
			if ( shouldMerge && fault != null ) {
				throw fault;
			}
		}
		
		private void runScope( Process p )
			throws ExitingException
		{
			try {
				p.run();
				if ( ethread.isKilled() ) {
					shouldMerge = false;
					p = ethread.getCompensation( id );
					if ( p != null ) { // Termination handling
						FaultException f = ethread.killerFault();
						ethread.clearKill();
						this.runScope( p );
						ethread.kill( f );
					}
				}
			} catch( FaultException f ) {
				p = ethread.getFaultHandler( f.faultName(), true );
				if ( p != null ) {
					Value scopeValue =
							new VariablePathBuilder( false )
							.add( ethread.currentScopeId(), 0 )
							.toVariablePath()
							.getValue();
					scopeValue.getChildren( f.faultName() ).set( 0, f.value() );
					this.runScope( p );
				} else {
					fault = f;
				}
			}
		}
	}
	
	private final String id;
	private final Process process;
	private final boolean autoPop;
	
	public ScopeProcess( String id, Process process, boolean autoPop )
	{
		this.id = id;
		this.process = process;
		this.autoPop = autoPop;<commit_msg>added faultName into default field of a scope, when a fault is raised<commit_after>/***************************************************************************
 *   Copyright (C) by <NAME>                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package jolie.process;

import jolie.ExecutionThread;
import jolie.lang.Constants;
import jolie.runtime.ExitingException;
import jolie.runtime.FaultException;
import jolie.runtime.Value;
import jolie.runtime.VariablePathBuilder;

public class ScopeProcess implements Process
{
	private class Execution
	{
		final private ScopeProcess parent;
		final private ExecutionThread ethread;
		private boolean shouldMerge = true;
		private FaultException fault = null;
		
		public Execution( ScopeProcess parent )
		{
			this.parent = parent;
			this.ethread = ExecutionThread.currentThread();
		}
		
		public void run()
			throws FaultException, ExitingException
		{
			ethread.pushScope( parent.id );
			runScope( parent.process );
			if ( autoPop ) {
				ethread.popScope( shouldMerge );
			}
			if ( shouldMerge && fault != null ) {
				throw fault;
			}
		}
		
		private void runScope( Process p )
			throws ExitingException
		{
			try {
				p.run();
				if ( ethread.isKilled() ) {
					shouldMerge = false;
					p = ethread.getCompensation( id );
					if ( p != null ) { // Termination handling
						FaultException f = ethread.killerFault();
						ethread.clearKill();
						this.runScope( p );
						ethread.kill( f );
					}
				}
			} catch( FaultException f ) {
				p = ethread.getFaultHandler( f.faultName(), true );
				if ( p != null ) {
					Value scopeValue =
							new VariablePathBuilder( false )
							.add( ethread.currentScopeId(), 0 )
							.toVariablePath()
							.getValue();
					scopeValue.getChildren( f.faultName() ).set( 0, f.value() );
                                        scopeValue.getFirstChild( Constants.Keywords.DEFAULT_HANDLER_NAME ).setValue( f.faultName() );
					this.runScope( p );
				} else {
					fault = f;
				}
			}
		}
	}
	
	private final String id;
	private final Process process;
	private final boolean autoPop;
	
	public ScopeProcess( String id, Process process, boolean autoPop )
	{
		this.id = id;
		this.process = process;
		this.autoPop = autoPop;
{'fraction_non_alphanumeric': 0.11979463776383342, 'fraction_numerical': 0.004848830576155163, 'mean_word_length': 1.8848210612916496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7137902', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1728, 'n_words': 579}