@@ -1202,37 +1202,73 @@ class cppfront
12021202
12031203 else
12041204 {
1205- // Tokenize
1206- //
1207- tokens.lex (source.get_lines ());
1208-
1209- // Parse
1210- //
1211- try
1212- {
1213- for (auto const & [line, entry] : tokens.get_map ()) {
1214- if (!parser.parse (entry, tokens.get_generated ())) {
1215- errors.emplace_back (
1216- source_position (line, 0 ),
1217- " parse failed for section starting here" ,
1218- false ,
1219- true // a noisy fallback error message
1220- );
1221- }
1222- }
1205+ process_cpp2 ();
1206+ }
1207+ }
12231208
1224- // Sema
1225- parser.visit (sema);
1226- if (!sema.apply_local_rules ()) {
1227- violates_initialization_safety = true ;
1228- }
1229- }
1230- catch (std::runtime_error& e) {
1209+ // -----------------------------------------------------------------------
1210+ // Constructor
1211+ //
1212+ // source_stream the contents of a source file to be processed
1213+ //
1214+ cppfront (std::istream& source_stream)
1215+ : sourcefile{ " stdin.cpp2" }
1216+ , source { errors }
1217+ , tokens { errors }
1218+ , parser { errors, includes }
1219+ , sema { errors }
1220+ {
1221+ // Load the program file into memory
1222+ //
1223+ if (!source.load (source_stream))
1224+ {
1225+ if (errors.empty ()) {
12311226 errors.emplace_back (
12321227 source_position (-1 , -1 ),
1233- e. what ()
1228+ " error reading source content from stdin "
12341229 );
12351230 }
1231+ source_loaded = false ;
1232+ }
1233+
1234+ else
1235+ {
1236+ process_cpp2 ();
1237+ }
1238+ }
1239+
1240+ auto process_cpp2 () -> void
1241+ {
1242+ // Tokenize
1243+ //
1244+ tokens.lex (source.get_lines ());
1245+
1246+ // Parse
1247+ //
1248+ try
1249+ {
1250+ for (auto const & [line, entry] : tokens.get_map ()) {
1251+ if (!parser.parse (entry, tokens.get_generated ())) {
1252+ errors.emplace_back (
1253+ source_position (line, 0 ),
1254+ " parse failed for section starting here" ,
1255+ false ,
1256+ true // a noisy fallback error message
1257+ );
1258+ }
1259+ }
1260+
1261+ // Sema
1262+ parser.visit (sema);
1263+ if (!sema.apply_local_rules ()) {
1264+ violates_initialization_safety = true ;
1265+ }
1266+ }
1267+ catch (std::runtime_error& e) {
1268+ errors.emplace_back (
1269+ source_position (-1 , -1 ),
1270+ e.what ()
1271+ );
12361272 }
12371273 }
12381274
0 commit comments