상속: CodeStatement
 public TypescriptLabeledStatement(
     IStatementFactory statementFactory,
     IExpressionFactory expressionFactory,
     CodeLabeledStatement statement,
     CodeGeneratorOptions options)
 {
     _statementFactory = statementFactory;
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
 }
 public static CodeLabeledStatement Clone(this CodeLabeledStatement statement)
 {
     if (statement == null) return null;
     CodeLabeledStatement s = new CodeLabeledStatement();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.Label = statement.Label;
     s.LinePragma = statement.LinePragma;
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.Statement = statement.Statement.Clone();
     s.UserData.AddRange(statement.UserData);
     return s;
 }
예제 #3
0
        private void EmitLabeledStatement(CodeLabeledStatement Labeled)
        {
            Depth++;
            Debug("Marking label: " + Labeled.Label);

            LabelMetadata Meta = LookupLabel(Labeled.Label);

            if (Meta.Resolved)
                throw new CompileException(Labeled, "Can not mark the label " + Meta.Name + " twice");

            Generator.MarkLabel(Meta.Label);
            EmitStatement(Labeled.Statement);

            Meta.Resolved = true;
            Meta.Bound = Labeled.Statement;

            Depth--;
        }
예제 #4
0
		public void Constructor0 ()
		{
			CodeLabeledStatement cls = new CodeLabeledStatement ();
			Assert.IsNull (cls.LinePragma, "#1");

			Assert.IsNotNull (cls.Label, "#2");
			Assert.AreEqual (string.Empty, cls.Label, "#3");

#if NET_2_0
			Assert.IsNotNull (cls.StartDirectives, "#4");
			Assert.AreEqual (0, cls.StartDirectives.Count, "#5");

			Assert.IsNotNull (cls.EndDirectives, "#6");
			Assert.AreEqual (0, cls.EndDirectives.Count, "#7");
#endif

			Assert.IsNotNull (cls.UserData, "#8");
			Assert.AreEqual (typeof(ListDictionary), cls.UserData.GetType (), "#9");
			Assert.AreEqual (0, cls.UserData.Count, "#10");
			
			string label = "mono";
			cls.Label = label;
			Assert.IsNotNull (cls.Label, "#11");
			Assert.AreSame (label, cls.Label, "#12");

			cls.Label = null;
			Assert.IsNotNull (cls.Label, "#13");
			Assert.AreEqual (string.Empty, cls.Label, "#14");

			CodeLinePragma clp = new CodeLinePragma ("mono", 10);
			cls.LinePragma = clp;
			Assert.IsNotNull (cls.LinePragma, "#15");
			Assert.AreSame (clp, cls.LinePragma, "#16");

			cls.LinePragma = null;
			Assert.IsNull (cls.LinePragma, "#17");

			Assert.IsNull (cls.Statement, "#18");

			CodeStatement stmt = new CodeStatement ();
			cls.Statement = stmt;
			Assert.IsNotNull (cls.Statement, "#19");
			Assert.AreSame (stmt, cls.Statement);
		}
예제 #5
0
파일: Flow.cs 프로젝트: lnsoso/IronAHK
 void EmitLabel(CodeLabeledStatement label)
 {
     writer.Write(label.Label);
     writer.Write(Parser.HotkeyBound);
 }
 public bool ValidateCodeLabeledStatement (CodeLabeledStatement exp) {
     PushError ("CodeLabeledStatement is not allowed.");
     return false;
 }
        public override object VisitLabelStatement(LabelStatement labelStatement, object data)
        {
            System.CodeDom.CodeLabeledStatement labelStmt = new CodeLabeledStatement(labelStatement.Label);

            // Add Statement to Current Statement Collection
            AddStmt(labelStmt);

            return labelStmt;
        }
