| 1 | //
|
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
|
|---|
| 3 | //
|
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
|---|
| 5 | // file "LICENCE" distributed with Cforall.
|
|---|
| 6 | //
|
|---|
| 7 | // Convert.cpp -- Convert between the new and old syntax trees.
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Thierry Delisle
|
|---|
| 10 | // Created On : Thu May 09 15::37::05 2019
|
|---|
| 11 | // Last Modified By : Andrew Beach
|
|---|
| 12 | // Last Modified On : Fri May 17 12:13:00 2019
|
|---|
| 13 | // Update Count : 3
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include "Convert.hpp"
|
|---|
| 17 |
|
|---|
| 18 | #include "AST/Attribute.hpp"
|
|---|
| 19 | #include "AST/Decl.hpp"
|
|---|
| 20 | #include "AST/Expr.hpp"
|
|---|
| 21 | #include "AST/Init.hpp"
|
|---|
| 22 | #include "AST/Stmt.hpp"
|
|---|
| 23 | #include "AST/TypeSubstitution.hpp"
|
|---|
| 24 |
|
|---|
| 25 | #include "SynTree/Attribute.h"
|
|---|
| 26 | #include "SynTree/Declaration.h"
|
|---|
| 27 | #include "SynTree/TypeSubstitution.h"
|
|---|
| 28 |
|
|---|
| 29 | //================================================================================================
|
|---|
| 30 | // Utilities
|
|---|
| 31 | template<template <class...> class C>
|
|---|
| 32 | struct to {
|
|---|
| 33 | template<typename T>
|
|---|
| 34 | static auto from( T && v ) -> C< typename T::value_type > {
|
|---|
| 35 | C< typename T::value_type > l;
|
|---|
| 36 | std::move(std::begin(v), std::end(v), std::back_inserter(l));
|
|---|
| 37 | return l;
|
|---|
| 38 | }
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | //================================================================================================
|
|---|
| 42 | class ConverterNewToOld : public ast::Visitor {
|
|---|
| 43 | public:
|
|---|
| 44 | template<typename T>
|
|---|
| 45 | T * get() {
|
|---|
| 46 | T * ret = strict_dynamic_cast< T * >( node );
|
|---|
| 47 | node = nullptr;
|
|---|
| 48 | return ret;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | private:
|
|---|
| 52 | BaseSyntaxNode * node = nullptr;
|
|---|
| 53 |
|
|---|
| 54 | // All the visit functions:
|
|---|
| 55 |
|
|---|
| 56 | const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
|
|---|
| 57 | (void)node;
|
|---|
| 58 | return nullptr;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
|
|---|
| 62 | (void)node;
|
|---|
| 63 | return nullptr;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | const ast::Decl * visit( const ast::StructDecl * node ) override final {
|
|---|
| 67 | (void)node;
|
|---|
| 68 | return nullptr;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | const ast::Decl * visit( const ast::UnionDecl * node ) override final {
|
|---|
| 72 | (void)node;
|
|---|
| 73 | return nullptr;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | const ast::Decl * visit( const ast::EnumDecl * node ) override final {
|
|---|
| 77 | (void)node;
|
|---|
| 78 | return nullptr;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | const ast::Decl * visit( const ast::TraitDecl * node ) override final {
|
|---|
| 82 | (void)node;
|
|---|
| 83 | return nullptr;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | const ast::Decl * visit( const ast::TypeDecl * node ) override final {
|
|---|
| 87 | (void)node;
|
|---|
| 88 | return nullptr;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
|
|---|
| 92 | (void)node;
|
|---|
| 93 | return nullptr;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
|
|---|
| 97 | (void)node;
|
|---|
| 98 | return nullptr;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
|
|---|
| 102 | (void)node;
|
|---|
| 103 | return nullptr;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
|
|---|
| 107 | (void)node;
|
|---|
| 108 | return nullptr;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
|
|---|
| 112 | (void)node;
|
|---|
| 113 | return nullptr;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
|
|---|
| 117 | (void)node;
|
|---|
| 118 | return nullptr;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
|
|---|
| 122 | (void)node;
|
|---|
| 123 | return nullptr;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | const ast::Stmt * visit( const ast::IfStmt * node ) override final {
|
|---|
| 127 | (void)node;
|
|---|
| 128 | return nullptr;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
|
|---|
| 132 | (void)node;
|
|---|
| 133 | return nullptr;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | const ast::Stmt * visit( const ast::ForStmt * node ) override final {
|
|---|
| 137 | (void)node;
|
|---|
| 138 | return nullptr;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
|
|---|
| 142 | (void)node;
|
|---|
| 143 | return nullptr;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
|
|---|
| 147 | (void)node;
|
|---|
| 148 | return nullptr;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
|
|---|
| 152 | (void)node;
|
|---|
| 153 | return nullptr;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
|
|---|
| 157 | (void)node;
|
|---|
| 158 | return nullptr;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
|
|---|
| 162 | (void)node;
|
|---|
| 163 | return nullptr;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | const ast::Stmt * visit( const ast::TryStmt * node ) override final {
|
|---|
| 167 | (void)node;
|
|---|
| 168 | return nullptr;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
|
|---|
| 172 | (void)node;
|
|---|
| 173 | return nullptr;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
|
|---|
| 177 | (void)node;
|
|---|
| 178 | return nullptr;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
|
|---|
| 182 | (void)node;
|
|---|
| 183 | return nullptr;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | const ast::Stmt * visit( const ast::WithStmt * node ) override final {
|
|---|
| 187 | (void)node;
|
|---|
| 188 | return nullptr;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
|
|---|
| 192 | (void)node;
|
|---|
| 193 | return nullptr;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
|
|---|
| 197 | (void)node;
|
|---|
| 198 | return nullptr;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
|
|---|
| 202 | (void)node;
|
|---|
| 203 | return nullptr;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
|
|---|
| 207 | (void)node;
|
|---|
| 208 | return nullptr;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
|
|---|
| 212 | (void)node;
|
|---|
| 213 | return nullptr;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | const ast::Expr * visit( const ast::NameExpr * node ) override final {
|
|---|
| 217 | (void)node;
|
|---|
| 218 | return nullptr;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | const ast::Expr * visit( const ast::AddressExpr * node ) override final {
|
|---|
| 222 | (void)node;
|
|---|
| 223 | return nullptr;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
|
|---|
| 227 | (void)node;
|
|---|
| 228 | return nullptr;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | const ast::Expr * visit( const ast::CastExpr * node ) override final {
|
|---|
| 232 | (void)node;
|
|---|
| 233 | return nullptr;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
|
|---|
| 237 | (void)node;
|
|---|
| 238 | return nullptr;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
|
|---|
| 242 | (void)node;
|
|---|
| 243 | return nullptr;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
|
|---|
| 247 | (void)node;
|
|---|
| 248 | return nullptr;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | const ast::Expr * visit( const ast::MemberExpr * node ) override final {
|
|---|
| 252 | (void)node;
|
|---|
| 253 | return nullptr;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | const ast::Expr * visit( const ast::VariableExpr * node ) override final {
|
|---|
| 257 | (void)node;
|
|---|
| 258 | return nullptr;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
|
|---|
| 262 | (void)node;
|
|---|
| 263 | return nullptr;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
|
|---|
| 267 | (void)node;
|
|---|
| 268 | return nullptr;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
|
|---|
| 272 | (void)node;
|
|---|
| 273 | return nullptr;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
|
|---|
| 277 | (void)node;
|
|---|
| 278 | return nullptr;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
|
|---|
| 282 | (void)node;
|
|---|
| 283 | return nullptr;
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
|
|---|
| 287 | (void)node;
|
|---|
| 288 | return nullptr;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
|
|---|
| 292 | (void)node;
|
|---|
| 293 | return nullptr;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
|
|---|
| 297 | (void)node;
|
|---|
| 298 | return nullptr;
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | const ast::Expr * visit( const ast::CommaExpr * node ) override final {
|
|---|
| 302 | (void)node;
|
|---|
| 303 | return nullptr;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | const ast::Expr * visit( const ast::TypeExpr * node ) override final {
|
|---|
| 307 | (void)node;
|
|---|
| 308 | return nullptr;
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | const ast::Expr * visit( const ast::AsmExpr * node ) override final {
|
|---|
| 312 | (void)node;
|
|---|
| 313 | return nullptr;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
|
|---|
| 317 | (void)node;
|
|---|
| 318 | return nullptr;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
|
|---|
| 322 | (void)node;
|
|---|
| 323 | return nullptr;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
|
|---|
| 327 | (void)node;
|
|---|
| 328 | return nullptr;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | const ast::Expr * visit( const ast::RangeExpr * node ) override final {
|
|---|
| 332 | (void)node;
|
|---|
| 333 | return nullptr;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
|
|---|
| 337 | (void)node;
|
|---|
| 338 | return nullptr;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | const ast::Expr * visit( const ast::TupleExpr * node ) override final {
|
|---|
| 342 | (void)node;
|
|---|
| 343 | return nullptr;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
|
|---|
| 347 | (void)node;
|
|---|
| 348 | return nullptr;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
|
|---|
| 352 | (void)node;
|
|---|
| 353 | return nullptr;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | const ast::Expr * visit( const ast::StmtExpr * node ) override final {
|
|---|
| 357 | (void)node;
|
|---|
| 358 | return nullptr;
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
|
|---|
| 362 | (void)node;
|
|---|
| 363 | return nullptr;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
|
|---|
| 367 | (void)node;
|
|---|
| 368 | return nullptr;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | const ast::Expr * visit( const ast::InitExpr * node ) override final {
|
|---|
| 372 | (void)node;
|
|---|
| 373 | return nullptr;
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
|
|---|
| 377 | (void)node;
|
|---|
| 378 | return nullptr;
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
|
|---|
| 382 | (void)node;
|
|---|
| 383 | return nullptr;
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | const ast::Expr * visit( const ast::GenericExpr * node ) override final {
|
|---|
| 387 | (void)node;
|
|---|
| 388 | return nullptr;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | const ast::Type * visit( const ast::VoidType * node ) override final {
|
|---|
| 392 | (void)node;
|
|---|
| 393 | return nullptr;
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | const ast::Type * visit( const ast::BasicType * node ) override final {
|
|---|
| 397 | (void)node;
|
|---|
| 398 | return nullptr;
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | const ast::Type * visit( const ast::PointerType * node ) override final {
|
|---|
| 402 | (void)node;
|
|---|
| 403 | return nullptr;
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | const ast::Type * visit( const ast::ArrayType * node ) override final {
|
|---|
| 407 | (void)node;
|
|---|
| 408 | return nullptr;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | const ast::Type * visit( const ast::ReferenceType * node ) override final {
|
|---|
| 412 | (void)node;
|
|---|
| 413 | return nullptr;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | const ast::Type * visit( const ast::QualifiedType * node ) override final {
|
|---|
| 417 | (void)node;
|
|---|
| 418 | return nullptr;
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | const ast::Type * visit( const ast::FunctionType * node ) override final {
|
|---|
| 422 | (void)node;
|
|---|
| 423 | return nullptr;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | const ast::Type * visit( const ast::StructInstType * node ) override final {
|
|---|
| 427 | (void)node;
|
|---|
| 428 | return nullptr;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | const ast::Type * visit( const ast::UnionInstType * node ) override final {
|
|---|
| 432 | (void)node;
|
|---|
| 433 | return nullptr;
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | const ast::Type * visit( const ast::EnumInstType * node ) override final {
|
|---|
| 437 | (void)node;
|
|---|
| 438 | return nullptr;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | const ast::Type * visit( const ast::TraitInstType * node ) override final {
|
|---|
| 442 | (void)node;
|
|---|
| 443 | return nullptr;
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | const ast::Type * visit( const ast::TypeInstType * node ) override final {
|
|---|
| 447 | (void)node;
|
|---|
| 448 | return nullptr;
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | const ast::Type * visit( const ast::TupleType * node ) override final {
|
|---|
| 452 | (void)node;
|
|---|
| 453 | return nullptr;
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | const ast::Type * visit( const ast::TypeofType * node ) override final {
|
|---|
| 457 | (void)node;
|
|---|
| 458 | return nullptr;
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | const ast::Type * visit( const ast::VarArgsType * node ) override final {
|
|---|
| 462 | (void)node;
|
|---|
| 463 | return nullptr;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | const ast::Type * visit( const ast::ZeroType * node ) override final {
|
|---|
| 467 | (void)node;
|
|---|
| 468 | return nullptr;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | const ast::Type * visit( const ast::OneType * node ) override final {
|
|---|
| 472 | (void)node;
|
|---|
| 473 | return nullptr;
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
|
|---|
| 477 | (void)node;
|
|---|
| 478 | return nullptr;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | const ast::Designation * visit( const ast::Designation * node ) override final {
|
|---|
| 482 | (void)node;
|
|---|
| 483 | return nullptr;
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | const ast::Init * visit( const ast::SingleInit * node ) override final {
|
|---|
| 487 | (void)node;
|
|---|
| 488 | return nullptr;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | const ast::Init * visit( const ast::ListInit * node ) override final {
|
|---|
| 492 | (void)node;
|
|---|
| 493 | return nullptr;
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | const ast::Init * visit( const ast::ConstructorInit * node ) override final {
|
|---|
| 497 | (void)node;
|
|---|
| 498 | return nullptr;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | const ast::Attribute * visit( const ast::Attribute * node ) override final {
|
|---|
| 502 | (void)node;
|
|---|
| 503 | return nullptr;
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
|
|---|
| 507 | (void)node;
|
|---|
| 508 | return nullptr;
|
|---|
| 509 | }
|
|---|
| 510 | };
|
|---|
| 511 |
|
|---|
| 512 | std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) {
|
|---|
| 513 | ConverterNewToOld c;
|
|---|
| 514 | std::list< Declaration * > decls;
|
|---|
| 515 | for(auto d : translationUnit) {
|
|---|
| 516 | d->accept( c );
|
|---|
| 517 | decls.emplace_back( c.get<Declaration>() );
|
|---|
| 518 | delete d;
|
|---|
| 519 | }
|
|---|
| 520 | return decls;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | //================================================================================================
|
|---|
| 524 |
|
|---|
| 525 | class ConverterOldToNew : public Visitor {
|
|---|
| 526 | public:
|
|---|
| 527 | ast::Decl * decl() {
|
|---|
| 528 | return strict_dynamic_cast< ast::Decl * >( node );
|
|---|
| 529 | }
|
|---|
| 530 | private:
|
|---|
| 531 | ast::Node * node;
|
|---|
| 532 |
|
|---|
| 533 | // Local Utilities:
|
|---|
| 534 |
|
|---|
| 535 | template<typename NewT, typename OldT>
|
|---|
| 536 | NewT * getAccept1( OldT old ) {
|
|---|
| 537 | old->accept(*this);
|
|---|
| 538 | return strict_dynamic_cast< NewT * >( node );
|
|---|
| 539 | }
|
|---|
| 540 |
|
|---|
| 541 | # define GET_ACCEPT_1(child, type) \
|
|---|
| 542 | getAccept1< ast::type, decltype( old->child ) >( old->child )
|
|---|
| 543 |
|
|---|
| 544 | template<typename NewT, typename OldC>
|
|---|
| 545 | std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) {
|
|---|
| 546 | std::vector< ast::ptr<NewT> > ret;
|
|---|
| 547 | ret.reserve( old.size() );
|
|---|
| 548 | for ( auto a : old ) {
|
|---|
| 549 | a->accept( *this );
|
|---|
| 550 | ret.emplace_back( strict_dynamic_cast< NewT * >(node) );
|
|---|
| 551 | }
|
|---|
| 552 | return ret;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | # define GET_ACCEPT_V(child, type) \
|
|---|
| 556 | getAcceptV< ast::type, decltype( old->child ) >( old->child )
|
|---|
| 557 |
|
|---|
| 558 | ast::Label make_label(Label* old) {
|
|---|
| 559 | return ast::Label(
|
|---|
| 560 | old->labelled->location,
|
|---|
| 561 | old->name,
|
|---|
| 562 | GET_ACCEPT_V(attributes, Attribute)
|
|---|
| 563 | );
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | template<template <class...> class C>
|
|---|
| 567 | C<ast::Label> make_labels(C<Label> olds) {
|
|---|
| 568 | C<ast::Label> ret;
|
|---|
| 569 | for (auto oldn : olds) {
|
|---|
| 570 | ret.push_back( make_label( &oldn ) );
|
|---|
| 571 | }
|
|---|
| 572 | return ret;
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | # define GET_LABELS_V(labels) \
|
|---|
| 576 | to<std::vector>::from( make_labels( std::move( labels ) ) )
|
|---|
| 577 |
|
|---|
| 578 | // Now all the visit functions:
|
|---|
| 579 |
|
|---|
| 580 | virtual void visit( ObjectDecl * old ) override final {
|
|---|
| 581 | auto decl = new ast::ObjectDecl(
|
|---|
| 582 | old->location,
|
|---|
| 583 | old->name,
|
|---|
| 584 | GET_ACCEPT_1(type, Type),
|
|---|
| 585 | GET_ACCEPT_1(init, Init),
|
|---|
| 586 | { old->get_storageClasses().val },
|
|---|
| 587 | { old->linkage.val },
|
|---|
| 588 | GET_ACCEPT_1(bitfieldWidth, Expr),
|
|---|
| 589 | GET_ACCEPT_V(attributes, Attribute),
|
|---|
| 590 | { old->get_funcSpec().val }
|
|---|
| 591 | );
|
|---|
| 592 | decl->scopeLevel = old->scopeLevel;
|
|---|
| 593 | decl->mangleName = old->mangleName;
|
|---|
| 594 | decl->isDeleted = old->isDeleted;
|
|---|
| 595 | decl->uniqueId = old->uniqueId;
|
|---|
| 596 | decl->extension = old->extension;
|
|---|
| 597 |
|
|---|
| 598 | this->node = decl;
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | virtual void visit( FunctionDecl * ) override final {
|
|---|
| 602 |
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | virtual void visit( StructDecl * old ) override final {
|
|---|
| 606 | auto decl = new ast::StructDecl(
|
|---|
| 607 | old->location,
|
|---|
| 608 | old->name,
|
|---|
| 609 | old->kind,
|
|---|
| 610 | GET_ACCEPT_V(attributes, Attribute),
|
|---|
| 611 | { old->linkage.val }
|
|---|
| 612 | );
|
|---|
| 613 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
|
|---|
| 614 | decl->body = old->body;
|
|---|
| 615 | decl->params = GET_ACCEPT_V(parameters, TypeDecl);
|
|---|
| 616 | decl->members = GET_ACCEPT_V(members, Decl);
|
|---|
| 617 | decl->extension = old->extension;
|
|---|
| 618 | decl->uniqueId = old->uniqueId;
|
|---|
| 619 | decl->storage = { old->storageClasses.val };
|
|---|
| 620 |
|
|---|
| 621 | this->node = decl;
|
|---|
| 622 | }
|
|---|
| 623 |
|
|---|
| 624 | virtual void visit( UnionDecl * old ) override final {
|
|---|
| 625 | auto decl = new ast::UnionDecl(
|
|---|
| 626 | old->location,
|
|---|
| 627 | old->name,
|
|---|
| 628 | GET_ACCEPT_V(attributes, Attribute),
|
|---|
| 629 | { old->linkage.val }
|
|---|
| 630 | );
|
|---|
| 631 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
|
|---|
| 632 | decl->body = old->body;
|
|---|
| 633 | decl->params = GET_ACCEPT_V(parameters, TypeDecl);
|
|---|
| 634 | decl->members = GET_ACCEPT_V(members, Decl);
|
|---|
| 635 | decl->extension = old->extension;
|
|---|
| 636 | decl->uniqueId = old->uniqueId;
|
|---|
| 637 | decl->storage = { old->storageClasses.val };
|
|---|
| 638 |
|
|---|
| 639 | this->node = decl;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | virtual void visit( EnumDecl * old ) override final {
|
|---|
| 643 | auto decl = new ast::UnionDecl(
|
|---|
| 644 | old->location,
|
|---|
| 645 | old->name,
|
|---|
| 646 | GET_ACCEPT_V(attributes, Attribute),
|
|---|
| 647 | { old->linkage.val }
|
|---|
| 648 | );
|
|---|
| 649 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
|
|---|
| 650 | decl->body = old->body;
|
|---|
| 651 | decl->params = GET_ACCEPT_V(parameters, TypeDecl);
|
|---|
| 652 | decl->members = GET_ACCEPT_V(members, Decl);
|
|---|
| 653 | decl->extension = old->extension;
|
|---|
| 654 | decl->uniqueId = old->uniqueId;
|
|---|
| 655 | decl->storage = { old->storageClasses.val };
|
|---|
| 656 |
|
|---|
| 657 | this->node = decl;
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | virtual void visit( TraitDecl * old ) override final {
|
|---|
| 661 | auto decl = new ast::UnionDecl(
|
|---|
| 662 | old->location,
|
|---|
| 663 | old->name,
|
|---|
| 664 | GET_ACCEPT_V(attributes, Attribute),
|
|---|
| 665 | { old->linkage.val }
|
|---|
| 666 | );
|
|---|
| 667 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
|
|---|
| 668 | decl->body = old->body;
|
|---|
| 669 | decl->params = GET_ACCEPT_V(parameters, TypeDecl);
|
|---|
| 670 | decl->members = GET_ACCEPT_V(members, Decl);
|
|---|
| 671 | decl->extension = old->extension;
|
|---|
| 672 | decl->uniqueId = old->uniqueId;
|
|---|
| 673 | decl->storage = { old->storageClasses.val };
|
|---|
| 674 |
|
|---|
| 675 | this->node = decl;
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | virtual void visit( TypeDecl * ) override final {
|
|---|
| 679 |
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | virtual void visit( TypedefDecl * old ) override final {
|
|---|
| 683 | auto decl = new ast::TypedefDecl(
|
|---|
| 684 | old->location,
|
|---|
| 685 | old->name,
|
|---|
| 686 | { old->storageClasses.val },
|
|---|
| 687 | GET_ACCEPT_1(base, Type),
|
|---|
| 688 | { old->linkage.val }
|
|---|
| 689 | );
|
|---|
| 690 | decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
|
|---|
| 691 | decl->params = GET_ACCEPT_V(parameters, TypeDecl);
|
|---|
| 692 | decl->extension = old->extension;
|
|---|
| 693 | decl->uniqueId = old->uniqueId;
|
|---|
| 694 | decl->storage = { old->storageClasses.val };
|
|---|
| 695 |
|
|---|
| 696 | this->node = decl;
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | virtual void visit( AsmDecl * ) override final {
|
|---|
| 700 |
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | virtual void visit( StaticAssertDecl * ) override final {
|
|---|
| 704 |
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | virtual void visit( CompoundStmt * old ) override final {
|
|---|
| 708 | auto stmt = new ast::CompoundStmt(
|
|---|
| 709 | old->location,
|
|---|
| 710 | to<std::list>::from( GET_ACCEPT_V(kids, Stmt) ),
|
|---|
| 711 | GET_LABELS_V(old->labels)
|
|---|
| 712 | );
|
|---|
| 713 |
|
|---|
| 714 | this->node = stmt;
|
|---|
| 715 | }
|
|---|
| 716 |
|
|---|
| 717 | virtual void visit( ExprStmt * old ) override final {
|
|---|
| 718 | this->node = new ast::ExprStmt(
|
|---|
| 719 | old->location,
|
|---|
| 720 | GET_ACCEPT_1(expr, Expr),
|
|---|
| 721 | GET_LABELS_V(old->labels)
|
|---|
| 722 | );
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | virtual void visit( AsmStmt * old ) override final {
|
|---|
| 726 | this->node = new ast::AsmStmt(
|
|---|
| 727 | old->location,
|
|---|
| 728 | old->voltile,
|
|---|
| 729 | GET_ACCEPT_1(instruction, Expr),
|
|---|
| 730 | GET_ACCEPT_V(output, Expr),
|
|---|
| 731 | GET_ACCEPT_V(input, Expr),
|
|---|
| 732 | GET_ACCEPT_V(clobber, ConstantExpr),
|
|---|
| 733 | GET_LABELS_V(old->gotolabels),
|
|---|
| 734 | GET_LABELS_V(old->labels)
|
|---|
| 735 | );
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | virtual void visit( DirectiveStmt * old ) override final {
|
|---|
| 739 | this->node = new ast::DirectiveStmt(
|
|---|
| 740 | old->location,
|
|---|
| 741 | old->directive,
|
|---|
| 742 | GET_LABELS_V(old->labels)
|
|---|
| 743 | );
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | virtual void visit( IfStmt * old ) override final {
|
|---|
| 747 | this->node = new ast::IfStmt(
|
|---|
| 748 | old->location,
|
|---|
| 749 | GET_ACCEPT_1(condition, Expr),
|
|---|
| 750 | GET_ACCEPT_1(thenPart, Stmt),
|
|---|
| 751 | GET_ACCEPT_1(elsePart, Stmt),
|
|---|
| 752 | GET_ACCEPT_V(initialization, Stmt),
|
|---|
| 753 | GET_LABELS_V(old->labels)
|
|---|
| 754 | );
|
|---|
| 755 | }
|
|---|
| 756 |
|
|---|
| 757 | virtual void visit( SwitchStmt * old ) override final {
|
|---|
| 758 | this->node = new ast::SwitchStmt(
|
|---|
| 759 | old->location,
|
|---|
| 760 | GET_ACCEPT_1(condition, Expr),
|
|---|
| 761 | GET_ACCEPT_V(statements, Stmt),
|
|---|
| 762 | GET_LABELS_V(old->labels)
|
|---|
| 763 | );
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | virtual void visit( CaseStmt * old ) override final {
|
|---|
| 767 | this->node = new ast::CaseStmt(
|
|---|
| 768 | old->location,
|
|---|
| 769 | GET_ACCEPT_1(condition, Expr),
|
|---|
| 770 | GET_ACCEPT_V(stmts, Stmt),
|
|---|
| 771 | GET_LABELS_V(old->labels)
|
|---|
| 772 | );
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | virtual void visit( WhileStmt * old ) override final {
|
|---|
| 776 | this->node = new ast::WhileStmt(
|
|---|
| 777 | old->location,
|
|---|
| 778 | GET_ACCEPT_1(condition, Expr),
|
|---|
| 779 | GET_ACCEPT_1(body, Stmt),
|
|---|
| 780 | GET_ACCEPT_V(initialization, Stmt),
|
|---|
| 781 | old->isDoWhile,
|
|---|
| 782 | GET_LABELS_V(old->labels)
|
|---|
| 783 | );
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | virtual void visit( ForStmt * old ) override final {
|
|---|
| 787 | this->node = new ast::ForStmt(
|
|---|
| 788 | old->location,
|
|---|
| 789 | GET_ACCEPT_V(initialization, Stmt),
|
|---|
| 790 | GET_ACCEPT_1(condition, Expr),
|
|---|
| 791 | GET_ACCEPT_1(increment, Expr),
|
|---|
| 792 | GET_ACCEPT_1(body, Stmt),
|
|---|
| 793 | GET_LABELS_V(old->labels)
|
|---|
| 794 | );
|
|---|
| 795 | }
|
|---|
| 796 |
|
|---|
| 797 | virtual void visit( BranchStmt * old ) override final {
|
|---|
| 798 | if (old->computedTarget) {
|
|---|
| 799 | this->node = new ast::BranchStmt(
|
|---|
| 800 | old->location,
|
|---|
| 801 | GET_ACCEPT_1(computedTarget, Expr),
|
|---|
| 802 | GET_LABELS_V(old->labels)
|
|---|
| 803 | );
|
|---|
| 804 | } else {
|
|---|
| 805 | ast::BranchStmt::Kind kind;
|
|---|
| 806 | switch (old->type) {
|
|---|
| 807 | #define CASE(n) \
|
|---|
| 808 | case BranchStmt::n: \
|
|---|
| 809 | kind = ast::BranchStmt::n; \
|
|---|
| 810 | break
|
|---|
| 811 | CASE(Goto);
|
|---|
| 812 | CASE(Break);
|
|---|
| 813 | CASE(Continue);
|
|---|
| 814 | CASE(FallThrough);
|
|---|
| 815 | CASE(FallThroughDefault);
|
|---|
| 816 | #undef CASE
|
|---|
| 817 | default:
|
|---|
| 818 | assertf(false, "Invalid BranchStmt::Type %d\n", old->type);
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | Label label = old->originalTarget;
|
|---|
| 822 | auto stmt = new ast::BranchStmt(
|
|---|
| 823 | old->location,
|
|---|
| 824 | kind,
|
|---|
| 825 | make_label(&label),
|
|---|
| 826 | GET_LABELS_V(old->labels)
|
|---|
| 827 | );
|
|---|
| 828 | stmt->target = make_label(&old->target);
|
|---|
| 829 | this->node = stmt;
|
|---|
| 830 | }
|
|---|
| 831 | }
|
|---|
| 832 |
|
|---|
| 833 | virtual void visit( ReturnStmt * old ) override final {
|
|---|
| 834 | this->node = new ast::ReturnStmt(
|
|---|
| 835 | old->location,
|
|---|
| 836 | GET_ACCEPT_1(expr, Expr),
|
|---|
| 837 | GET_LABELS_V(old->labels)
|
|---|
| 838 | );
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 | virtual void visit( ThrowStmt * old ) override final {
|
|---|
| 842 | ast::ThrowStmt::Kind kind;
|
|---|
| 843 | switch (old->kind) {
|
|---|
| 844 | case ThrowStmt::Terminate:
|
|---|
| 845 | kind = ast::ThrowStmt::Terminate;
|
|---|
| 846 | break;
|
|---|
| 847 | case ThrowStmt::Resume:
|
|---|
| 848 | kind = ast::ThrowStmt::Resume;
|
|---|
| 849 | break;
|
|---|
| 850 | default:
|
|---|
| 851 | assertf(false, "Invalid ThrowStmt::Kind %d\n", old->kind);
|
|---|
| 852 | }
|
|---|
| 853 |
|
|---|
| 854 | this->node = new ast::ThrowStmt(
|
|---|
| 855 | old->location,
|
|---|
| 856 | kind,
|
|---|
| 857 | GET_ACCEPT_1(expr, Expr),
|
|---|
| 858 | GET_ACCEPT_1(target, Expr),
|
|---|
| 859 | GET_LABELS_V(old->labels)
|
|---|
| 860 | );
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | virtual void visit( TryStmt * old ) override final {
|
|---|
| 864 | this->node = new ast::TryStmt(
|
|---|
| 865 | old->location,
|
|---|
| 866 | GET_ACCEPT_1(block, CompoundStmt),
|
|---|
| 867 | GET_ACCEPT_V(handlers, CatchStmt),
|
|---|
| 868 | GET_ACCEPT_1(finallyBlock, FinallyStmt),
|
|---|
| 869 | GET_LABELS_V(old->labels)
|
|---|
| 870 | );
|
|---|
| 871 | }
|
|---|
| 872 |
|
|---|
| 873 | virtual void visit( CatchStmt * old ) override final {
|
|---|
| 874 | ast::CatchStmt::Kind kind;
|
|---|
| 875 | switch (old->kind) {
|
|---|
| 876 | case CatchStmt::Terminate:
|
|---|
| 877 | kind = ast::CatchStmt::Terminate;
|
|---|
| 878 | break;
|
|---|
| 879 | case CatchStmt::Resume:
|
|---|
| 880 | kind = ast::CatchStmt::Resume;
|
|---|
| 881 | break;
|
|---|
| 882 | default:
|
|---|
| 883 | assertf(false, "Invalid CatchStmt::Kind %d\n", old->kind);
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | this->node = new ast::CatchStmt(
|
|---|
| 887 | old->location,
|
|---|
| 888 | kind,
|
|---|
| 889 | GET_ACCEPT_1(decl, Decl),
|
|---|
| 890 | GET_ACCEPT_1(cond, Expr),
|
|---|
| 891 | GET_ACCEPT_1(body, Stmt),
|
|---|
| 892 | GET_LABELS_V(old->labels)
|
|---|
| 893 | );
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | virtual void visit( FinallyStmt * old ) override final {
|
|---|
| 897 | this->node = new ast::FinallyStmt(
|
|---|
| 898 | old->location,
|
|---|
| 899 | GET_ACCEPT_1(block, CompoundStmt),
|
|---|
| 900 | GET_LABELS_V(old->labels)
|
|---|
| 901 | );
|
|---|
| 902 | }
|
|---|
| 903 |
|
|---|
| 904 | virtual void visit( WaitForStmt * old ) override final {
|
|---|
| 905 | ast::WaitForStmt * stmt = new ast::WaitForStmt(
|
|---|
| 906 | old->location,
|
|---|
| 907 | GET_LABELS_V(old->labels)
|
|---|
| 908 | );
|
|---|
| 909 |
|
|---|
| 910 | stmt->clauses.reserve( old->clauses.size() );
|
|---|
| 911 | for (size_t i = 0 ; i < old->clauses.size() ; ++i) {
|
|---|
| 912 | stmt->clauses.push_back({
|
|---|
| 913 | ast::WaitForStmt::Target{
|
|---|
| 914 | GET_ACCEPT_1(clauses[i].target.function, Expr),
|
|---|
| 915 | GET_ACCEPT_V(clauses[i].target.arguments, Expr)
|
|---|
| 916 | },
|
|---|
| 917 | GET_ACCEPT_1(clauses[i].statement, Stmt),
|
|---|
| 918 | GET_ACCEPT_1(clauses[i].condition, Expr)
|
|---|
| 919 | });
|
|---|
| 920 | }
|
|---|
| 921 | stmt->timeout = {
|
|---|
| 922 | GET_ACCEPT_1(timeout.time, Expr),
|
|---|
| 923 | GET_ACCEPT_1(timeout.statement, Stmt),
|
|---|
| 924 | GET_ACCEPT_1(timeout.condition, Expr),
|
|---|
| 925 | };
|
|---|
| 926 | stmt->orElse = {
|
|---|
| 927 | GET_ACCEPT_1(timeout.statement, Stmt),
|
|---|
| 928 | GET_ACCEPT_1(timeout.condition, Expr),
|
|---|
| 929 | };
|
|---|
| 930 |
|
|---|
| 931 | this->node = stmt;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | virtual void visit( WithStmt * old ) override final {
|
|---|
| 935 | this->node = new ast::WithStmt(
|
|---|
| 936 | old->location,
|
|---|
| 937 | GET_ACCEPT_V(exprs, Expr),
|
|---|
| 938 | GET_ACCEPT_1(stmt, Stmt),
|
|---|
| 939 | GET_LABELS_V(old->labels)
|
|---|
| 940 | );
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 | virtual void visit( NullStmt * old ) override final {
|
|---|
| 944 | this->node = new ast::NullStmt(
|
|---|
| 945 | old->location,
|
|---|
| 946 | GET_LABELS_V(old->labels)
|
|---|
| 947 | );
|
|---|
| 948 | }
|
|---|
| 949 |
|
|---|
| 950 | virtual void visit( DeclStmt * old ) override final {
|
|---|
| 951 | this->node = new ast::DeclStmt(
|
|---|
| 952 | old->location,
|
|---|
| 953 | GET_ACCEPT_1(decl, Decl),
|
|---|
| 954 | GET_LABELS_V(old->labels)
|
|---|
| 955 | );
|
|---|
| 956 | }
|
|---|
| 957 |
|
|---|
| 958 | virtual void visit( ImplicitCtorDtorStmt * old ) override final {
|
|---|
| 959 | this->node = new ast::ImplicitCtorDtorStmt(
|
|---|
| 960 | old->location,
|
|---|
| 961 | GET_ACCEPT_1(callStmt, Stmt),
|
|---|
| 962 | GET_LABELS_V(old->labels)
|
|---|
| 963 | );
|
|---|
| 964 | }
|
|---|
| 965 |
|
|---|
| 966 | ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
|
|---|
| 967 |
|
|---|
| 968 | ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
|
|---|
| 969 |
|
|---|
| 970 | for (decltype(old->begin()) old_i = old->begin(); old_i != old->end(); old_i++) {
|
|---|
| 971 | rslt->add( old_i->first,
|
|---|
| 972 | getAccept1<ast::Type>(old_i->second) );
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {
|
|---|
| 976 | rslt->addVar( old_i->first,
|
|---|
| 977 | getAccept1<ast::Expr>(old_i->second) );
|
|---|
| 978 | }
|
|---|
| 979 | }
|
|---|
| 980 |
|
|---|
| 981 | void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) {
|
|---|
| 982 |
|
|---|
| 983 | (void) nwInferred;
|
|---|
| 984 | (void) oldInferParams;
|
|---|
| 985 | (void) oldResnSlots;
|
|---|
| 986 |
|
|---|
| 987 | // TODO
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
|
|---|
| 991 |
|
|---|
| 992 | nw->result = GET_ACCEPT_1(result, Type);
|
|---|
| 993 | nw->env = convertTypeSubstitution(old->env);
|
|---|
| 994 |
|
|---|
| 995 | nw->extension = old->extension;
|
|---|
| 996 | convertInferUnion(nw->inferred, old->inferParams, old->resnSlots);
|
|---|
| 997 |
|
|---|
| 998 | return nw;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | virtual void visit( ApplicationExpr * ) override final {
|
|---|
| 1002 | // TODO
|
|---|
| 1003 | }
|
|---|
| 1004 |
|
|---|
| 1005 | virtual void visit( UntypedExpr * ) override final {
|
|---|
| 1006 | // TODO
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | virtual void visit( NameExpr * old ) override final {
|
|---|
| 1010 | this->node = visitBaseExpr( old,
|
|---|
| 1011 | new ast::NameExpr(
|
|---|
| 1012 | old->location,
|
|---|
| 1013 | old->get_name()
|
|---|
| 1014 | )
|
|---|
| 1015 | );
|
|---|
| 1016 | }
|
|---|
| 1017 |
|
|---|
| 1018 | virtual void visit( CastExpr * ) override final {
|
|---|
| 1019 | // TODO ... (rest)
|
|---|
| 1020 | }
|
|---|
| 1021 |
|
|---|
| 1022 | virtual void visit( KeywordCastExpr * ) override final {
|
|---|
| 1023 |
|
|---|
| 1024 | }
|
|---|
| 1025 |
|
|---|
| 1026 | virtual void visit( VirtualCastExpr * ) override final {
|
|---|
| 1027 |
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | virtual void visit( AddressExpr * ) override final {
|
|---|
| 1031 |
|
|---|
| 1032 | }
|
|---|
| 1033 |
|
|---|
| 1034 | virtual void visit( LabelAddressExpr * ) override final {
|
|---|
| 1035 |
|
|---|
| 1036 | }
|
|---|
| 1037 |
|
|---|
| 1038 | virtual void visit( UntypedMemberExpr * ) override final {
|
|---|
| 1039 |
|
|---|
| 1040 | }
|
|---|
| 1041 |
|
|---|
| 1042 | virtual void visit( MemberExpr * ) override final {
|
|---|
| 1043 |
|
|---|
| 1044 | }
|
|---|
| 1045 |
|
|---|
| 1046 | virtual void visit( VariableExpr * ) override final {
|
|---|
| 1047 |
|
|---|
| 1048 | }
|
|---|
| 1049 |
|
|---|
| 1050 | virtual void visit( ConstantExpr * ) override final {
|
|---|
| 1051 |
|
|---|
| 1052 | }
|
|---|
| 1053 |
|
|---|
| 1054 | virtual void visit( SizeofExpr * ) override final {
|
|---|
| 1055 |
|
|---|
| 1056 | }
|
|---|
| 1057 |
|
|---|
| 1058 | virtual void visit( AlignofExpr * ) override final {
|
|---|
| 1059 |
|
|---|
| 1060 | }
|
|---|
| 1061 |
|
|---|
| 1062 | virtual void visit( UntypedOffsetofExpr * ) override final {
|
|---|
| 1063 |
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | virtual void visit( OffsetofExpr * ) override final {
|
|---|
| 1067 |
|
|---|
| 1068 | }
|
|---|
| 1069 |
|
|---|
| 1070 | virtual void visit( OffsetPackExpr * ) override final {
|
|---|
| 1071 |
|
|---|
| 1072 | }
|
|---|
| 1073 |
|
|---|
| 1074 | virtual void visit( LogicalExpr * ) override final {
|
|---|
| 1075 |
|
|---|
| 1076 | }
|
|---|
| 1077 |
|
|---|
| 1078 | virtual void visit( ConditionalExpr * ) override final {
|
|---|
| 1079 |
|
|---|
| 1080 | }
|
|---|
| 1081 |
|
|---|
| 1082 | virtual void visit( CommaExpr * ) override final {
|
|---|
| 1083 |
|
|---|
| 1084 | }
|
|---|
| 1085 |
|
|---|
| 1086 | virtual void visit( TypeExpr * ) override final {
|
|---|
| 1087 |
|
|---|
| 1088 | }
|
|---|
| 1089 |
|
|---|
| 1090 | virtual void visit( AsmExpr * ) override final {
|
|---|
| 1091 |
|
|---|
| 1092 | }
|
|---|
| 1093 |
|
|---|
| 1094 | virtual void visit( ImplicitCopyCtorExpr * ) override final {
|
|---|
| 1095 |
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|
| 1098 | virtual void visit( ConstructorExpr * ) override final {
|
|---|
| 1099 |
|
|---|
| 1100 | }
|
|---|
| 1101 |
|
|---|
| 1102 | virtual void visit( CompoundLiteralExpr * ) override final {
|
|---|
| 1103 |
|
|---|
| 1104 | }
|
|---|
| 1105 |
|
|---|
| 1106 | virtual void visit( RangeExpr * ) override final {
|
|---|
| 1107 |
|
|---|
| 1108 | }
|
|---|
| 1109 |
|
|---|
| 1110 | virtual void visit( UntypedTupleExpr * ) override final {
|
|---|
| 1111 |
|
|---|
| 1112 | }
|
|---|
| 1113 |
|
|---|
| 1114 | virtual void visit( TupleExpr * ) override final {
|
|---|
| 1115 |
|
|---|
| 1116 | }
|
|---|
| 1117 |
|
|---|
| 1118 | virtual void visit( TupleIndexExpr * ) override final {
|
|---|
| 1119 |
|
|---|
| 1120 | }
|
|---|
| 1121 |
|
|---|
| 1122 | virtual void visit( TupleAssignExpr * ) override final {
|
|---|
| 1123 |
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | virtual void visit( StmtExpr * ) override final {
|
|---|
| 1127 |
|
|---|
| 1128 | }
|
|---|
| 1129 |
|
|---|
| 1130 | virtual void visit( UniqueExpr * ) override final {
|
|---|
| 1131 |
|
|---|
| 1132 | }
|
|---|
| 1133 |
|
|---|
| 1134 | virtual void visit( UntypedInitExpr * ) override final {
|
|---|
| 1135 |
|
|---|
| 1136 | }
|
|---|
| 1137 |
|
|---|
| 1138 | virtual void visit( InitExpr * ) override final {
|
|---|
| 1139 |
|
|---|
| 1140 | }
|
|---|
| 1141 |
|
|---|
| 1142 | virtual void visit( DeletedExpr * ) override final {
|
|---|
| 1143 |
|
|---|
| 1144 | }
|
|---|
| 1145 |
|
|---|
| 1146 | virtual void visit( DefaultArgExpr * ) override final {
|
|---|
| 1147 |
|
|---|
| 1148 | }
|
|---|
| 1149 |
|
|---|
| 1150 | virtual void visit( GenericExpr * ) override final {
|
|---|
| 1151 |
|
|---|
| 1152 | }
|
|---|
| 1153 |
|
|---|
| 1154 | virtual void visit( VoidType * ) override final {
|
|---|
| 1155 |
|
|---|
| 1156 | }
|
|---|
| 1157 |
|
|---|
| 1158 | virtual void visit( BasicType * ) override final {
|
|---|
| 1159 |
|
|---|
| 1160 | }
|
|---|
| 1161 |
|
|---|
| 1162 | virtual void visit( PointerType * ) override final {
|
|---|
| 1163 |
|
|---|
| 1164 | }
|
|---|
| 1165 |
|
|---|
| 1166 | virtual void visit( ArrayType * ) override final {
|
|---|
| 1167 |
|
|---|
| 1168 | }
|
|---|
| 1169 |
|
|---|
| 1170 | virtual void visit( ReferenceType * ) override final {
|
|---|
| 1171 |
|
|---|
| 1172 | }
|
|---|
| 1173 |
|
|---|
| 1174 | virtual void visit( QualifiedType * ) override final {
|
|---|
| 1175 |
|
|---|
| 1176 | }
|
|---|
| 1177 |
|
|---|
| 1178 | virtual void visit( FunctionType * ) override final {
|
|---|
| 1179 |
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | virtual void visit( StructInstType * ) override final {
|
|---|
| 1183 |
|
|---|
| 1184 | }
|
|---|
| 1185 |
|
|---|
| 1186 | virtual void visit( UnionInstType * ) override final {
|
|---|
| 1187 |
|
|---|
| 1188 | }
|
|---|
| 1189 |
|
|---|
| 1190 | virtual void visit( EnumInstType * ) override final {
|
|---|
| 1191 |
|
|---|
| 1192 | }
|
|---|
| 1193 |
|
|---|
| 1194 | virtual void visit( TraitInstType * ) override final {
|
|---|
| 1195 |
|
|---|
| 1196 | }
|
|---|
| 1197 |
|
|---|
| 1198 | virtual void visit( TypeInstType * ) override final {
|
|---|
| 1199 |
|
|---|
| 1200 | }
|
|---|
| 1201 |
|
|---|
| 1202 | virtual void visit( TupleType * ) override final {
|
|---|
| 1203 |
|
|---|
| 1204 | }
|
|---|
| 1205 |
|
|---|
| 1206 | virtual void visit( TypeofType * ) override final {
|
|---|
| 1207 |
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | virtual void visit( AttrType * ) override final {
|
|---|
| 1211 |
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | virtual void visit( VarArgsType * ) override final {
|
|---|
| 1215 |
|
|---|
| 1216 | }
|
|---|
| 1217 |
|
|---|
| 1218 | virtual void visit( ZeroType * ) override final {
|
|---|
| 1219 |
|
|---|
| 1220 | }
|
|---|
| 1221 |
|
|---|
| 1222 | virtual void visit( OneType * ) override final {
|
|---|
| 1223 |
|
|---|
| 1224 | }
|
|---|
| 1225 |
|
|---|
| 1226 | virtual void visit( GlobalScopeType * ) override final {
|
|---|
| 1227 |
|
|---|
| 1228 | }
|
|---|
| 1229 |
|
|---|
| 1230 | virtual void visit( Designation * ) override final {
|
|---|
| 1231 |
|
|---|
| 1232 | }
|
|---|
| 1233 |
|
|---|
| 1234 | virtual void visit( SingleInit * ) override final {
|
|---|
| 1235 |
|
|---|
| 1236 | }
|
|---|
| 1237 |
|
|---|
| 1238 | virtual void visit( ListInit * ) override final {
|
|---|
| 1239 |
|
|---|
| 1240 | }
|
|---|
| 1241 |
|
|---|
| 1242 | virtual void visit( ConstructorInit * ) override final {
|
|---|
| 1243 |
|
|---|
| 1244 | }
|
|---|
| 1245 |
|
|---|
| 1246 | virtual void visit( Constant * ) override final {
|
|---|
| 1247 |
|
|---|
| 1248 | }
|
|---|
| 1249 |
|
|---|
| 1250 | virtual void visit( Attribute * ) override final {
|
|---|
| 1251 |
|
|---|
| 1252 | }
|
|---|
| 1253 |
|
|---|
| 1254 | virtual void visit( AttrExpr * ) override final {
|
|---|
| 1255 |
|
|---|
| 1256 | assert( 0 );
|
|---|
| 1257 | }
|
|---|
| 1258 | };
|
|---|
| 1259 |
|
|---|
| 1260 | #undef GET_LABELS_V
|
|---|
| 1261 | #undef GET_ACCEPT_V
|
|---|
| 1262 | #undef GET_ACCEPT_1
|
|---|
| 1263 |
|
|---|
| 1264 | std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) {
|
|---|
| 1265 | ConverterOldToNew c;
|
|---|
| 1266 | std::list< ast::ptr< ast::Decl > > decls;
|
|---|
| 1267 | for(auto d : translationUnit) {
|
|---|
| 1268 | d->accept( c );
|
|---|
| 1269 | decls.emplace_back( c.decl() );
|
|---|
| 1270 | delete d;
|
|---|
| 1271 | }
|
|---|
| 1272 | return decls;
|
|---|
| 1273 | }
|
|---|