public override bool NotNullObjectEquals(ClepsType obj) { if (obj.GetType() != typeof(BasicClepsType)) { return(false); } BasicClepsType objToCompare = obj as BasicClepsType; return(RawTypeName == objToCompare.RawTypeName); }
public override object VisitThisAssignment([NotNull] ClepsParser.ThisAssignmentContext context) { if(CurrMemberIsStatic) { string errorMessage = "Cannot use the this keyword in a static member"; Status.AddError(new CompilerError(FileName, context.Start.Line, context.Start.Column, errorMessage)); //just return something to avoid stalling return CodeGenerator.CreateByte(0); } BasicClepsType currentClassType = new BasicClepsType(FullyQualifiedClassName); IValue thisValue = CodeGenerator.GetThisInstanceValue(currentClassType); IValue thisPtr = CodeGenerator.GetPtrToValue(thisValue); return thisPtr; }
public override object VisitFunctionCallAssignment([NotNull] ClepsParser.FunctionCallAssignmentContext context) { BasicClepsType currentType = new BasicClepsType(FullyQualifiedClassName); IValue target = CurrMemberIsStatic? null : CodeGenerator.GetThisInstanceValue(currentType); return doFunctionCall(context.functionCall(), target, currentType, true /* allowVoidReturn */); }
public IValue GetFunctionCallReturnValue(IValue target, BasicClepsType targetType, string targetFunctionName, FunctionClepsType clepsType, List<IValue> parameters) { string code; if (CompilerConstants.SystemSupportedTypes.Contains(targetType) && target != null) { string fullFunctionName = String.Format("{0}.{1}.prototype.{2}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString(), JavaScriptCodeParameters.GetMangledFunctionName(targetFunctionName, clepsType)); string functionTarget = target != null ? (target as JavaScriptValue).Expression : String.Format("{0}.{1}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString()); string parameterString = String.Join("", parameters.Select(v => ", " + (v as JavaScriptValue).Expression).ToList()); code = String.Format("{0}.call({1}{2})", fullFunctionName, functionTarget, parameterString); } else { string functionTarget = target != null ? (target as JavaScriptValue).Expression : String.Format("{0}.{1}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString()); string fullFunctionName = String.Format("{0}.{1}", functionTarget, JavaScriptCodeParameters.GetMangledFunctionName(targetFunctionName, clepsType)); string parameterString = String.Join(", ", parameters.Select(v => (v as JavaScriptValue).Expression).ToList()); code = String.Format("{0}({1})", fullFunctionName, parameterString); } JavaScriptValue ret = new JavaScriptValue(code, clepsType.ReturnType); return ret; }
public IValue GetThisInstanceValue(BasicClepsType thisInstanceType) { JavaScriptValue ret = new JavaScriptValue("this", thisInstanceType); return ret; }
public IValue CreateClassInstance(BasicClepsType instanceType, List<IValue> parameters) { string parameterString = String.Join(", ", parameters.Select(v => (v as JavaScriptValue).Expression).ToList()); string code = String.Format("new {0}.{1}({2})", JavaScriptCodeParameters.TOPLEVELNAMESPACE, instanceType.GetClepsTypeString(), parameterString); JavaScriptValue ret = new JavaScriptValue(code, instanceType); return ret; }
public IValue CreateClassInstance(BasicClepsType instanceType, List<IValue> parameters) { throw new NotImplementedException(); }
public override object VisitFunctionCallAssignment([NotNull] ClepsParser.FunctionCallAssignmentContext context) { if(!ClassManager.IsClassBodySet(FullyQualifiedClassName)) { //This is probably due to some earlier error. Just return something to avoid stalling compilation return CodeGenerator.CreateByte(0); } ClepsType currentType = new BasicClepsType(FullyQualifiedClassName); return doFunctionCall(context.functionCall(), currentType, !CurrMemberIsStatic, false /* allowVoidReturn */); }