public VariableDescription(ATriggerDecl triggerDecl) { Name = triggerDecl.GetName().Text; Type = "trigger"; PlacementPrefix = "Field"; VariableType = VariableTypes.Field; Const = false; IsStatic = false; realType = new ANamedType(new TIdentifier("trigger"), null); Visibility = (PVisibilityModifier)triggerDecl.GetVisibilityModifier().Clone(); Line = triggerDecl.GetName().Line; Position = TextPoint.FromCompilerCoords(triggerDecl.GetActionsToken()); }
/*public override void OutAIncludeDecl(AIncludeDecl node) * { * string name = Util.GetString(node.GetName()); * SourceFileContents sourceFile = compiler.LookupFile(name); * if (sourceFile != null) * { * Includes.Add(sourceFile); * } * }*/ public override void OutATriggerDecl(ATriggerDecl node) { //Add field Fields.Add(new VariableDescription(node)); //Add event method //The methods don't start from node.GetName(), make the parser add the events, conditions and action tokens if (node.GetEvents() != null) { Methods.Add( new MethodDescription(TextPoint.FromCompilerCoords(node.GetEventToken().Line, node.GetEventToken().Pos), new AVoidType(new TVoid("void")), (AABlock)node.GetEvents(), null)); } if (node.GetConditions() != null) { Methods.Add( new MethodDescription(TextPoint.FromCompilerCoords(node.GetConditionsToken().Line, node.GetConditionsToken().Pos), new AVoidType(new TVoid("void")), (AABlock)node.GetConditions(), null)); } //Actions. this one can be called { AMethodDecl method = new AMethodDecl((PVisibilityModifier)node.GetVisibilityModifier().Clone(), null, null, null, null, null, new ANamedType(new TIdentifier("bool"), null), new TIdentifier(node.GetName().Text, node.GetActionsToken().Line, node.GetActionsToken().Pos), new ArrayList() { new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType( new TIdentifier("bool"), null), new TIdentifier("testConds"), null), new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new ANamedType( new TIdentifier("bool"), null), new TIdentifier("runActions"), null) }, node.GetActions()); Methods.Add(new MethodDescription(method)); } }
public override void OutATriggerDecl(ATriggerDecl node) { data.Triggers.Add(node); }
public override void OutATriggerDecl(ATriggerDecl node) { //If no actions, insert it if (node.GetActions() == null) { node.SetActions(new AABlock(new ArrayList(), new TRBrace("}", -1, -1))); node.SetActionsToken(new TActions("actions", -1, -1)); } //If return in events is missing, insert it. if (node.GetEvents() != null) { AABlock block = (AABlock)node.GetEvents(); bool insertReturn = false; while (true) { if (block.GetStatements().Count == 0) { insertReturn = true; break; } PStm lastStm = (PStm)block.GetStatements()[block.GetStatements().Count - 1]; if (lastStm is AVoidReturnStm) { break; } if (lastStm is ABlockStm) { block = (AABlock)((ABlockStm)block.GetStatements()[block.GetStatements().Count - 1]).GetBlock(); continue; } insertReturn = true; break; } if (insertReturn) { block.GetStatements().Add(new AVoidReturnStm(new TReturn("return", block.GetToken().Line, block.GetToken().Pos))); } } //Also for actions //if (node.GetActions() != null) { AABlock block = (AABlock)node.GetActions(); bool insertReturn = false; while (true) { if (block.GetStatements().Count == 0) { insertReturn = true; break; } PStm lastStm = (PStm)block.GetStatements()[block.GetStatements().Count - 1]; if (lastStm is AVoidReturnStm) { break; } if (lastStm is ABlockStm) { block = (AABlock)((ABlockStm)block.GetStatements()[block.GetStatements().Count - 1]).GetBlock(); continue; } insertReturn = true; break; } if (insertReturn) { block.GetStatements().Add(new AVoidReturnStm(new TReturn("return", block.GetToken().Line, block.GetToken().Pos))); } } }