コード例 #1
0
ファイル: PrettyPrinter.cpp プロジェクト: 18768108070/pyv8
void PrettyPrinter::PrintFunctionLiteral(FunctionLiteral* function) {
  Print("function ");
  PrintLiteral(function->name(), false);
  PrintParameters(function->scope());
  Print(" { ");
  PrintDeclarations(function->scope()->declarations());
  PrintStatements(function->body());
  Print(" }");
}
コード例 #2
0
ファイル: debugger.cpp プロジェクト: 8l/objeck-lang
void Runtime::Debugger::ProcessInfo(Info* info) {
  const wstring &cls_name = info->GetClassName();
  const wstring &mthd_name = info->GetMethodName();

#ifdef _DEBUG
  wcout << L"--- info class=" << cls_name << L", method=" << mthd_name << L" ---" << endl;
#endif

  if(interpreter) {
    // method info
    if(cls_name.size() > 0 && mthd_name.size() > 0) {
      StackClass* klass = cur_program->GetClass(cls_name);
      if(klass && klass->IsDebug()) {
        vector<StackMethod*> methods = klass->GetMethods(mthd_name);
        if(methods.size() > 0) {
          for(size_t i = 0; i < methods.size(); i++) {
            StackMethod* method = methods[i];
            wcout << L"  class: type=" << klass->GetName() << L", method="
									<< PrintMethod(method) << endl;
						if(method->GetNumberDeclarations() > 0) {
							wcout << L"  parameters:" << endl;
							PrintDeclarations(method->GetDeclarations(), method->GetNumberDeclarations());
						}
          }
        }
        else {
          wcout << L"unable to find method." << endl;
          is_error = true;
        }
      }
      else {
        wcout << L"unable to find class." << endl;
        is_error = true;
      }
    }
    // class info
    else if(cls_name.size() > 0) {
      StackClass* klass = cur_program->GetClass(cls_name);
      if(klass && klass->IsDebug()) {
        wcout << L"  class: type=" << klass->GetName() << endl;
        // print
        wcout << L"  parameters:" << endl;
				if(klass->GetNumberInstanceDeclarations() > 0) {
					PrintDeclarations(klass->GetInstanceDeclarations(), klass->GetNumberInstanceDeclarations());
				}
      }
      else {
        wcout << L"unable to find class." << endl;
        is_error = true;
      }
    }
    // general info
    else {
      wcout << L"general info:" << endl;
      wcout << L"  program executable: file='" << program_file << L"'" << endl;

      // parse method and class names
      const wstring &long_name = cur_frame->method->GetName();
      int end_index = long_name.find_last_of(':');
      const wstring &cls_mthd_name = long_name.substr(0, end_index);

      int mid_index = cls_mthd_name.find_last_of(':');
      const wstring &cls_name = cls_mthd_name.substr(0, mid_index);
      const wstring &mthd_name = cls_mthd_name.substr(mid_index + 1);

      // print
      wcout << L"  current file='" << cur_file_name << L":" << cur_line_num << L"', method='"
						<< cls_name << L"->" << mthd_name << L"(..)'" << endl;
    }
  }
  else {
    wcout << L"program is not running." << endl;
  }
}