예제 #8
0
        public Func<int> Compile(bool bigint = false, bool binary = false)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            CodeNamespace ns = new CodeNamespace("Aheui");
            ns.Imports.Add(new CodeNamespaceImport("System"));
            ns.Imports.Add(new CodeNamespaceImport("System.Numerics"));
            ns.Imports.Add(new CodeNamespaceImport("CShAheui.Core"));
            unit.Namespaces.Add(ns);

            CodeTypeDeclaration aheui = new CodeTypeDeclaration("AheuiExecutor");
            Type baseType = bigint ? typeof(BigIntAheuiBase) : typeof(IntAheuiBase);
            aheui.BaseTypes.Add(baseType);

            CodeMemberMethod execute = new CodeMemberMethod();
            execute.ReturnType = new CodeTypeReference(typeof(int));
            execute.Name = "ExecuteInternal";
            execute.Attributes = MemberAttributes.Family | MemberAttributes.Override;

            CodeStatementCollection collection = new CodeStatementCollection();
            for (int i = 0; i < Instructions.Count; i++)
            {
                var instr = Instructions[i];
                CodeLabeledStatement label = null;
                if (instr.IsReferenced)
                {
                    label = new CodeLabeledStatement($"lineno_{i}");
                }
                if (instr.Command == 'J')
                {
                    collection.Add(new CodeGotoStatement($"lineno_{instr.Argument}"));
                }
                else if (instr.Command == 'ㅎ')
                {
                    CodeFieldReferenceExpression storage = new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), "storage");
                    CodeMethodInvokeExpression pop = new CodeMethodInvokeExpression(storage, "MakeReturnValue");
                    collection.Add(new CodeMethodReturnStatement(pop));
                }
                else if (instr.Command != 'ㅇ')
                {
                    CodeMethodInvokeExpression inv = new CodeMethodInvokeExpression(
                        new CodeThisReferenceExpression(), "Step",
                        new CodePrimitiveExpression(instr.Command), new CodePrimitiveExpression(instr.Argument));
                    if (instr.ReverseJumpTo != -1)
                    {
                        CodeConditionStatement reverse = new CodeConditionStatement(
                            inv, new CodeGotoStatement($"lineno_{instr.ReverseJumpTo}"));
                        collection.Add(reverse);
                    }
                    else
                    {
                        collection.Add(new CodeExpressionStatement(inv));
                    }
                }
                if (label != null)
                {
                    if (collection.Count > 0) label.Statement = collection[0];
                    else collection.Add(label);
                    collection[0] = label;
                }
                execute.Statements.AddRange(collection);
                collection.Clear();
            }
            aheui.Members.Add(execute);
            ns.Types.Add(aheui);

            var provider = new CSharpCodeProvider();
            CompilerParameters cp = new CompilerParameters();
            if (binary)
            {
                CodeEntryPointMethod entry = new CodeEntryPointMethod();
                var returnStmt = new CodeMethodReturnStatement(new CodeMethodInvokeExpression(
                    new CodeObjectCreateExpression("Aheui.AheuiExecutor"), "Execute"));
                entry.Statements.Add(returnStmt);
                entry.ReturnType = new CodeTypeReference(typeof(int));
                aheui.Members.Add(entry);
                cp.OutputAssembly = "out.exe";
            }
            cp.GenerateExecutable = binary;
            cp.GenerateInMemory = !binary;
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Numerics.dll");
            cp.ReferencedAssemblies.Add("CShAheui.Core.dll");
            cp.CompilerOptions = "/optimize";
            #if DEBUG
            cp.TempFiles = new TempFileCollection(".", true);
            #endif

            var cpass = provider.CompileAssemblyFromDom(cp, unit);
            if (!binary)
            {
                var assembly = cpass?.CompiledAssembly;
                object aheuiExecutor = assembly.CreateInstance("Aheui.AheuiExecutor");
                var realExecute = aheuiExecutor.GetType().GetMethod("Execute");

                return () => (int)realExecute.Invoke(aheuiExecutor, null);
            }
            else return null;
        }
예제 #9
0
		protected abstract void GenerateLabeledStatement (CodeLabeledStatement statement);
예제 #10
0
		protected override void GenerateLabeledStatement (CodeLabeledStatement e)
		{
		}
예제 #11
0
 protected override void GenerateLabeledStatement(System.CodeDom.CodeLabeledStatement e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 private  void GenerateLabeledStatement(CodeLabeledStatement e) {
     Indent--;
     Output.Write(e.Label);
     Output.WriteLine(":");
     Indent++;
     if (e.Statement != null) {
         GenerateStatement(e.Statement);
     }
 }
예제 #13
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement e)
 {
     throw new NotImplementedException("The method or operation is not implemented.");
 }
예제 #14
0
 private void Write(CodeLabeledStatement e){
   TextWriter w = this.writer;
   w.Write(e.Label);
   w.Write(':');
   if (e.Statement != null){
     w.WriteLine();
     this.level++;
     this.WriteIndent();
     this.level--;
     this.Write(e.Statement);
   }else
     w.WriteLine(';');
 }
예제 #15
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement statement)
 {
     throw new NotSupportedException();
 }
