<commit_before>/*
 * Copyright (c) 2012 DeNA Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

import "./classdef.jsx";
import "./parser.jsx";
import "./type.jsx";
import "./util.jsx";
import "./statement.jsx";
import "./optimizer.jsx";


abstract class Expression implements Stashable {

	var _token : Token;

	function constructor (token : Token) {
		this._token = token;
	}

	function constructor (that : Expression) {
		this._token = that.getToken();
		for (var k in that._optimizerStash)
			this._optimizerStash[k] = that._optimizerStash[k].clone();
	}

	abstract function clone () : Expression;
	abstract function serialize () : variant;

	function instantiate (instantiationContext : InstantiationContext) : boolean {
		function onExpr(expr : Expression) : boolean {
			if (expr instanceof NewExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as NewExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof ArrayLiteralExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as ArrayLiteralExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof MapLiteralExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as MapLiteralExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof AsExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as AsExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof AsNoConvertExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as AsNoConvertExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof ClassExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as ClassExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof LocalExpression) {
				// update local to the instantiated one
				(expr as LocalExpression).setLocal((expr as LocalExpression).getLocal().getInstantiated());
			}
			return expr.forEachExpression(onExpr);
		}
		return onExpr(this);
	}

	function getToken () : Token {
		return this._token;
	}

	abstract function analyze (context : AnalysisContext, parentExpr : Expression) : boolean;

	abstract function getType () : Type;

	function getHolderType () : Type {
		return null;
	}

	function forEachExpression (cb : function(:Expression):boolean) : boolean {
		return this.forEachExpression(function(expr : Expression, _ : function(:Expression):void){
			return cb(expr);
		});
	}

	abstract function forEachExpression (cb : function (:Expression, :function (:Expression) : void) : boolean) : boolean;

	function assertIsAssignable (context : AnalysisContext, token : Token, type : Type) : boolean {
		context.errors.push(new CompileError(token, "left-hand-side expression is not assignable"));
		return false;
	}

	override function getOptimizerStash () : Map.<OptimizerStash> {
		return this._optimizerStash;
	}

	static function assertIsAssignable (context : AnalysisContext, token : Token, lhsType : Type, rhsType : Type) : boolean {
		if (! lhsType.isAssignable()) {
			context.errors.push(new CompileError(token, "left-hand-side expression is not assignable"));
			return false;
		}
		if (! rhsType.isConvertibleTo(lhsType)) {<commit_msg>remove redundant code<commit_after>/*
 * Copyright (c) 2012 DeNA Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

import "./classdef.jsx";
import "./parser.jsx";
import "./type.jsx";
import "./util.jsx";
import "./statement.jsx";
import "./optimizer.jsx";


abstract class Expression implements Stashable {

	var _token : Token;

	function constructor (token : Token) {
		this._token = token;
	}

	function constructor (that : Expression) {
		this._token = that.getToken();
		for (var k in that._optimizerStash)
			this._optimizerStash[k] = that._optimizerStash[k].clone();
	}

	abstract function clone () : Expression;
	abstract function serialize () : variant;

	function instantiate (instantiationContext : InstantiationContext) : boolean {
		function onExpr(expr : Expression) : boolean {
			if (expr instanceof NewExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as NewExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof ArrayLiteralExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as ArrayLiteralExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof MapLiteralExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as MapLiteralExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof AsExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as AsExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof AsNoConvertExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as AsNoConvertExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof ClassExpression) {
				var srcType = expr.getType();
				if (srcType != null) {
					(expr as ClassExpression).setType(srcType.instantiate(instantiationContext));
				}
			} else if (expr instanceof LocalExpression) {
				// update local to the instantiated one
				(expr as LocalExpression).setLocal((expr as LocalExpression).getLocal().getInstantiated());
			}
			return expr.forEachExpression(onExpr);
		}
		return onExpr(this);
	}

	function getToken () : Token {
		return this._token;
	}

	abstract function analyze (context : AnalysisContext, parentExpr : Expression) : boolean;

	abstract function getType () : Type;

	function getHolderType () : Type {
		return null;
	}

	function forEachExpression (cb : function(:Expression):boolean) : boolean {
		return this.forEachExpression(function(expr : Expression, _ : function(:Expression):void){
			return cb(expr);
		});
	}

	abstract function forEachExpression (cb : function (:Expression, :function (:Expression) : void) : boolean) : boolean;

	function assertIsAssignable (context : AnalysisContext, token : Token, type : Type) : boolean {
		context.errors.push(new CompileError(token, "left-hand-side expression is not assignable"));
		return false;
	}

	static function assertIsAssignable (context : AnalysisContext, token : Token, lhsType : Type, rhsType : Type) : boolean {
		if (! lhsType.isAssignable()) {
			context.errors.push(new CompileError(token, "left-hand-side expression is not assignable"));
			return false;
		}
		if (! rhsType.isConvertibleTo(lhsType)) {
{'fraction_non_alphanumeric': 0.10350246969016615, 'fraction_numerical': 0.000898069151324652, 'mean_word_length': 4.222157092614302, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6136243', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2408, 'n_words': 838}