<commit_before>
'use strict';

import { Dispatcher, Service } from './service';
import { IContext } from './icontext';


// {
// 	"ID":"g_1",
// 	"Numchildren":0,
// 	"Val":"0 '\\000'\n",
// 	"CanAssign":true,
// 	"Expression":"testfunc2_local",
// 	"ExprPath":"testfunc2_local",
// 	"FormatString":"",
// 	"Type":"uint8_t(a complex DWARF expression:\n     0: DW_OP_breg28 1 [$r28]\n.\n)",
// 	"Size":1
// }
export interface IExpressionContext extends IContext {
	Numchildren: number;
	Val: string;
	CanAssign: boolean;
	Expression: string;
	ExprPath: string;
	FormatString: string;
	Type: string;
	Size: number;
}


export class ExpressionContext implements IExpressionContext {

	public ID: string;
	public Numchildren: number;
	public Val: string;
	public CanAssign: boolean;
	public Expression: string;
	public ExprPath: string;
	public FormatString: string;
	public Type: string;
	public Size: number;

	public setProperties(properties: any): void {

	}

	public getProperties(callback: (properties: any) => void): void {

	}


	public static fromJson(data: IExpressionContext): ExpressionContext {
		let context = new ExpressionContext();

		context.ID = data["ID"];
		context.Numchildren = data["Numchildren"];
		context.Val = data["Val"];
		context.CanAssign = data["CanAssign"];
		context.Expression = data["Expression"];
		context.ExprPath = data["ExprPath"];
		context.FormatString = data["FormatString"];
		context.Type = data["Type"];
		context.Size = data["Size"];

		return context;
	}

	public toString(): string {
		return `${this.ID}`;
	}
}

export class ExpressionsService extends Service {

	public constructor(dispatcher: Dispatcher) {
		super("Expressions", dispatcher);
	}

	public getChildren(parentContext: string, callback: (children: string[]) => void): void {

		this.dispatcher.sendCommand(this.name, "getChildren", [parentContext], (errorReport, eventData) => {
			let contextIds = <string[]>JSON.parse(eventData);
			callback(contextIds);

		});
	}

	public getContext(contextId: string, callback: (expression: ExpressionContext) => void): void {
		this.dispatcher.sendCommand(this.name, "getContext", [contextId], (errorReport, eventData) => {
			let contextData = <ExpressionContext>JSON.parse(eventData[0]);
			let newContext = ExpressionContext.fromJson(contextData);

			callback(newContext);
		});
	}

	public compute(contextId: string, language: string, expression: string, callback: (expression: ExpressionContext) => void): void {
		this.dispatcher.sendCommand(this.name, "compute", [language, expression], (errorReport, eventData) => {
			let contextData = <ExpressionContext>JSON.parse(eventData[0]);
			let newContext = ExpressionContext.fromJson(contextData);

			callback(newContext);
		})
	}

	public dispose(contextId: string): void {
		this.dispatcher.sendCommand(this.name, "dispose", [contextId]);
	}



	public eventHandler(event: string, eventData: string[]): void {
		switch(event) {
			default:
				this.log(`No matching event handler: ${event}`);
		}
	}
}<commit_msg>Implement dispose on expression<commit_after>
'use strict';

import { Dispatcher, Service } from './service';
import { IContext } from './icontext';


// {
// 	"ID":"g_1",
// 	"Numchildren":0,
// 	"Val":"0 '\\000'\n",
// 	"CanAssign":true,
// 	"Expression":"testfunc2_local",
// 	"ExprPath":"testfunc2_local",
// 	"FormatString":"",
// 	"Type":"uint8_t(a complex DWARF expression:\n     0: DW_OP_breg28 1 [$r28]\n.\n)",
// 	"Size":1
// }
export interface IExpressionContext extends IContext {
	Numchildren: number;
	Val: string;
	CanAssign: boolean;
	Expression: string;
	ExprPath: string;
	FormatString: string;
	Type: string;
	Size: number;
}


export class ExpressionContext implements IExpressionContext {

	public ID: string;
	public Numchildren: number;
	public Val: string;
	public CanAssign: boolean;
	public Expression: string;
	public ExprPath: string;
	public FormatString: string;
	public Type: string;
	public Size: number;

	private service: ExpressionsService;

	public setProperties(properties: any): void {

	}

	public getProperties(callback: (properties: any) => void): void {

	}


	public static fromJson(service: ExpressionsService, data: IExpressionContext): ExpressionContext {
		let context = new ExpressionContext();

		context.service = service;

		context.ID = data["ID"];
		context.Numchildren = data["Numchildren"];
		context.Val = data["Val"];
		context.CanAssign = data["CanAssign"];
		context.Expression = data["Expression"];
		context.ExprPath = data["ExprPath"];
		context.FormatString = data["FormatString"];
		context.Type = data["Type"];
		context.Size = data["Size"];

		return context;
	}

	public toString(): string {
		return `${this.ID}`;
	}

	public dispose(): void {
		this.service.dispose(this.ID);
	}
}

export class ExpressionsService extends Service {

	public constructor(dispatcher: Dispatcher) {
		super("Expressions", dispatcher);
	}

	public getChildren(parentContext: string, callback: (children: string[]) => void): void {

		this.dispatcher.sendCommand(this.name, "getChildren", [parentContext], (errorReport, eventData) => {
			let contextIds = <string[]>JSON.parse(eventData);
			callback(contextIds);

		});
	}

	public getContext(contextId: string, callback: (expression: ExpressionContext) => void): void {
		this.dispatcher.sendCommand(this.name, "getContext", [contextId], (errorReport, eventData) => {
			let contextData = <ExpressionContext>JSON.parse(eventData[0]);
			let newContext = ExpressionContext.fromJson(this, contextData);

			callback(newContext);
		});
	}

	public compute(contextId: string, language: string, expression: string, callback: (expression: ExpressionContext) => void): void {
		this.dispatcher.sendCommand(this.name, "compute", [contextId, language, expression], (errorReport, eventData) => {
			let contextData = <ExpressionContext>JSON.parse(eventData[0]);
			let newContext = ExpressionContext.fromJson(this, contextData);

			callback(newContext);
		})
	}

	public dispose(contextId: string): void {
		this.dispatcher.sendCommand(this.name, "dispose", [contextId]);
	}



	public eventHandler(event: string, eventData: string[]): void {
		switch(event) {
			default:
				this.log(`No matching event handler: ${event}`);
		}
	}
}
{'fraction_non_alphanumeric': 0.1493756003842459, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 4.9894534995206135, 'pattern_counts': {'":': 18, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5545041', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1906, 'n_words': 453}