예제 #16
0
        protected virtual CodeLabeledStatement Rewrite(CodeLabeledStatement source, ref bool didRewrite)
        {
            if (source == null)
            {
                return source;
            }

            bool didChildRewrite = false;
            CodeLabeledStatement result = new CodeLabeledStatement();
            result.Label = source.Label;
            result.Statement = this.Rewrite(source.Statement, ref didChildRewrite);
            result.LinePragma = this.Rewrite(source.LinePragma, ref didChildRewrite);
            this.Rewrite(result.StartDirectives, source.StartDirectives, ref didChildRewrite);
            this.Rewrite(result.EndDirectives, source.EndDirectives, ref didChildRewrite);
            this.Rewrite(result.UserData, source.UserData, ref didChildRewrite);
            if (didChildRewrite)
            {
                didRewrite = true;
                return result;
            }
            else
            {
                return source;
            }
        }
예제 #17
0
 private Statement Translate(CodeLabeledStatement statement){
   if (statement == null) return null;
   LabeledStatement ls = new LabeledStatement();
   ls.Label = Identifier.For(statement.Label);
   ls.Statement = this.Translate(statement.Statement);
   return ls;
 }
예제 #18
0
		protected override void GenerateLabeledStatement (CodeLabeledStatement statement)
		{
			Indent--;
			Output.Write (statement.Label);
			Output.WriteLine (":");
			Indent++;

			if (statement.Statement != null) {
				GenerateStatement (statement.Statement);
			}
		}
 public void Generate(CodeLabeledStatement statement)
 {
     throw new NotImplementedException();
 }
예제 #20
0
 private void ValidateLabeledStatement(CodeLabeledStatement e) {
     ValidateIdentifier(e,"Label",e.Label);
     if (e.Statement != null) {
         ValidateStatement(e.Statement);
     }
 }
 protected override void GenerateLabeledStatement(CodeLabeledStatement e) {
   throw new Exception(JScriptException.Localize("No goto statements", CultureInfo.CurrentUICulture));
 }
예제 #22
0
			public void Visit (CodeLabeledStatement o)
			{
				g.GenerateLabeledStatement (o);
			}
		protected override void GenerateLabeledStatement(CodeLabeledStatement e)
		{
			Output.WriteLine("[CodeLabeledStatement: {0}]", e.ToString());
		}
예제 #24
0
		protected override void GenerateLabeledStatement (CodeLabeledStatement statement)
		{
			TextWriter output = Output;

			Indent--;
			output.WriteLine (statement.Label + ":");
			Indent++;
			if (statement.Statement != null) {
				GenerateStatement (statement.Statement);
			}
		}
예제 #25
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement e)
 {
     Indent--;
     Output.Write(e.Label);
     Output.WriteLine(':');
     Indent++;
     if (e.Statement != null)
     {
         GenerateStatement(e.Statement);
     }
 }
예제 #26
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement e)
 {
     base.Indent--;
     base.Output.Write(e.Label);
     base.Output.WriteLine(":");
     base.Indent++;
     if (e.Statement != null)
     {
         base.GenerateStatement(e.Statement);
     }
 }
예제 #27
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement e)
 {
     // Currently, nothing here
 }
예제 #28
0
        /// <summary>
        /// Generates code for the specified labeled statement.
        /// </summary>
        /// <remarks><c>LABEL: STATEMENT</c> or <c>LABEL:</c> if <param name="e"/>.<see cref="CodeLabeledStatement.Statement">Statement</see> is  null</remarks>
        protected override void GenerateLabeledStatement(CodeLabeledStatement e)
        {
            if (Indent > 0)
            {
                Indent--;
                Output.Write(e.Label);
                Output.WriteLine(Tokens.Colon);
                Indent++;
            }
            else
            {
                Output.Write(e.Label);
                Output.WriteLine(Tokens.Colon);
            }

            if (e.Statement != null) GenerateStatement(e.Statement);
        }
예제 #29
0
 protected override void GenerateLabeledStatement(CodeLabeledStatement statement)
 {
     throw new NotSupportedException ("Labeled statement is not supported in JScript.");
 }
        public override object Visit(LabelStatement labelStatement, object data)
        {
            ProcessSpecials(labelStatement.Specials);

            System.CodeDom.CodeLabeledStatement labelStmt = new CodeLabeledStatement(labelStatement.Label,(CodeStatement)labelStatement.AcceptVisitor(this, data));

            // Add Statement to Current Statement Collection
            AddStmt(labelStmt);

            return labelStmt;
        }
예제 #31
0
		public void CodeLabeledStatementTest ()
		{
			CodeLabeledStatement cls = new CodeLabeledStatement ();
			statement = cls;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				":{0}", NewLine), Generate (), "#1");

			cls.Label = "class";
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"class:{0}", NewLine), Generate (), "#2");

			cls.Statement = new CodeSnippetStatement ("A");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"class:{0}" +
#if NET_2_0
				"A{0}",
#else
				"    A{0}",
#endif
				NewLine), Generate (), "#3");
		}