static bool CopyCatchVar(Command TryComm, CodeScopeNode Scope, Identifier Type, CodeString Name, CodeString Code) { var CatchVar = GetOrCreateCatchVariable(TryComm); var NewVar = Scope.CreateAndDeclareVariable(Name, Type); if (NewVar == null || CatchVar == null) { return(false); } return(CopyCatchVar(Scope, CatchVar, NewVar, Code)); }
static bool CopyCatchVar(CodeScopeNode Scope, Identifier From, Identifier To, CodeString Code) { var Plugin = Scope.GetPlugin(); if (!Plugin.Begin()) { return(false); } var Ch = new ExpressionNode[] { Plugin.NewNode(new IdExpressionNode(To, Code)), Plugin.NewNode(new IdExpressionNode(From, Code)), }; if (Ch[0] == null || Ch[1] == null) { return(false); } if (!To.Children[0].IsEquivalent(From.Children[0])) { var CastCh1 = Plugin.NewNode(new IdExpressionNode(To.Children[0], Code)); if (CastCh1 == null) { return(false); } var CastCh = new ExpressionNode[] { Ch[1], CastCh1 }; Ch[1] = Plugin.NewNode(new OpExpressionNode(Operator.Cast, CastCh, Code)); if (Ch[1] == null) { return(false); } } var Node = Plugin.NewNode(new OpExpressionNode(Operator.Assignment, Ch, Code)); if (Node == null || Plugin.End(ref Node) == PluginResult.Failed) { return(false); } var Comm = new Command(Scope, Code, CommandType.Expression); Comm.Expressions = new List <ExpressionNode>() { Node }; Scope.Children.Add(Comm); return(true); }
static bool CallStaticConstructors(IdContainer Container, CodeScopeNode Scope, PluginRoot Plugin, CodeString Code) { for (var i = 0; i < Container.Children.Count; i++) { if (!CallStaticConstructors(Container.Children[i], Scope, Plugin, Code)) { return(false); } } for (var i = 0; i < Container.IdentifierList.Count; i++) { var Ctor = Container.IdentifierList[i] as Constructor; if (Ctor == null || (Ctor.Flags & IdentifierFlags.Static) == 0) { continue; } if (!Plugin.Begin()) { return(false); } var CtorNode = Plugin.NewNode(new IdExpressionNode(Ctor, Code)); if (CtorNode == null) { Plugin.Reset(); return(false); } var NodeCh = new ExpressionNode[] { CtorNode }; var Node = Plugin.NewNode(new OpExpressionNode(Operator.Call, NodeCh, Code)); if (Node == null || Plugin.End(ref Node) == PluginResult.Failed) { Plugin.Reset(); return(false); } Scope.Children.Add(new Command(Scope, Code, CommandType.Expression) { Expressions = new List <ExpressionNode>() { Node }, }); } return(true); }
bool AddConstructorCommands() { if (Function is Constructor) { var Structured = Parent as StructuredScope; var Type = Structured.StructuredType; #warning ERROR if (ConstructorCall == null) { for (var i = 0; i < Type.BaseStructures.Length; i++) { var Base = Type.BaseStructures[i].Base; var BaseStructure = Base.UnderlyingStructureOrRealId as StructuredType; if (!BaseStructure.HasParameterLessCtor) { State.Messages.Add(MessageId.NoParamLessConstructor, Function.Declaration); return(false); } } } if (Type is ClassType) { var CtorInitializer = new CodeScopeNode(this, new CodeString()); if (!CtorInitializer.BasicConstructorCommands()) { return(false); } Children.Insert(0, CtorInitializer); } } return(true); }
public abstract bool Process(CodeScopeNode Scope);
public static CodeScopeNode CreateCatchScope(Command TryComm, CodeString CommandCode, CodeString Inner, Identifier Type = null, CodeString Name = new CodeString()) { var State = TryComm.State; if ((TryComm.Flags & CommandFlags.CatchesAllException) != 0) { State.Messages.Add(MessageId.CatchesAllException, CommandCode); return(null); } if (TryComm.CatchScope == null) { CreateRootCatchScope(TryComm); } var ExceptionClass = Identifiers.GetByFullNameFast <ClassType>(State, "System.Exception"); if (ExceptionClass == null) { throw new ApplicationException(); } if (Type == null || Type.IsEquivalent(ExceptionClass)) { TryComm.Flags |= CommandFlags.CatchesAllException; if (TryComm.CatchScope.Children.Count == 0) { if ((TryComm.Flags & CommandFlags.TryHasCatchVariable) != 0) { throw new ApplicationException(); } if (Type != null && !CreateCatchVariable(TryComm, Type, Name)) { return(null); } TryComm.CatchScope.Code = Inner; return(TryComm.CatchScope); } else { var Cond = TryComm.CatchScope.Children[0] as Command; var ElseScope = new CodeScopeNode(Cond, Inner); Cond.Children.Add(ElseScope); if (Type != null && !CopyCatchVar(TryComm, ElseScope, Type, Name, CommandCode)) { return(null); } return(ElseScope); } } else { if (!Identifiers.IsSubtypeOf(Type, ExceptionClass)) { State.Messages.Add(MessageId.CannotBeThisType, Name); return(null); } Command Cond; if (TryComm.CatchScope.Children.Count == 0) { Cond = new Command(TryComm.CatchScope, TryComm.Code, CommandType.If); Cond.Expressions = new List <ExpressionNode>(); TryComm.CatchScope.Children.Add(Cond); } else { Cond = TryComm.CatchScope.Children[0] as Command; } var Condition = CreateCatchCondition(TryComm, Cond, Type, CommandCode); if (Condition == null) { return(null); } var ThenScope = new CodeScopeNode(Cond, Inner); Cond.Expressions.Add(Condition); Cond.Children.Add(ThenScope); if (!CopyCatchVar(TryComm, ThenScope, Type, Name, CommandCode)) { return(null); } return(ThenScope); } }